我(还)我的RSA的项目,现在我可以成功地创建密钥,并加密与他们如何解密用RSA加密的块?
def encrypt(clear_message, public_key):
clear_list = convert_into_unicode (clear_message)
n = public_key[0]
e = public_key[1]
message_chiffre = str()
for i, value in enumerate (clear_list) :
encrypted_value = str(pow (int(value), e, n))
encrypted_message += (encrypted_value)
return encrypted_message
def convert_into_unicode (clear_message):
str_unicode = ''
for car in clear_message:
str_unicode += str (ord (car))
if len (str_unicode) % 5 != 0:
str_unicode += (5 - len (str_unicode) % 5) * '0'
clear_list = []
i = 5
while i <= len (str_unicode):
clear_list .append (str_unicode [i-5:i])
i += 5
return liste_claire
的字符串,例如,加密消息的“Hello World”返回['72101', '10810', '81113', '28711', '11141', '08100', '32330']
为clear_list
然后 '3863 111 1616 3015 1202 341 4096'
as encrypted_message
说明:主程序中调用的函数为encrypt()
。它使用另一个函数将字符串转换为unicode值的列表,但是因为我已经读过,因此只能通过频率分析才能找到明确的消息。
真的那么容易吗?
因为它可能是,我来我的主要问题。如你所知,一个字符的Unicode值是两位数或三位数字。在加密之前,Unicode值被分成5个数字组('stack' - >'115 116 97 99 107' - >'11511 69799 10700')
但问题是,当我想解密这个,我怎么知道我必须将那个字符串分开,以便一个数字代表一个字符? 我的意思是,以前的Unicode值可能是11或115(我知道它不可能是11,但这只是一个例子)。所以要解密然后找回角色,问题是,我不知道我需要多少数字。
我原本以为加入了“0”时的Unicode值是< 100,但 1),然后可以很容易地做同样的事情比以前用的频率分析 2)但是,当我进行加密,“ 087'会导致'467'和'089'会导致'046',所以问题仍然存在。
感谢您的帮助,这将是非常赞赏
请不要用RSA加密任意长的数据。 RSA只能以块加密长数据,但RSA并非[意指](http://crypto.stackexchange.com/q/14/13022)可用作分组密码。相反,数据使用新加密的AES加密。密钥又用RSA加密,因为它很短。这种所谓的[混合加密](https://en.wikipedia.org/wiki/Hybrid_cryptosystem)速度更快,更安全(如果您使用随机化和[已验证的分组加密模式](https://en.wikipedia)。组织/维基/ Block_cipher_mode_of_operation#Authenticated_encryption))。 –
Unicode码点数可以超过3个字符长。 – Wyzard
请参阅我对@Marteen Bodewes的回答 – Guil23