equal
deleted
inserted
replaced
41 MAGIC = '$1$' # Magic string |
41 MAGIC = '$1$' # Magic string |
42 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
42 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
43 |
43 |
44 from hashlib import md5 # pylint: disable=E0611 |
44 from hashlib import md5 # pylint: disable=E0611 |
45 |
45 |
|
46 from six.moves import range |
|
47 |
|
48 |
46 def to64 (v, n): |
49 def to64 (v, n): |
47 ret = '' |
50 ret = '' |
48 while (n - 1 >= 0): |
51 while (n - 1 >= 0): |
49 n = n - 1 |
52 n = n - 1 |
50 ret = ret + ITOA64[v & 0x3f] |
53 ret = ret + ITOA64[v & 0x3f] |
60 # salt can have up to 8 characters: |
63 # salt can have up to 8 characters: |
61 salt = salt.split('$', 1)[0] |
64 salt = salt.split('$', 1)[0] |
62 salt = salt[:8] |
65 salt = salt[:8] |
63 ctx = pw + MAGIC + salt |
66 ctx = pw + MAGIC + salt |
64 final = md5(pw + salt + pw).digest() |
67 final = md5(pw + salt + pw).digest() |
65 for pl in xrange(len(pw), 0, -16): |
68 for pl in range(len(pw), 0, -16): |
66 if pl > 16: |
69 if pl > 16: |
67 ctx = ctx + final[:16] |
70 ctx = ctx + final[:16] |
68 else: |
71 else: |
69 ctx = ctx + final[:pl] |
72 ctx = ctx + final[:pl] |
70 # Now the 'weird' xform (??) |
73 # Now the 'weird' xform (??) |
77 i = i >> 1 |
80 i = i >> 1 |
78 final = md5(ctx).digest() |
81 final = md5(ctx).digest() |
79 # The following is supposed to make |
82 # The following is supposed to make |
80 # things run slower. |
83 # things run slower. |
81 # my question: WTF??? |
84 # my question: WTF??? |
82 for i in xrange(1000): |
85 for i in range(1000): |
83 ctx1 = '' |
86 ctx1 = '' |
84 if i & 1: |
87 if i & 1: |
85 ctx1 = ctx1 + pw |
88 ctx1 = ctx1 + pw |
86 else: |
89 else: |
87 ctx1 = ctx1 + final[:16] |
90 ctx1 = ctx1 + final[:16] |