Class: ActsAsHavingStringId::TEA
- Inherits:
-
Object
- Object
- ActsAsHavingStringId::TEA
- Defined in:
- lib/acts_as_having_string_id/tea.rb
Constant Summary collapse
- DELTA =
0x9e3779b9
- ITERATIONS =
32
Instance Method Summary collapse
- #decrypt(num) ⇒ Object
- #encrypt(num) ⇒ Object
-
#initialize(pass_phrase) ⇒ TEA
constructor
A new instance of TEA.
Constructor Details
#initialize(pass_phrase) ⇒ TEA
Returns a new instance of TEA.
36 37 38 |
# File 'lib/acts_as_having_string_id/tea.rb', line 36 def initialize(pass_phrase) @key = passphrase_to_key(pass_phrase) end |
Instance Method Details
#decrypt(num) ⇒ Object
46 47 48 49 50 |
# File 'lib/acts_as_having_string_id/tea.rb', line 46 def decrypt(num) nums = to_32bit_ints(num) dec = decrypt_chunk(nums[0], nums[1], @key) from_32bit_ints(dec[0], dec[1]) end |
#encrypt(num) ⇒ Object
40 41 42 43 44 |
# File 'lib/acts_as_having_string_id/tea.rb', line 40 def encrypt(num) nums = to_32bit_ints(num) enc = encrypt_chunk(nums[0], nums[1], @key) from_32bit_ints(enc[0], enc[1]) end |