Created
July 29, 2010 15:23
-
-
Save fritz0705/498409 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 dm_crypt(message, key) | |
if key.empty? | |
return message | |
end | |
result = "" | |
i = 0 | |
message.each_byte do |byte| | |
result += (byte ^ key[i % key.bytesize].ord ^ i).chr | |
i += 1 | |
end | |
return dm_crypt(result, key[1..-1]) | |
end | |
def dm_keygen(msg = nil) | |
complexity = 2 | |
random = File.open("/dev/urandom") | |
msg = random.read(complexity) unless msg | |
base_key = random.read(complexity) | |
result = dm_crypt(msg, base_key) | |
Fiber.new do | |
loop do | |
File.open("/dev/null", "r+b").write(random.read(complexity * 16)) | |
key = random.read(complexity) | |
while result != dm_crypt(msg, key) | |
key = random.read(complexity) | |
end | |
Fiber.yield key | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment