[Zope] - Cryptography...

Magnus Lie Hetland Magnus.Hetland@idi.ntnu.no
Wed, 30 Dec 1998 15:53:59 +0100 (CET)


I don't know if you guys have seen Andrew K's page on Cryptographic
Curiosities... But it shouldn't be too hard to include for instance the
RSA algorithm in Zope, when it can be expressed in four lines of Python:

#!/usr/local/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)))

According to his example, it can be used like this:

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

Fuller description can be found on
http://starship.skyport.net/crew/amk/writing/crypto-curiosa.html

(And just out of curiosity: Is it a crime to view this web page outside
the US? ;)

--

  Magnus           
  Lie              
  Hetland          www.pvv.org/arcadia <arcadia@pvv..org>