SYNOPSIS

  use Crypt::CipherSaber;
  my $cs = Crypt::CipherSaber->new('my pathetic secret key');

my $coded = $cs->encrypt('Here is a secret message for you'); my $decoded = $cs->decrypt($coded);

# encrypt from and to a file open(INFILE, 'secretletter.txt') or die "Can't open infile: $!"; open(OUTFILE, '>secretletter.cs1') or die "Can't open outfile: $!"; binmode(INFILE); binmode(OUTFILE); $cs->fh_crypt(\*INFILE, \*OUTFILE, 1);

# decrypt from and to a file open(INFILE, 'secretletter.cs1') or die "Can't open infile: $!"; open(OUTFILE, '>secretletter.txt') or die "Can't open outfile: $!"; binmode(INFILE); binmode(OUTFILE); $cs->fh_crypt(\*INFILE, \*OUTFILE);

DESCRIPTION

The Crypt::CipherSaber module implements CipherSaber encryption, described at http://ciphersaber.gurus.com. It is simple, fairly speedy, and relatively secure algorithm based on \s-1RC4\s0.

Encryption and decryption are done based on a secret key, which must be shared with all intended recipients of a message.

METHODS

Initialize a new Crypt::CipherSaber object. $key, the key used to encrypt or to decrypt messages is required. $N is optional. If provided and greater than one, it will implement CipherSaber-2 encryption (slightly slower but more secure). If not specified, or equal to 1, the module defaults to CipherSaber-1 encryption. $N must be a positive integer greater than one.

encrypt($message)

Encrypt a message. This uses the key stored in the current Crypt::CipherSaber object. It will generate a 10-byte random \s-1IV\s0 (Initialization Vector) automatically, as defined in the \s-1RC4\s0 specification. This returns a string containing the encrypted message. Note that the encrypted message may contain unprintable characters, as it uses the extended \s-1ASCII\s0 character set (valid numbers 0 through 255).

decrypt($message)

Decrypt a message. For the curious, the first ten bytes of an encrypted message are the \s-1IV\s0, so this must strip it off first. This returns a string containing the decrypted message. The decrypted message may also contain unprintable characters, as the CipherSaber encryption scheme can handle binary files with fair ease. If this is important to you, be sure to treat the results correctly. If you wish to generate the \s-1IV\s0 with a more cryptographically secure random string (at least compared to Perl's builtin rand() function), you may do so separately, passing it to this method directly. The \s-1IV\s0 must be a ten-byte string consisting of characters from the extended \s-1ASCII\s0 set. This is generally only useful for encryption, although you may extract the first ten characters of an encrypted message and pass them in yourself. You might as well call decrypt(), though. The more random the \s-1IV\s0, the stronger the encryption tends to be. On some operating systems, you can read from /dev/random. Other approaches are the Math::TrulyRandom module, or compressing a file, removing the headers, and compressing it again.

fh_crypt(\*INPUT, \*OUTPUT, ($iv))

For the sake of efficiency, Crypt::CipherSaber can now operate on filehandles. It's not super brilliant, but it's relatively fast and sane. Pass in a reference to the input file handle and the output filehandle. If your platform needs to use \*(C`binmode()\*(C', this is your responsibility. It is also your responsibility to close the files. You may also pass in an optional third parameter, an \s-1IV\s0. There are three possibilities here. If you pass no \s-1IV\s0, \*(C`fh_crypt()\*(C' will pull the first ten bytes from *INPUT and use that as an \s-1IV\s0. This corresponds to decryption. If you pass in an \s-1IV\s0 of your own (generally ten digits, but more than one digits as the code is now), it will use your own \s-1IV\s0 when encrypting the file. If you pass in the value '1', it will generate a new, random \s-1IV\s0 for you. This corresponds to an encryption.

COPYRIGHT AND LICENSE

Copyright (C) 2000 - 2001 chromatic

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

chromatic <[email protected]>

thanks to jlp for testing, moral support, and never fearing the icky details and to the fine folks at http://perlmonks.org

Additional thanks to Olivier Salaun and the Sympa project (http://www.sympa.org) for testing.

RELATED TO Crypt::CipherSaber…

the CipherSaber home page at http://ciphersaber.gurus.com

perl\|(1), rand().