Sha256: 8215a0465dafde01efca9ec47f5f7b851ca021777755070250bfa1417993bea2

Contents?: true

Size: 875 Bytes

Versions: 4

Compression:

Stored size: 875 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: :notnew:
      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: :notnew:
      super("Expected input #{n} to be smaller than modulus #{mod}")
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
bkerley-affine-0.2.2 lib/affine/errors.rb
bkerley-affine-0.2.3 lib/affine/errors.rb
affine-0.2.3 lib/affine/errors.rb
affine-0.2.2 lib/affine/errors.rb