MCPcopy Create free account
hub / github.com/ActiveState/code / passwordToKey

Function passwordToKey

recipes/Python/572196_RSA/recipe-572196.py:122–136  ·  view source on GitHub ↗
(password,bits=64)

Source from the content-addressed store, hash-verified

120 return p,q
121
122def 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
138def crypt(string,power,n):
139 data1=0L

Callers 2

__init__Method · 0.85
recipe-572196.pyFile · 0.85

Calls 6

passwordToPrimePairFunction · 0.85
modInverseFunction · 0.85
totientFunction · 0.85
hexdigestMethod · 0.80
gcdFunction · 0.70
newMethod · 0.45

Tested by

no test coverage detected