python的汉语凯撒密码_凯撒密码python加密
Python源代码:Note: working for negative shift numbers also
Note: if reverse shift then we do encode - decode message
Note: preserving spaces alsosmall_chars = [chr(item) for item in range(ord('a'), ord('z')+1)]
upper_chars = [item.upper() for item in small_chars]
def encode_chr(chr_item, is_upper_case):
'''
Cipher each chr_item.
'''
# setting orig and end order.
if is_upper_case:
orig_ord = ord('A')
end_ord = ord('Z')
else:
orig_ord = ord('a')
end_ord = ord('z')
# calculating shift
temp_ord = ord(chr_item)+shift
# calculating offset order with modulo.
# char is after end_ord, calculating offset
num_of_chars = 26
offset_ord = (temp_ord - end_ord - 1)%num_of_chars
return chr(orig_ord + offset_ord)
# enable while loop to repeat until status not 'y'
status = 'y'
while status == 'y':
# enter word to cipher.
word = raw_input("Word: ")
# enter char shift
shift = input("Shift: ")
# create cipher list variable
cipher = list()
# loop trough each char in word
for chr_item in word:
# encode just letters.
# replace non-alfa with underscore: "_"
if chr_item in upper_chars or chr_item in small_chars:
# set is_uppser_case to True for upper case chars.
is_upper_case = (chr_item in upper_chars) and True
# cipher char.
temp_chr = encode_chr(chr_item, is_upper_case)
# append ciphered char to list
cipher.append(temp_chr)
elif chr_item is ' ':
cipher.append(chr_item)
else:
cipher.append('_')
# print word
print word
# print ciphered word
print ''.join(cipher)
# repeat again for another word?
status = raw_input("Repeat? [y|n]: ")
测试用例:
^{pr2}$
输出:Note: if reverse shift then we do encode - decode message>>>
Word: "Mary Had a Little Lamb"
Shift: 1
"Mary Had a Little Lamb"
_Nbsz Ibe b Mjuumf Mbnc_
Repeat? [y|n]: y
Word: _Nbsz Ibe b Mjuumf Mbnc_
Shift: -1
_Nbsz Ibe b Mjuumf Mbnc_
_Mary Had a Little Lamb_
Repeat? [y|n]: n
>>>
python的汉语凯撒密码_凯撒密码python加密相关推荐
- python密码学凯撒密码_凯撒密码在Python
python密码学凯撒密码 Hello everyone, in this tutorial you'll learn about Caesar cipher in Python. If you ha ...
- python在建筑施工方面的应用_有哪些关于 Python 在建筑中的应用和教程?
2018.02.09更新 (發現距離上一次更新馬上就要兩年了--) 嗯,兩年間發生了很多事.我也莫名其妙跑到ETH來了. 做起了Fab的優化,python已經完全不能滿足效率和複雜度的要求,走上了C+ ...
- 利用python爬取知乎评论_一个简单的python爬虫,爬取知乎
一个简单的python爬虫,爬取知乎 主要实现 爬取一个收藏夹 里 所有问题答案下的 图片 文字信息暂未收录,可自行实现,比图片更简单 具体代码里有详细注释,请自行阅读 项目源码: 1 # -*- c ...
- linux 内存密码_您的密码错误是内存问题
linux 内存密码 Let's play a game. Look at this string of characters for a minute and then see if you can ...
- 用python画小猪佩奇动画片全集_教你用Python画小猪佩奇
刚过去几个月大家票圈肯定都被"小猪佩奇"."社会人"等字样刷屏了,不知道啥时候开始小猪佩奇成立社会人的标志,我说不出个所以然.但是相信很多人和我一样没有看过这系 ...
- python语言程序设计基础上海交通大学_北京交通大学:Python语言程序设计
『课程目录』:$ y0 q8 G3 Q" Z% p6 K│ ├─第一章概述, c) e/ m) X# s- B, r│ │ 1.1.1第1课时计算机起源 – 计算机发展史中三位里程碑人物,快 ...
- python六小时网络爬虫入门_一小时入门 Python 3 网络爬虫
原标题:一小时入门 Python 3 网络爬虫 作者:Jack-Cui,热爱技术分享,活跃于 CSDN 和知乎,开设的<Python3网络爬虫入门>.<Python3机器学习> ...
- python能做出什么样的网站_我能用Python做什么?
如果你想学Python,或者你刚开始学习Python,那么你可能会问:"我能用Python做什么?" 这个问题不好回答,因为Python有很多用途. 但是随着时间,我发现有Pyth ...
- 怎么知道 网站是否直接明文保存密码_忘记账号密码 浏览器记住了 怎么找回密码?...
对于健忘又没有使用保存密码插件的习惯的人来说,忘记密码是经常的事情. 而大家知道的也就是通过网站的找回密码选项,通过邮箱,手机号,人工等方式找回密码,但是如果是个小网站,没有找回的功能,或者当时是随便 ...
- python爬网页数据用什么_初学者如何用“python爬虫”技术抓取网页数据?
原标题:初学者如何用"python爬虫"技术抓取网页数据? 在当今社会,互联网上充斥着许多有用的数据.我们只需要耐心观察并添加一些技术手段即可获得大量有价值的数据.而这里的&quo ...
最新文章
- java python rsa加密_实现Java加密,Python解密的RSA非对称加密算法功能
- Promise 的基础用法
- P3321 [SDOI2015]序列统计(未解决)
- UI测试脸型软件,App脸型美化剖析|UI-影视-其他|观点|freshoil - 原创文章 - 站酷 (ZCOOL)...
- 智慧交通day04-特定目标车辆追踪03:siamese在目标跟踪中的应用-DaSiamRPN(2018)
- C++ 基类和派生类的virtual虚析构函数
- RPC与Apache Thift
- sql 的 where 和 having 的区别和用法
- 2020 cr节目源_2020/8月最新IPTV M3U8直播源分享
- 【MATLAB】三角函数
- 香农编码、哈夫曼编码、费诺编码的特点、优缺点及应用
- 触动精灵贝塞尔曲线Bezier Curve
- 热搜!中科大一博士生打印学位论文,分量堪比书籍!可“惨”的是...
- python三年a班的成绩_Python学习小结
- 基于RealSense的坐姿检测技术
- 假如自家APP被苹果下架了 你会怎么处理?
- 欧几里得算法(除法表达式)
- 开发历程之让暴风雨来得更猛烈些吧!
- Ylmf OS4开启3D
- 刘芳2008终极精选【再醉一次 精选】320K/mp3[紫色系]
热门文章
- 企业如何管理好业务代表
- bound2im.m
- RecSys - DHE (Deep Hash Embedding)
- 猫头虎为不同行业精心挑选的MacBook Pro配置指南之深度解析:如何根据行业需求精准选择MacBook Pro配置 - M1, M2, M3系列全面对比
- 2018年4月计算机组成原理试题,2018年4月自考计算机组成原理201804真题及答案
- PostgreSQL 关于时间复杂函数详解(长期更)
- 字符集和编码——Unicode(UTFUCS)深度历险
- 通过阅读以上内容,您可以了解到消费者行为习惯对推荐系统的影响,以及如何为推荐系统设计更符合用户习惯的产品。
- 动规(18)-并查集基础题——团伙
- Web Service获取天气预报