My math teacher asked us to program the RSA encryption/decryption process in python. So I've created the following function: lettre_chiffre(T) which convert each character in the string into a number with the ord() function chiffre_lettre(T) which does the opposite with chr() And as these functions create 4 numbers blocks I need to encrypted in RSA with 5 numbers block to prevent frequency analysis. The problem is the ord function doesn't works well with french accents "é" "à"... Therefore, I was interested by using the bytearray method, but I have no idea how to use it.
How can I make this program works with accents. The encryption and decryption in byte with bytearray is not working with "é" and "à" for example.
python
def lettre_chiffre(T):
Message_chiffre = str('')
for lettre in T:
if ord(lettre) < 10000:
nombre = str(ord(lettre))
while len(nombre) != 4:
nombre = str('0') + nombre
Message_chiffre += nombre
else:
print("erreur lettre : ",lettre)
while len(Message_chiffre)%4 != 0:
Message_chiffre = str('0') + Message_chiffre
return str(Message_chiffre)
def chiffre_lettre(T):
Message_lettre = str('')
A =T
for i in range(int(len(str(A))/4)):
nombre = str(A)[4*i:4*i+4]
if int(nombre) < 10000:
Message_lettre += str(chr(int(nombre)))
return Message_lettre