python实现移位加密和解密
作者:吉米多的围棋 发布时间:2022-03-20 09:09:27
标签: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
0
投稿
猜你喜欢
- 网页广告 Banner 设计图文手册:采用以下要点来改善你的BANNER。广告并不便宜。 确信你的广告被第一时间读到。使用像这样的Sans
- 在开始之前先说一点,DOM是非常容易理解的,但是大家说的太官方,让人很是难于理解,我们就用非常简单的语言翻译一遍。加深对DOM的理解,从而对
- 从其他语言转入Go语言的同学经常会陷入一个思考:如何创建一个单例?有些同学可能会把其它语言中的双检锁模式移植过来,双检锁模式也称为懒汉模式,
- QTimer控件介绍如果在应用程序中周期性地进行某项操作,比如周期性的检测主机的cpu值,则需要用到QTimer定时器,QTimer类提供了
- 简介:单例模式可以保证一个类仅有一个实例,并提供一个访问它的全局访问点。适用性于当类只能有一个实例而且客户可以从一个众所周知的访问点访问它,
- 本文实例讲述了Python3.6日志Logging模块简单用法。分享给大家供大家参考,具体如下:Logging是一个很方便的模块,用来打印日
- Git跟其他版本控制系统一样,可以打标签(tag)标记一个版本号。发布一个版本时,我们通常先在版本库中打一个标签,这样,就唯一确定了打标签时
- 故障描述percona5.6,mysqldump全备份,导入备份数据时报错Duplicate entry 'hoc_log99-it
- 一:购物车管理功能1.添加商品(不重复添加)、2.删除商品(购物车中有的才能删除)、3.查看购物车4.退出系统产品列表products =
- 发送普通邮件发送文本和html普通邮件如下:from email.header import Headerfrom email.mime.t
- 信号和槽机制是 QT 的核心机制,要精通 QT 编程就必须对信号和槽有所了解。信号和槽是一种高级接口,应用于对象之间的通信,它是 QT 的核
- 一、安装xlrd地址下载后,使用 pip install .whl 安装即好。查看帮助:>>> import xlrd&g
- 首先,我们看看models.py里的模型,有个upload_to参数,为了和过去一刀两断,楼主决定给upload_to赋值一个新的值叫ava
- 一、hashlib模块什么是哈希模块:hashlib模块是一种加密模块,内部存有多种加密类型加密的作用:可将明文数据进行加密,转换成一串密文
- SQL Server执行动态SQL的话,应该如何实现呢?下面就为您介绍SQL Server执行动态SQL两种正确方式,希望可以让您对SQL
- 全局引用公共的组件及公共的JS文件1. 创建一个公共的目录 timeline ,里面包含 timeline.js 和 timeline.vu
- 一、需求描述web 自动化测试/python爬虫往往会遇到扫码登录的情况,不是所有的网站都支持用户密码登录,遇到这种扫码登录的情况会阻碍我们
- 1.概念百度百科:笛卡尔乘积是指在数学中,两个集合X和Y的笛卡尔积(Cartesian product),又称直积,表示为X &ti
- 设计单个页面,一点一点做就行了,但处理的页面多了,每个页面都一点点的做下去是非常费时费力的,特别是当许
- fmtfmt是go语言中的格式化输入输出库,其中主要分为两个部分,分别是输出部分和输入部分。输出PrintPrint函数的主要功能是输出,和