Jason Leane > Toolbox > Toolbox::CryptOTP

Download:
Toolbox-0.52.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.52   Source  

NAME ^

Toolbox::CryptOTP - Play around with one-time-pad type encryption

SYNOPSIS ^

        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');

DESCRIPTION ^

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.

encrypt_file(input, output, pad) decrypt_file(input, output, pad)

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).

encrypt_string("string", 'FF') decrypt_string("f2fe3222", 'FF')

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.

rand_pad("filename.pad")

Generates a somewhat-random pad file, BLOCKSIZE bytes long. Use this if you can't locate a pad file of your own...

BLOCKSIZE

You can set the size of the functions' encryption blocks by setting Toolbox::CryptOTP::BLOCKSIZE. The default is 4096 (bytes).

EXPORTABLE FUNCTIONS ^

All functions are exported.

        use Toolbox::CryptOTP;

BUGS ^

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.

TO DO ^

Add more useful things as I think of them... Send me suggestions!

AUTHOR ^

Jason Leane (alphamethyl@mac.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?"

syntax highlighting: