Sha256: fe88f65708618217d14cb35e8f619b2d0b2c1367c72e99d914387bb9ac147106

Contents?: true

Size: 857 Bytes

Versions: 3

Compression:

Stored size: 857 Bytes

Contents

module Affine

  # Parent class for Affine cipher errors.
  #
  # This is a good kind of error to rescue when you're not
  # sure about the key, modulus, plaintext, or ciphertext
  # and want to fail cleanly.
  class AffineError < StandardError
  end

  # Raised when two numbers that are supposed to be coprime
  # (greatest common denominator of 1) are not.
  #
  # Keys and moduli from external sources might raise these.
  class CoprimeError < AffineError
    def initialize(a, b) #:nodoc:
      super("Expected #{a} to be coprime with #{b}")
    end
  end

  # Raised when an input number is larger than the modulus.
  #
  # Plaintexts or ciphertexts from external sources might
  # raise these.
  class RangeError < AffineError
    def initialize(n, mod) #:nodoc:
      super("Expected input #{n} to be smaller than modulus #{mod}")
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
bkerley-affine-0.2.0 lib/affine/errors.rb
bkerley-affine-0.2.1 lib/affine/errors.rb
affine-0.2.1 lib/affine/errors.rb