简体   繁体   English

如何使用RSA算法加密文本

[英]How to encrypt text using RSA algo

I need to encrypt texts written in a file and decrypt it, without using the PyCrypto library. 我需要加密写在文件中的文本并将其解密,而无需使用PyCrypto库。 The file will contain string type data. 该文件将包含字符串类型数据。 Now I want to convert the strings to int numbers so that I can apply the RSA keys on the integer values. 现在,我想将字符串转换为整数,以便可以将RSA密钥应用于整数值。 But I did not find any tutorial on how to convert texts into int. 但是我没有找到有关如何将文本转换为int的任何教程。 How to convert the strings into its integer value and Is there any better way of doing this? 如何将字符串转换为其整数值,还有更好的方法吗? then how? 那怎么办 Thank you. 谢谢。

I too had this project, and I did this: 我也有这个项目,我做到了:

First what you will need is to read the datas from the text file and save it to a list. 首先,您需要从文本文件中读取数据并将其保存到列表中。 You can use .split() which will do this : If the file contains only one line like this 您可以使用.split()来执行此操作:如果文件仅包含这样的一行

hello ! it will make it as 它将成为

list_of_the_file['h', 'e', 'l', 'l', 'o', ' ', '!']

Now as you have a list of all the letters that the file contains serially, you can use the ord() which will generate a unique value for each type of character for example a or more precisely ord(a) will give you the value 97 and it will return 97 only for the a present in the list not for any other character. 现在,有了文件中包含的所有字母的列表,您可以使用ord() ,它将为每种类型的字符生成一个唯一值,例如a或更精确的是ord(a)将为您提供值97并且它仅针对列表中的a会返回97 ,而不会返回其他任何字符。 Then you can apply the keys on that integer value and can store it in a list or a file. 然后,您可以将键应用于该整数值,并将其存储在列表或文件中。 Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM