凯撒爆破脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
LETTERS1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LETTERS2="abcdefghijklmnopqrstuvwxyz"

text=input("请输入密文:")
for key in range(len(LETTERS)):
str=""
for i in text:
if i in LETTERS:
if i.isupper(): #密文字母为大写
num = LETTERS1.find(i) #在字母里搜索到密文字符的位置
num = num - key
if num<0:
num = num + len(LETTERS1)
str = str + LETTERS1[num] #将解密后字符追加到字符串末尾
elif i.islower(): #密文字母为小写
num = LETTERS2.find(i) #在字母里搜索到密文字符的位置
num = num - key
if num<0:
num = num + len(LETTERS2)
str = str + LETTERS2[num] #将解密后字符追加到字符串末尾
else:
str = str + i #如果密文中内容不在字母里则不解密,直接追加
print('第%d把钥匙的结果是%s' %(key, str)) #显示每一个可能的值

更新: 2024-10-08 15:53:54
原文: https://www.yuque.com/chaye-apqbl/vsc85q/rb4kptqaufh3x1f0


凯撒爆破脚本
http://example.com/2024/01/19/Crypto/古典密码/凯撒爆破脚本/
Author
chaye
Posted on
January 19, 2024
Licensed under