我的数学老师让我们用python编写RSA加密/解密过程。因此,我创建了以下函数: lettre_chiffre(T),它使用ord()函数chiffre_lettre(T)将字符串中的每个字符转换为一个数字,该函数与chr()相反,并且由于这些函数创建了4个数字块,我需要在RSA中使用5个数字块进行加密,以防止频率分析。问题是ord函数不能很好地处理法语口音"é“"à"...因此,我对使用bytearray方法很感兴趣,但我不知道如何使用它。
我怎样才能让这个程序带着口音工作。例如,字节数组的加密和解密不适用于"é“和"à”。
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发布于 2019-05-26 03:36:05
参考这篇文章:https://stackoverflow.com/a/2788599
你需要的是
>>> '\xc3\xa9'.decode('utf8')
u'\xe9'
>>> u = '\xc3\xa9'.decode('utf8')
>>> u
u'\xe9'
>>> ucd.name(u)
'LATIN SMALL LETTER E WITH ACUTE'https://stackoverflow.com/questions/56306869
复制相似问题