DES encryption algorithm
Joshua Muskovitz
joshm at taconic.net
Wed Jan 16 03:45:30 EST 2002
> > 1: Has any pure python algorithm been implemented already?
I ported my ex-companies C implementation of DES to Python. I made a first
pass just porting function by function. This was the easiest solution,
since it made unit testing of each function much easier. I also refactored
the code as I went, inlining functions that were really only called in one
or two places.
One thing that will bite you in the ass is that python bitwise right shift
is *sign extended*, so you can't just use >> in your bit twiddling. This
was the bug that took the longest for me to find.
Here is a handy function for handling right shift. Replace all occurrances
of x >> y in your code with rshift(x, y).
def rshift(num, dist):
if dist == 0:
return num
else:
return ( (num >> dist) & (0x7fffffff >> (dist-1) ) )
--
# Joshua Muskovitz
# joshm at taconic.net
def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
lyyrs('Hire me! I need the work!')
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list