Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Copyright 2013 Jesse Zilstorff
- class Diamond
- def swap(stream, key, cipher, offset)
- last = key.first
- stream.bytes.with_index.map do |byte, index|
- key.unshift(last ^= (index+offset) ^ key.pop)
- byte ^ last ^ cipher.getbyte(index)
- end.pack("C*")
- end
- def encrypt(instream, outstream, key)
- blksize = instream.stat.blksize
- offset = key.pop
- buffer = 0x00.chr*blksize
- cipher = swap(buffer, key, buffer, offset)
- while instream.read(blksize, buffer)
- cipher = swap(buffer, key, cipher, offset)
- outstream.write(cipher)
- end
- end
- def decrypt(instream, outstream, key)
- blksize = instream.stat.blksize
- offset = key.pop
- buffer = 0x00.chr*blksize
- cipher = swap(buffer, key, buffer, offset)
- while instream.read(blksize, buffer)
- outstream.write(swap(buffer, key, cipher, offset))
- cipher.replace(buffer)
- end
- end
- end
- Diamond.new.send(
- ARGV.shift,
- File.new(ARGV.shift),
- File.new(ARGV.shift, IO::CREAT|IO::WRONLY),
- "PUT YOUR RANDOM-LOOKING KEY HERE".bytes.to_a
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement