如何使用RSA算法加密文本 [英] How to encrypt text using RSA algo

查看:90
本文介绍了如何使用RSA算法加密文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要加密写在文件中的文本并将其解密,而无需使用PyCrypto库.该文件将包含字符串类型数据.现在,我想将字符串转换为整数,以便可以将RSA密钥应用于整数值.但是我没有找到有关如何将文本转换为int的任何教程.如何将字符串转换为其整数值,还有更好的方法吗?那怎么办谢谢.

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.

推荐答案

我也有这个项目,我做到了:

I too had this project, and I did this:

首先,您需要从文本文件中读取数据并将其保存到列表中.您可以使用 .split()来做到这一点:如果文件仅包含这样的一行

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

你好!,它将变为

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

现在,有了文件序列包含的所有字母的列表,您可以使用 ord(),它将为每种字符类型生成一个唯一值,例如 a或更确切地说,ord(a)将为您提供值 97 ,并且仅针对出现在其中的 a 返回 97 .列出任何其他字符.然后,您可以将键应用于该整数值,并将其存储在列表或文件中.希望这会有所帮助.

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.

这篇关于如何使用RSA算法加密文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆