思路:将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)

      

最新文章

  1. 2. K线学习知识二
  2. POJ1273Drainage Ditches[最大流]
  3. Visual Studio 插件AnkhSvn 更改Svn URL和登录信息
  4. HTTP 协议缓存
  5. ReorderList 的使用
  6. 【Ubuntu14.04.1】设置开机可以Root用户身份登录
  7. seajs 使用 jquery插件
  8. GoldenGate 之 Bounded Recovery说明
  9. Java---实力弹弹球,弹弹弹
  10. CSS选择器列表
  11. 2015傅富泰写——STRING权
  12. VS2010 下编译 cocos2d-x-2.1.4
  13. 时钟(AnalogClock和DigitalClock)的功能与用法
  14. codeforces A. Orchestra B. Island Puzzle
  15. 和我一起学习爬虫之HTTP/HTTPS抓包工具--Fiddler
  16. asp.net网页上获取其中表格中的数据(爬数据)
  17. Tecplot: Legend和图像中 Dashed/Dash dot/Long dash 等虚线显示没有区别的问题
  18. 2017.07.14【NOIP提高组】模拟赛B组
  19. 如何通过代码设置WPF控件的字体,颜色
  20. 本地构建:Gulp

热门文章

  1. linux安装后需要进行的一些基本设置
  2. Maven 3.6.1 下载及安装配置
  3. kotlin 泛型中类型投射
  4. SQL 里ESCAPE的用法
  5. PHP 调用C# WebService
  6. golang web框架设计5:配置设计
  7. centos7:ssh免密登陆设置
  8. 10-3 LVM(逻辑卷管理器)
  9. &lt;marquee&gt;滚动文字&lt;/marquee&gt;
  10. 使用FRP配置Windows远程控制