class CryptoToolchain::BlackBoxes::MT19937StreamCipher
Constants
- MAX_SEED
Attributes
plaintext[R]
prng[R]
seed[R]
Public Class Methods
generate_token(length: 32, seed: Time.now.to_i)
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 15 def self.generate_token(length: 32, seed: Time.now.to_i) new("A" * length, seed: seed).keystream.to_base64 end
max_seed()
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 6 def max_seed @max_seed ||= MAX_SEED end
max_seed=(val)
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 10 def max_seed=(val) @max_seed = val end
new(plaintext, seed: rand(0..(self.class.max_seed)))
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 19 def initialize(plaintext, seed: rand(0..(self.class.max_seed))) @seed = seed & self.class.max_seed @prng = CryptoToolchain::Utilities::MT19937.new(@seed) @plaintext = plaintext end
Public Instance Methods
decrypt(str)
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 29 def decrypt(str) str ^ keystream end
encrypt(str = plaintext)
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 25 def encrypt(str = plaintext) str ^ keystream end
keystream()
click to toggle source
# File lib/crypto_toolchain/black_boxes/mt_19937_stream_cipher.rb, line 33 def keystream return @keystream if defined? @keystream _keystream = (0..(plaintext.bytesize / 4)).each_with_object("") do |_, memo| memo << [prng.extract].pack("L") end @keystream = _keystream[0...(plaintext.bytesize)] end