Created
July 8, 2015 14:20
-
-
Save anonymous/b9ed3dbe73ec053fcded to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def LCG(seed) | |
return (1103515245*(seed)+12345)%128 | |
end | |
def enc(msg, key) | |
newSeed = LCG(key) | |
if msg.length > 0 | |
return (msg[0].ord^newSeed).chr + enc(msg[1..-1], newSeed).to_s | |
end | |
end | |
def dec(ciph, key) | |
return enc(ciph, key) | |
end | |
key = 31337; | |
msg = "Attack at dawn!" | |
cipher_text = enc(msg, key) | |
plain_text = dec(cipher_text,key) | |
puts "Original Message: #{msg}" | |
puts "Cipher Text: #{cipher_text}" | |
puts "Plain Text: #{plain_text}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And if you make LCG with much more bits, then it will be "almost secure":
but... slow