Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #!/import/bw/tools/local/perl-5.8.0/bin/perl |
2 | ||
3 | eval 'exec /import/bw/tools/local/perl-5.8.0/bin/perl -S $0 ${1+"$@"}' | |
4 | if 0; # not running under some shell | |
5 | ######################################################################### | |
6 | # This Perl script is Copyright (c) 2000, Peter J Billam # | |
7 | # c/o P J B Computing, www.pjb.com.au # | |
8 | # # | |
9 | # This program is free software; you can redistribute it and/or # | |
10 | # modify it under the same terms as Perl itself. # | |
11 | ######################################################################### | |
12 | use Crypt::Tea; | |
13 | ||
14 | while ($ARGV[$[] =~ /^-/) { | |
15 | if ($ARGV[$[] =~ /^-c/) { $encrypt='yes'; shift; | |
16 | } elsif ($ARGV[$[] =~ /^-s/) { $sign='yes'; shift; | |
17 | } elsif ($ARGV[$[] =~ /^-j/) { print &tea_in_javascript; exit 1; | |
18 | } else { print <<EOT; exit; | |
19 | usage: | |
20 | tea -c filename # encrypts filename | |
21 | tea filename # decrypts filename | |
22 | tea -s filename # calculates ascii digital signature for filename | |
23 | tea -j # outputs JavaScript code to do compatible encryption | |
24 | tea -h # prints this message | |
25 | ||
26 | For encryption and decryption, you will be asked for a password. | |
27 | It should be a sufficiently longish string; say 17 random 8-bit bytes. | |
28 | Version 1.43, | |
29 | #COMMENT# | |
30 | ||
31 | EOT | |
32 | } | |
33 | } | |
34 | # tea -c3 filename # triple-encrypts filename | |
35 | # tea -3 filename # triple-decrypts filename | |
36 | # for single encryption, or 3 times that to justify triple encryption. | |
37 | ||
38 | undef $/; my $text = <>; $/="\n"; | |
39 | if ($sign) { print &asciidigest ($text) . "\n"; exit 0; } | |
40 | ||
41 | open(TTY, ">/dev/tty") || die "Can't write /dev/tty: $!\n"; | |
42 | open(TTYIN, "</dev/tty") || die "Can't read /dev/tty: $!\n"; | |
43 | print TTY 'Password: '; my $key = <TTYIN>; | |
44 | close TTY; close TTYIN; | |
45 | $key =~ s/[\r\n]*$//; | |
46 | exit unless $key; | |
47 | ||
48 | if ($encrypt) { | |
49 | print &encrypt ($text, $key), "\n"; | |
50 | } else { | |
51 | print &decrypt ($text, $key); | |
52 | } | |
53 | exit 0; | |
54 | ||
55 | __END__ | |
56 | ||
57 | =pod | |
58 | ||
59 | =head1 NAME | |
60 | ||
61 | tea - Perl script to give command-line access to Crypt::Tea.pm | |
62 | ||
63 | =head1 SYNOPSIS | |
64 | ||
65 | tea -c filename # encrypts filename | |
66 | tea filename # decrypts filename | |
67 | tea -s filename # calculates ascii digital signature for filename | |
68 | tea -j # outputs JavaScript doing compatible encryption | |
69 | tea -h # prints this message | |
70 | ||
71 | For encryption and decryption, you will be asked for a password. | |
72 | It should be a sufficiently longish string; say 17 random 8-bit bytes. | |
73 | ||
74 | =head1 DESCRIPTION | |
75 | ||
76 | This script uses the Crypt::Tea.pm module to offer TEA, the Tiny | |
77 | Encryption Algorithm, and some Modes of Use based on CBC, compatibly in | |
78 | both Perl and JavaScript. | |
79 | ||
80 | The various options offer encryption, decryption and digest, and all | |
81 | cyphertext is ascii-encoded to prevent munging. Another option returns | |
82 | JavaScript code which offers identical functions in JS, and this can | |
83 | be used by GCIs to feed to the browser. Triple encryption will be | |
84 | offered later. | |
85 | ||
86 | Version 1.42, | |
87 | #COMMENT# | |
88 | ||
89 | =head1 AUTHOR | |
90 | ||
91 | Peter J Billam <computing@pjb.com.au> | |
92 | ||
93 | =head1 CREDITS | |
94 | ||
95 | Based on Crypt::Tea.pm | |
96 | ||
97 | =head1 SEE ALSO | |
98 | ||
99 | http://www.pjb.com.au/, http://www.cpan.org, perl(1). | |
100 | ||
101 | =cut | |
102 |