(password,bits=64)
| 120 | return p,q |
| 121 | |
| 122 | def passwordToKey(password,bits=64): |
| 123 | assert 64<=bits |
| 124 | assert bits%4==0 |
| 125 | length=bits//4 |
| 126 | pswd=md5.new(password).hexdigest() |
| 127 | p,q=passwordToPrimePair(pswd,bits) |
| 128 | n=p*q |
| 129 | append="0"*(length-len(pswd)) |
| 130 | possible=int(pswd+append,16)|1 # n is always even |
| 131 | # so possible must be odd |
| 132 | while not gcd(possible,n): |
| 133 | possible+=2 # keep it odd |
| 134 | private=possible |
| 135 | public=modInverse(private,totient(p,q)) |
| 136 | return public,private,n |
| 137 | |
| 138 | def crypt(string,power,n): |
| 139 | data1=0L |
no test coverage detected