Class: ShiftCiphers::HardenedVigenere::RandomOffsetsStream
- Inherits:
-
Object
- Object
- ShiftCiphers::HardenedVigenere::RandomOffsetsStream
- Defined in:
- lib/shift_ciphers/hardened_vigenere.rb
Constant Summary collapse
- SEEDING_RAND_MAX =
2**32-1
Instance Method Summary collapse
-
#initialize(key, max) ⇒ RandomOffsetsStream
constructor
A new instance of RandomOffsetsStream.
- #next(plaintext_char) ⇒ Object
Constructor Details
#initialize(key, max) ⇒ RandomOffsetsStream
Returns a new instance of RandomOffsetsStream.
41 42 43 44 45 46 |
# File 'lib/shift_ciphers/hardened_vigenere.rb', line 41 def initialize(key, max) @random = key.bytes.reduce(Random.new(0)) do |random, byte| Random.new(random.rand(SEEDING_RAND_MAX) ^ byte) end @max = max end |
Instance Method Details
#next(plaintext_char) ⇒ Object
48 49 50 51 52 |
# File 'lib/shift_ciphers/hardened_vigenere.rb', line 48 def next(plaintext_char) plaintext_byte = plaintext_char.bytes.reduce(0){|a,e| a ^ e} @random = Random.new(@random.rand(SEEDING_RAND_MAX) ^ plaintext_byte) @random.rand(@max) end |