[1596] in cryptography@c2.net mail archive

home help back first fref pref prev next nref lref last post

how to use RSA in perl (was Re: EAR question)

daemon@ATHENA.MIT.EDU (Adam Back)
Tue Sep 23 14:56:36 1997

Date: Tue, 23 Sep 1997 19:11:18 +0100
From: Adam Back <aba@dcs.ex.ac.uk>
To: iang@cs.berkeley.edu
CC: cryptography@c2.net
In-reply-to: <606mcf$q6g$1@abraham.cs.berkeley.edu> (iang@cs.berkeley.edu)


Ian Goldberg <iang@cs.berkeley.edu> writes:
> In article <199709222023.VAA02921@server.test.net>,
> Adam Back  <aba@dcs.ex.ac.uk> wrote:
> >--
> >Now officially an EAR violation...
> >Have *you* violated EAR today? --> http://www.dcs.ex.ac.uk/~aba/rsa/
> >
> >print pack"C*",split/\D+/,`echo "16iII*o\U@{$/=$z;[(pop,pop,unpack"H*",<>
> >)]}\EsMsKsN0[lN*1lK[d2%Sa2/d0<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<J]dsJxp"|dc`

Whoops another export, somebody better inform the fedz.

> BTW, what's the invokation syntax for this?  The web site in your sig gives
> a different version:

Well actually, I think that Peter Junger got "permission denied" to
his fun "can I export this?" explorations on the 3 line version which
is the one on the web page, this:

#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)

The usage for that one is:

% echo squeamish ossifrage | rsa.pl -k=[e] -n=[n] > squeamish.rsa
% rsa.pl -k=[d] -n=[n] < squeamish.rsa
squeamish ossifrage
%

Where [e] is the public exponent, [d] the private exponent, and [n]
the RSA modulus.


The newer two line version has different usage, and is incompatible
due to different blocking method, the usage for this one:

print pack"C*",split/\D+/,`echo "16iII*o\U@{$/=$z;[(pop,pop,unpack"H*",<>
)]}\EsMsKsN0[lN*1lK[d2%Sa2/d0<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<J]dsJxp"|dc`

is:

%
% echo squeamish ossifrage | rsa.pl [e] [n] > squeamish.rsa
% rsa.pl [d] [n] < squeamish.rsa
squeamish ossifrage
%

Actually I found that I couldn't get the 2 line version to work on a
1024 bit key recently under linux (I did get a 512 bit key to work).
I'm not sure if this is just my current setup.

But I do know the 3 line version works, under linux, tested up to 2048
bits I think at one point.

>    - Ian "Oops; did I just quote that?  Damn.  I'm *shocked* that such
>           a thing would happen!"

Lock this man up at once.  Can't all the exporters of this sig go
along and demand to be collectively locked up?

btw For anybody is counting they also said he couldn't export this RC4
in 4 lines of C:

#define S,t=s[i],s[i]=s[j],s[j]=t /* rc4 key <file */
unsigned char s[256],i,j,t;main(c,v)char**v;{++v;while
(s[++i]=i);while(j+=s[i]+(*v)[i%strlen(*v)]S,++i);for(
j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}

However he could export this OTP in 1 line of perl, by Paul Leyland
(with one byte saving my me):

main(i,c)int*c;{for(c=fopen(c[1],"r");i=~getchar();putchar(getc(c)^~i));}

Adam

Here's how to send me some mail with the 3 line version:

rsa.pl -k=13 -n=b487306fc179f3bd5e55a9e7c5737722dc97ec4326838b67de8146382149\
88cd90416ff55fee783c32aacc55f2b90c073c69344f5a4d9a6fb3f90770ffe6a78084bbae3f\
2c77fe14b70e0db894b063e01f91e169591ec2b5da7bf2a0427b7bd77bfa97129e9cfe10768b\
919f05728e7484949bf29de83b6a9fe7f36ea2de58b5 | \
uuencode perl-rsa-mail | mail -s "rsa mail" aba@dcs.ex.ac.uk

home help back first fref pref prev next nref lref last post