51 v = v >> 6 |
51 v = v >> 6 |
52 return ret |
52 return ret |
53 |
53 |
54 |
54 |
55 def crypt(pw, salt, magic=None): |
55 def crypt(pw, salt, magic=None): |
56 if magic==None: |
56 if magic is None: |
57 magic = MAGIC |
57 magic = MAGIC |
58 # Take care of the magic string if present |
58 # Take care of the magic string if present |
59 if salt[:len(magic)] == magic: |
59 if salt[:len(magic)] == magic: |
60 salt = salt[len(magic):] |
60 salt = salt[len(magic):] |
61 # salt can have up to 8 characters: |
61 # salt can have up to 8 characters: |
62 salt = salt.split('$', 1)[0] |
62 salt = salt.split('$', 1)[0] |
63 salt = salt[:8] |
63 salt = salt[:8] |
64 ctx = pw + magic + salt |
64 ctx = pw + magic + salt |
65 final = md5.md5(pw + salt + pw).digest() |
65 final = md5.md5(pw + salt + pw).digest() |
66 for pl in range(len(pw),0,-16): |
66 for pl in xrange(len(pw), 0, -16): |
67 if pl > 16: |
67 if pl > 16: |
68 ctx = ctx + final[:16] |
68 ctx = ctx + final[:16] |
69 else: |
69 else: |
70 ctx = ctx + final[:pl] |
70 ctx = ctx + final[:pl] |
71 # Now the 'weird' xform (??) |
71 # Now the 'weird' xform (??) |