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

Function crypt

recipes/Python/572196_RSA/recipe-572196.py:138–148  ·  view source on GitHub ↗
(string,power,n)

Source from the content-addressed store, hash-verified

136 return public,private,n
137
138def crypt(string,power,n):
139 data1=0L
140 for char in string:
141 data1<<=8
142 data1+=ord(char)
143 data2=pow(data1,power,n)
144 ret=""
145 while data2:
146 data2,r=divmod(data2,256)
147 ret=chr(r)+ret
148 return ret
149
150def encrypt(string,power,n,bits=128):
151 string=string.replace('/',"/s").replace('\0',"/0") # escape \x00

Callers 2

encryptFunction · 0.70
decryptFunction · 0.70

Calls 1

powFunction · 0.50

Tested by

no test coverage detected