python自动解密(python实现移位加密和解密)
类别:脚本大全 浏览量:2254
时间:2021-10-28 10:10:40 python自动解密
python实现移位加密和解密本文实例为大家分享了python实现移位加密和解密的具体代码,供大家参考,具体内容如下
代码很简单,就不多做解释啦。主要思路是将字符串转为ascii码,将大小写字母分别移位密钥表示的位数,然后转回字符串。需要注意的是,当秘钥大于26的时候,我使用循环将其不断减去26,直到密钥等效小于26为止。
|
def encrypt(): temp = raw_input ( "please input your sentence: " ) key = int ( raw_input ( "please input your key: " )) lista = map ( ord ,temp) lens = len (lista) for i in range (lens): a = lista[i] if 65 < = a < = 90 : a + = key while a > 90 : a - = 26 elif 97 < = a < = 122 : a + = key while a > 122 : a - = 26 lista[i] = a lista = map ( chr ,lista) lista = ''.join(lista) print lista def unencrypt(): temp = raw_input ( "please input your sentence: " ) key = int ( raw_input ( "please input your key: " )) lista = map ( ord , temp) lens = len (lista) for i in range (lens): a = lista[i] if 65 < = a < = 90 : a - = key while a < 65 : a + = 26 elif 97 < = a < = 122 : a - = key while a < 97 : a + = 26 lista[i] = a lista = map ( chr , lista) lista = ''.join(lista) print lista a = int ( raw_input ( "input 0 to encrypt and 1 to unencrypt" )) if a = = 0 : encrypt() elif a = = 1 : unencrypt() |
效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/St_laurence/article/details/83352951
您可能感兴趣
- python中怎么实现登录程序(详解Python用户登录接口的方法)
- python实现网络爬虫的步骤(Python实现的爬取小说爬虫功能示例)
- python 内存读写(详解python持久化文件读写)
- python 装饰器模式(python重试装饰器的简单实现方法)
- python实现列表删除重复元素(Python代码实现删除一个list里面重复元素的方法)
- pythonimage库(Python/Django后端使用PIL Image生成头像缩略图)
- python有哪几种赋值(关于python多重赋值的小问题)
- python中lambda函数是什么意思(python ---lambda匿名函数介绍)
- python人脸识别库(python3人脸识别的两种方法)
- pythonopt用法(Python语言检测模块langid和langdetect的使用实例)
- python3字符串格式化怎么操作(python3实现字符串操作的实例代码)
- python樱花绽放代码(新年快乐! python实现绚烂的烟花绽放效果)
- python socket 设置通信协议(详解python中TCP协议中的粘包问题)
- python写一个二叉树(Python二叉搜索树与双向链表转换算法示例)
- python浪漫表白源码(python七夕浪漫表白源码)
- scrapy框架爬取小说的正文内容(Scrapy框架爬取Boss直聘网Python职位信息的源码)
- 常见的喜阴植物有哪些 养室内盆栽就在这里选(常见的喜阴植物有哪些)
- 这8种耐阴植物,营造阴生植物花境,也是一个不错的选择(营造阴生植物花境)
- 览邦G08 Plus SMART WATCH 测评⑱ 全独立这才是智能手表该有的样子(览邦G08PlusSMART)
- 荣耀手表 GS 3 真机亮相 不支持无线充电(荣耀手表GS3)
- 通过体温就能为智能手表充电 原来是用NASA在空间站用的黑科技(通过体温就能为智能手表充电)
- 智能手表兼容Windows和Android 无需充电挑战苹果(智能手表兼容Windows和Android)
热门推荐
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9