The function ConvertToInt(message)
should convert a text message to an integer number so ciphertext in RSA can be produced using the formula M^e mod n. Here M is the message that must be encoded into a single number. Instead, my following function ConvertToInt returns an array with elements each of which is the ASCII value of the characters. So the result becomes a character by character encryption instead of a string.
Which is the proper way to convert the message to an integer and calculate the proper RSA encrypted result?
Here is my code:
def ConvertToInt(message):
l = len(message)
arra = []
i = 0
while(i<l):
j=ord(message[i])
arra.append(j)
i += 1
return arra
def mod_ex(b, k, m):
i = 1
j = 0
while(j<=k):
b = (b*i) % m
i = b
j += 1
return b
def PowMod(s,modulo,exponent):
bin_e = bin(exponent)
bin_e = bin_e [::-1]
ln = len(bin_e)
result = 1
slen = len(s)
for i in range(0,slen,+1):
for j in range(0,ln-2,+1):
if(bin_e[j]=='1'):
result *= mod_ex(s[i],j,modulo)
s[i] = result%modulo
result = 1
return s
def Encrypt(message, modulo, exponent):
s = ConvertToInt(message)
return PowMod(s, modulo, exponent)
x = Encrypt("Aa",473,17)
print(x)