How do I use the "three line version of the RSA algorithm" written in Perl?

981 Views Asked by At

The book "An Introduction to Mathematical Cryptography" by J. Hoffstein et al. talks about a three-line implementation of the RSA algorithm in Perl, which people used to protest US government censorship of cryptography:

To protest the government's policy, people wrote a three line version of the RSA algorithm in a programming language called perl and printed it on tee shirts and soda cans, thereby making these products into munitions. In principle, wearing an "RSA enabled" tee shirt on a flight from New York to Europe subjected the wearer to a large fine and a 10 year jail term.

I looked online for the actual Perl program, and found it here: http://www.cypherspace.org/rsa/story.html.

#!/bin/perl -s-- -export-a-crypto-system-sig -RSA-3-lines-PERL
$m=unpack(H.$w,$m."\0"x$w),$_=`echo "16do$w 2+4Oi0$d*-^1[d2%Sa
2/d0<X+d*La1=z\U$n%0]SX$k"[$m*]\EszlXx++p|dc`,s/^.|\W//g,print
pack('H*',$_)while read(STDIN,$m,($w=2*$d-1+length$n&~1)/2)

The above is equivalent to the following:

#!/bin/perl -s --

$w = ( 2 * $d - 1 + length($n) ) & ~1;

while (read(STDIN, $m, $w/2)) {
   $m = unpack(H.$w, $m.("\0"x$w));
   $_ = `echo "16do$w 2+4Oi0$d*-^1[d2%Sa2/d0<X+d*La1=z\U$n%0]SX$k"[$m*]\EszlXx++p | dc`;
   s/^.|\W//g;
   print pack('H*', $_);
}

My question is: How would I use this program to encrypt and later decrypt a piece of data? Does the program support key generation as well, or do I need to have a key already?

0

There are 0 best solutions below