[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cryptography
Subject:    Python RSA
From:       Eugene Leitl <eugene.leitl () lrz ! uni-muenchen ! de>
Date:       1999-06-24 23:07:44
[Download RAW message or body]


Got this from Mordy Ovits <movits@lockstar.com>

Is the following of more than trivial value? It does seem to use L
integers... 

#!/usr/bin/python 
from sys import*;from string import*;a=argv;[s,p,q]=filter(lambda x:x[:1]!=
'-',a);d='-d'in a;e,n=atol(p,16),atol(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d
while s:s=stdin.read(inb);s and map(stdout.write,map(lambda i,b=pow(reduce(
lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1)))

Invoked as:

	echo 'Top secret message.' | rsa.py 10001 1967cb529 >ciphertext
	cat ciphertext             | rsa.py -d ac363601 1967cb529 

	* rsa.py (4 lines): Performs RSA public key
encryption/decryption.  It requires two arguments, and can accept a
single option: '-d' for decryption (the default action is encryption).
The first argument must be the required exponent, expressed in
hexadecimal, and the second is the modulus, also in hex.  You still
have to choose the correct exponent, whether the '-d' option is
present or not; '-d' simply changes the number of bytes read at a
single time.

	As an example: Let us assume the modulus is 6819722537, the
encryption exponent is 65537, and the decryption exponent is
2889233921.  Then, after converting the numbers to hex, we can encrypt
and then decrypt by the following commands:

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic