Toolbox::CryptOTP - Play around with one-time-pad type encryption
use Toolbox::CryptOTP; $plaintextfile = "doc.txt"; # Generate a random pad $pad_file = rand_pad("mypad.otp"); # Encrypt a file encrypt_file($plaintextfile, "ciphertext.txt", "mypad.otp"); # Decrypt it back decrypt_file("ciphertext.txt", "decrypted-plain.txt", "mypad.otp"); # Encrypt a string $plaintext = "Squeamish Ossifrage"; $garbage = encrypt_string($plaintext, 'f4'); # Decrypt it back $text = decrypt_string($garbage, 'f4');
A module meant for those interested in learning abotu cryptography... the methods used here are not MEANT to be secure, and should be used solely to understand the principles of encryption. DO NOT use any function in this module to attempt to protect sensitive data.
These functions implement "One-Time-Pad" encryption. For the file encryption/decryption functions, you specify another file as the 'pad'. One block is read from this file, and applied to each block of the input (NOTE: this is a BIG security flaw). If you run the output back through, with an IDENTICAL pad, you should recover the plaintext.
For more information, see "Internet Cryptography" by Richard E. Smith. It covers this topic and many others.
Encrypts or decrypts a file. For encryption, the input is plaintext, the output is ciphertext. For decryption, the input is ciphertext, the output is plaintext. The pad is shared between both functions. All arguments are filenames (not fileHANDLES).
Encrypts or decrypts a string. The pad is given as a two-digit hexadecimal number (00 - FF). It is applied to each character of the plaintext/ciphertext. Returns either ciphertext of plaintext.
Generates a somewhat-random pad file, BLOCKSIZE bytes long. Use this if you can't locate a pad file of your own...
You can set the size of the functions' encryption blocks by setting
Toolbox::CryptOTP::BLOCKSIZE. The default is 4096 (bytes).
All functions are exported.
None that i know about. If you want to see bugs, go have a look at DES...
Wel, of course, using it for actual crypto is a bug in itself.
Add more useful things as I think of them... Send me suggestions!
Jason Leane (email@example.com)
Copyright 2002 Jason Leane
Thanks to LucyFerr for getting me out of a rut and renewing my enthusiasm for Perl with her own brand of persevereance as she learned Perl for the first time.
"Now quick, what's 0xDEADBEEF in octal?"