How to encrypt text using RSA algo

China☆狼群 提交于 2019-12-11 17:46:01

问题


I need to encrypt texts written in a file and decrypt it, without using the PyCrypto library. 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. But I did not find any tutorial on how to convert texts into int. How to convert the strings into its integer value and Is there any better way of doing this? then how? Thank you.


回答1:


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

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. Then you can apply the keys on that integer value and can store it in a list or a file. Hope this will help.



来源:https://stackoverflow.com/questions/55282063/how-to-encrypt-text-using-rsa-algo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!