python核心编程 习题7-10
来源:互联网 发布:制作精品课程网站软件 编辑:程序博客网 时间:2024/05/17 01:20
7–10. 加密。
(a) 用上一个练习的思路编写一个"rot13"翻译器。 "rot13"是一个古老而又简单的加密方法,它把字母表中的每个字母用其后的第 13 个字母来代替。 字母表中前半部分字母将被映射到后半部分,而后半部分字母将被映射到前半部分,大小写保持不变。举例来说,'a'将被替换为'n','X'将被替换为'K'; 数字和符号不进行翻译。
(b)在你的解决方案的基础上加一个应用程序,让它提示用户输入准备加密的字符串(这个算法同时也可以对加密后的字符串进行解密)
这题比较简单,一天学了一章真累啊。。。
def rot13(string): '''将一个字符串变为rot13加密''' lens=len(string) newstring='' for i in range(0,lens): if 64<ord(string[i])<78 or 96<ord(string[i])<110: newstring=newstring+chr(ord(string[i])+13) elif 91>ord(string[i])>77 or 123>ord(string[i])>109: newstring=newstring+chr(ord(string[i])-13) else: newstring=newstring+string[i] return newstringif __name__ == '__main__': print('rot13加密/解密后结果为:%s'%rot13(input('源字符串为:')))
0 0
- python核心编程 习题7-10
- 《Python核心编程》第7章 习题
- 《Python核心编程》第7章 习题
- 《Python核心编程》第7章 习题
- python核心编程 9-10习题
- 《Python核心编程》第10章 习题
- 《Python核心编程习题》---chapter6
- 《Python核心编程习题》---chapter7
- 《Python核心编程习题》---chapter8
- 《Python核心编程习题》---chapter9
- 《Python核心编程习题》---chapte11
- Python 核心编程习题2
- python核心编程-第7章课后习题答案
- 《Python核心编程》习题7-5与13-4
- 《python 核心编程第二版第7章》习题
- Python核心编程v2.0 第10章习题答案
- <python核心编程第二版第10章>习题
- python核心编程第二章习题
- ubuntu 技巧
- 内存各个区域的区别
- Feedforward Deep Networks(要点)
- java中wait/notify机制
- CentOs7修改密码
- python核心编程 习题7-10
- ios-Label中显示多种样式的字体
- Scala---文件读取、写入、控制台操作
- abstract class和interface的区别
- 利用WMI打造完美三无后门(scrcons.exe)
- <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>意义
- caffe训练网络的实践
- Deep learning系列(十)随机梯度下降
- ORACLE异常总结