1Crypt::CipherSaber(3) User Contributed Perl DocumentationCrypt::CipherSaber(3)
2
3
4
6 Crypt::CipherSaber - Perl module implementing CipherSaber encryption.
7
9 use Crypt::CipherSaber;
10 my $cs = Crypt::CipherSaber->new('my sad secret key');
11
12 my $coded = $cs->encrypt('Here is a secret message for you');
13 my $decoded = $cs->decrypt($coded);
14
15 # encrypt from and to a file
16 open my $in, 'secretletter.txt' or die "Can't open infile: $!";
17 open my $out, '>', 'secretletter.cs1' or die "Can't open outfile: $!";
18 binmode $in;
19 binmode $out;
20
21 $cs->fh_crypt($in, $out, 1);
22
23 # decrypt from and to a file
24 open my $in, 'secretletter.txt' or die "Can't open infile: $!";
25 open my $out, '>', 'secretletter.cs1' or die "Can't open outfile: $!";
26
27 binmode $in;
28 binmode $out;
29 $cs->fh_crypt($in, $out);
30
32 The Crypt::CipherSaber module implements CipherSaber encryption,
33 described at <http://ciphersaber.gurus.com/>. It is simple, fairly
34 speedy, and relatively secure algorithm based on RC4. Relatively, given
35 RC4.
36
37 Encryption and decryption are done based on a secret key, which must be
38 shared with all intended recipients of a message.
39
41 new($key, $N)
42 Initialize a new Crypt::CipherSaber object. $key is a required
43 parameter: the key used to encrypt or to decrypt messages. $N is
44 optional. If provided and greater than one, it causes the object
45 to use CipherSaber-2 encryption (slightly slower but more secure).
46 If not specified, or equal to 1, the module defaults to
47 CipherSaber-1 encryption. $N must be a positive integer greater
48 than one.
49
50 encrypt($message)
51 Encrypt a message. This uses the key stored in the current
52 Crypt::CipherSaber object. It generates a 10-byte random IV
53 (Initialization Vector) automatically, as defined in the RC4
54 specification. This returns a string containing the encrypted
55 message.
56
57 Note that the encrypted message may contain unprintable characters,
58 as it uses the extended ASCII character set (valid numbers 0
59 through 255).
60
61 decrypt($message)
62 Decrypt a message. For the curious, the first ten bytes of an
63 encrypted message are the IV, so this must strip it off first.
64 This returns a string containing the decrypted message.
65
66 The decrypted message may also contain unprintable characters, as
67 the CipherSaber encryption scheme handles binary filesIf this is
68 important to you, be sure to treat the results correctly.
69
70 crypt($iv, $message)
71 If you wish to generate the IV with a more cryptographically secure
72 random string (at least compared to Perl's builtin "rand()"
73 operator), you may do so separately, passing it to this method
74 directly. The IV must be a ten-byte string consisting of
75 characters from the extended ASCII set.
76
77 This is generally only useful for encryption, although you may
78 extract the first ten characters of an encrypted message and pass
79 them in yourself. You might as well call decrypt(), though. The
80 more random the IV, the stronger the encryption tends to be. On
81 some operating systems, you can read from /dev/random. Other
82 approaches are the Math::TrulyRandom module, or compressing a file,
83 removing the headers, and compressing it again.
84
85 fh_crypt( $in_fh, $out_fh, ($iv))
86 For the sake of efficiency, Crypt::CipherSaber can operate on
87 filehandles. It's not super brilliant, but it's relatively fast
88 and sane. If your platform needs to use "binmode()", this is your
89 responsibility. It is also your responsibility to close the files.
90
91 You may also pass in an optional third parameter, an IV. There are
92 three possibilities here. If you pass no IV, "fh_crypt()" will
93 pull the first ten bytes from the input filehandle and use that as
94 an IV. This corresponds to decryption. If you pass in an IV of
95 your own, it will use that when encrypting the file. If you pass
96 in the value 1, it will generate a new, random IV for you. This
97 corresponds to an encryption.
98
100 Copyright (C) 2000 - 2015 chromatic
101
102 This library is free software; you can use, modify, and redistribute it
103 under the same terms as Perl 5.20.x itself.
104
106 chromatic "chromatic at cpan dot org"
107
108 thanks to jlp for testing, moral support, and never fearing the icky
109 details and to the fine folks at PerlMonks <http://perlmonks.org/>.
110
111 Additional thanks to Olivier Salaun and the Sympa project
112 <http://www.sympa.org> for testing.
113
115 the CipherSaber home page at <http://ciphersaber.gurus.com/>
116
117 perl(1), rand().
118
119
120
121perl v5.30.1 2020-01-29 Crypt::CipherSaber(3)