【python密码学编程】7.暴力破解凯撒加密法

 # _*_ coding:utf-8 _*_
#Caeser Ciper
import pyperclip
messgae = 'GUVF VF ZL FRPERG ZRFFTNR.'
nums = range(1,27)
mode = 'decrypt' #模式是加密而非解密(decrypt)
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' #常量要大写
translated = ''
for key in nums:
translated =''
for symbol in messgae:
if symbol in LETTERS:
num = LETTERS.find(symbol) #find()返回的是该字符在字符串中的位置 if mode == 'encrypt':#判断当前是加密还是解密过程
num = num+key
elif mode == 'decrypt':
num = num-key if num > len(LETTERS):#当处理后的数字脱离26个字母的数字范围后的处理
num = num - len(LETTERS)
elif num < 0:
num = num + len(LETTERS) translated = translated + LETTERS[num]#空字符串一个个加上翻译后得到的字符 else:
#如果要翻译的字符不在26个大写字母的范围内
translated =translated + symbol print key ,translated.lower()
1 ftue ue yk eqodqf yqeesmq.
2 estd td xj dpncpe xpddrlp.
3 drsc sc wi combod woccqko.
4 cqrb rb vh bnlanc vnbbpjn.
5 bpqa qa ug amkzmb umaaoim.
6 aopz pz tf zljyla tlzznhl.
7 znoy oy se ykixkz skyymgk.
8 ymnx nx rd xjhwjy rjxxlfj.
9 xlmw mw qc wigvix qiwwkei.
10 wklv lv pb vhfuhw phvvjdh.
11 vjku ku oa ugetgv oguuicg.
12 uijt jt nz tfdsfu nftthbf.
13 this is my secret messgae.
14 sghr hr lx rdbqds ldrrfzd.
15 rfgq gq kw qcapcr kcqqeyc.
16 qefp fp jv pbzobq jbppdxb.
17 pdeo eo iu oaynap iaoocwa.
18 ocdn dn ht nzxmzo hznnbvz.
19 nbcm cm gs mywlyn gymmauy.
20 mabl bl fr lxvkxm fxllztx.
21 lzak ak eq kwujwl ewkkysw.
22 kyzj zj dp jvtivk dvjjxrv.
23 jxyi yi co iushuj cuiiwqu.
24 iwxh xh bn htrgti bthhvpt.
25 hvwg wg am gsqfsh asgguos.
26 guvf vf zl frperg zrfftnr.
[Finished in 0.2s]

仅允许非商业转载,转载请注明出处

上一篇:apache的域名添加虚拟端口号


下一篇:vsftpd3.0.3配置