Class: FF1::Cipher
- Inherits:
-
Object
- Object
- FF1::Cipher
- Defined in:
- lib/ff1/cipher.rb
Constant Summary collapse
- ROUNDS =
10
Instance Method Summary collapse
- #decrypt(ciphertext, tweak = '') ⇒ Object
- #encrypt(plaintext, tweak = '') ⇒ Object
-
#initialize(key, radix = 10, mode = Modes::REVERSIBLE) ⇒ Cipher
constructor
A new instance of Cipher.
-
#irreversible? ⇒ Boolean
Check if the cipher is in irreversible mode.
-
#reversible? ⇒ Boolean
Check if the cipher is in reversible mode.
Constructor Details
#initialize(key, radix = 10, mode = Modes::REVERSIBLE) ⇒ Cipher
Returns a new instance of Cipher.
8 9 10 11 12 13 14 |
# File 'lib/ff1/cipher.rb', line 8 def initialize(key, radix = 10, mode = Modes::REVERSIBLE) @key = key @radix = radix @mode = mode @irreversible_salt = generate_irreversible_salt if @mode == Modes::IRREVERSIBLE validate_parameters end |
Instance Method Details
#decrypt(ciphertext, tweak = '') ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ff1/cipher.rb', line 26 def decrypt(ciphertext, tweak = '') if @mode == Modes::IRREVERSIBLE raise FF1::Error, 'Cannot decrypt in irreversible mode - data is permanently transformed' end reversible_decrypt(ciphertext, tweak) end |
#encrypt(plaintext, tweak = '') ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/ff1/cipher.rb', line 16 def encrypt(plaintext, tweak = '') validate_input(plaintext) if @mode == Modes::IRREVERSIBLE irreversible_encrypt(plaintext, tweak) else reversible_encrypt(plaintext, tweak) end end |
#irreversible? ⇒ Boolean
Check if the cipher is in irreversible mode
40 41 42 |
# File 'lib/ff1/cipher.rb', line 40 def irreversible? @mode == Modes::IRREVERSIBLE end |
#reversible? ⇒ Boolean
Check if the cipher is in reversible mode
35 36 37 |
# File 'lib/ff1/cipher.rb', line 35 def reversible? @mode == Modes::REVERSIBLE end |