Class: IntegerObfuscator
- Inherits:
-
Object
- Object
- IntegerObfuscator
- Defined in:
- lib/integer_obfuscator.rb,
lib/integer_obfuscator/version.rb
Overview
Obfuscates or unobfuscates 32-bit integers using a 32-bit block cipher based on SKIPJACK.
Defined Under Namespace
Classes: RangeError
Constant Summary collapse
- MAX_SIZE =
(2 ** 32) - 1
- VERSION =
'0.1.0'
Instance Method Summary collapse
-
#initialize(key) ⇒ IntegerObfuscator
constructor
Creates an obfuscator.
-
#obfuscate(i) ⇒ Integer
Obfuscates an integer.
-
#unobfuscate(i) ⇒ Integer
Unobfuscates an integer.
Constructor Details
#initialize(key) ⇒ IntegerObfuscator
Creates an obfuscator
18 19 20 21 |
# File 'lib/integer_obfuscator.rb', line 18 def initialize(key) shakey = Digest::SHA1.digest(key)[0...10] @c = Cipher::Skip32.new(shakey) end |
Instance Method Details
#obfuscate(i) ⇒ Integer
Obfuscates an integer
27 28 29 30 |
# File 'lib/integer_obfuscator.rb', line 27 def obfuscate(i) require_32bit_integer(i) @c.encrypt([i].pack("I")).unpack("I").first end |
#unobfuscate(i) ⇒ Integer
Unobfuscates an integer
36 37 38 39 |
# File 'lib/integer_obfuscator.rb', line 36 def unobfuscate(i) require_32bit_integer(i) @c.decrypt([i].pack("I")).unpack("I").first end |