Python实现英文文章加密传送,收到后进行解密
2024-09-04 03:47:15
思路:将I Love You这样的字符串中的每一个字符,将他的Unicode码都就进行加或减去一个特定的数,
在传送过程中,如果被截获,获取的也是一段混乱的文章,当收到这段文章后,按相同的方式对Unicode编码减去或加上这个特定的数,就回到了原来的值,
注意:空格不做处理
小写字母,大写字母加或减去特定数后可能出现越过英文字母的Unicode码的边界,需要做处理:
message = input("Enter a message:")
key = input("Enter shift number:")
secret_message="" for lett in message:
unicode = ord(lett)+int(key)
if lett.isalpha():
if lett.isupper():
if unicode>ord('Z'):
unicode-=
if unicode<ord("A"):
unicode+=
if lett.islower():
if unicode > ord('z'):
unicode -=
if unicode < ord("a"):
unicode +=
secret_message+=chr(unicode)
else:
secret_message+=lett
print("加密后的字符串:",secret_message) print("****************变成明文的步骤*************")
orig_message=""
key=-*int(key)
for lett in secret_message:
unicode = ord(lett) + int(key)
if lett.isalpha():
if lett.isupper():
if unicode > ord('Z'):
unicode -=
if unicode < ord("A"):
unicode +=
if lett.islower():
if unicode > ord('z'):
unicode -=
if unicode < ord("a"):
unicode +=
orig_message += chr(unicode)
else:
orig_message += lett
print("明文是:",orig_message)
最新文章
- 2. K线学习知识二
- POJ1273Drainage Ditches[最大流]
- Visual Studio 插件AnkhSvn 更改Svn URL和登录信息
- HTTP 协议缓存
- ReorderList 的使用
- 【Ubuntu14.04.1】设置开机可以Root用户身份登录
- seajs 使用 jquery插件
- GoldenGate 之 Bounded Recovery说明
- Java---实力弹弹球,弹弹弹
- CSS选择器列表
- 2015傅富泰写——STRING权
- VS2010 下编译 cocos2d-x-2.1.4
- 时钟(AnalogClock和DigitalClock)的功能与用法
- codeforces A. Orchestra B. Island Puzzle
- 和我一起学习爬虫之HTTP/HTTPS抓包工具--Fiddler
- asp.net网页上获取其中表格中的数据(爬数据)
- Tecplot: Legend和图像中 Dashed/Dash dot/Long dash 等虚线显示没有区别的问题
- 2017.07.14【NOIP提高组】模拟赛B组
- 如何通过代码设置WPF控件的字体,颜色
- 本地构建:Gulp