lib/affine/cipher.rb in affine-0.2.1 vs lib/affine/cipher.rb in affine-0.2.2
- old
+ new
@@ -26,15 +26,23 @@
@b_key = b_key
@a_inv = extended_gcd(a_key, modulus)
end
# Encrypt one +plaintext+ into a +ciphertext+.
+ #
+ # == Argument
+ # [+plaintext+] a single positive integer between 0 and the +modulus+
+ # for the cipher
def encipher(plaintext)
raise RangeError.new(plaintext, @modulus) if plaintext > @modulus
((@a_key * plaintext) + @b_key) % @modulus
end
# Decrypt one +ciphertext+ into a +plaintext+.
+ #
+ # == Argument
+ # [+ciphertext+] a single positive integer between 0 and the +modulus+
+ # for the cipher
def decipher(ciphertext)
raise RangeError.new(ciphertext, @modulus) if ciphertext > @modulus
(@a_inv * (ciphertext - @b_key)) % @modulus
end