MD5()

Sam Holden sholden at flexal.cs.usyd.edu.au
Wed Oct 27 05:34:08 CEST 2004


On Tue, 26 Oct 2004 22:37:47 -0400, ed18hg <ed18hg at brllsouth.net> wrote:
> Hello,
> I'm using this code to get the MD5 of the numbers 0-9. How can I loop 
> through the combination of all lowercase letters and 0-9. I read in the 
> documentation the string operation ascii_lowercase but I'm a bit confused on 
> how to combine it with integers. Thanks in advance.

It depends what you mean by "combination of all lowercase letters and 0-9".

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465

shows one way of generating combinations, but what you want depends on
what you are actually trying to do.

>
> for i in xrange(10):
>  import md5
>  m=md5.new()
>  m.update("%i"%i)
>  print"i=",i,"md5(i)=",m.hexdigest() 

If you want all pairs of lowercase letters and 0-9 you could, for example, use:

import string
import md5

def pairs(s):
    for c1 in s:
        for c2 in s:
            yield c1+c2

for i in pairs(string.ascii_lowercase+string.digits):
    m = md5.new()
    m.update(i)
    print "i=",i,"md5(i)=",m.hexdigest()

-- 
Sam Holden



More information about the Python-list mailing list