[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Message Digest Ciphers (was Re: rc2 export limits..)
P J Ponder writes:
> How can I use SHA to encrypt something for someone else to
> decrypt? I know how to use it for authentication; am I missing
> something here?
Check Applied Cryptography for info on ciphers such as "Karn",
"Luby-Rackoff", and "MDC" ... These are encryption algorithms that use
one-way hashes as their block functions.
Attached is a version of the Karn cipher I implemented as an
export-a-crypt-system .sig a while back... I used python because it's my
favorite language and has MD5 built-in. I implemented the Karn cipher since
it was the simplest (and therefore shortest) of the MD ciphers, not because
it's the most secure.
andrew
#!/usr/local/bin/python -- -export-a-crypt-system MD5 CBC-mode Karn Cipher
from md5 import *;from sys import *;from string import *;M=md5;il=ir=M(argv[3]\
).digest();ki=M(argv[2]).digest();K,k=ki[:8],ki[8:];p=stdin.read(32);c={'-e':'\
l=x(l,il);r=x(r,ir);R=x(M(l+K).digest(),r);L=x(M(R+k).digest(),l);il=L;ir=R','\
-d':'L=x(M(r+k).digest(),l);R=x(M(L+K).digest(),r);L=x(L,il);R=x(R,ir);ir=r;il\
=l'};main="def x(a,b):return joinfields(map(lambda m,n:chr(m^n),map(lambda m:o\
rd(m),a),map(lambda m:ord(m),b)),'');\nwhile(p):p=ljust(p,32);l,r=p[:16],p[16:\
];exec(c[argv[1]]);stdout.write(L+R);p=stdin.read(32)";exec(main)
#try: echo 'TESTING 1 2 3' | karn -e 'key' 'I-V' | karn -d 'key' 'I-V'