(1)在键盘上进行查找比划,观察形状①------形状------②------圈起来------
(2)键盘坐标加密,法1.- - -以字母所在列为横坐标,数字行为纵坐标;法2- - - 数字行为横坐标,以字母所在列为纵坐标
常用“/”或“ ” 分割,而有些在线编译器无法识别,其中莫斯码表包含少
import Morse
MorseList = {
".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G",
"....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N",
"---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T",
"..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z",
"-----": "0", ".----": "1", "..---": "2", "...--": "3", "....-": "4",
".....": "5", "-....": "6", "--...": "7", "---..": "8", "----.": "9",
".-.-.-": ".", "---...": ":", "--..--": ",", "-.-.-.": ";", "..--..": "?",
"-...-": "=", ".----.": "'", "-..-.": "/", "-.-.--": "!", "-....-": "-",
"..--.-": "_", ".-..-.": '"', "-.--.": "(", "-.--.-": ")", "...-..-": "$",
". ...": "&", ".--.-.": "@", ".-.-.": "+","----.--": "{","-----.-": "}"
}
def morse(string, sign):
# 分割,字符串string,分割标识符sign
lists = string.split(sign)
for code in lists:
print(MorseList.get(code), end="")
#get(code)后可加.lower()
if __name__ == "__main__":
Morse.morse("..-. .-.. .- --.", " ")
'''加密
a=int(input('请输入密钥:'))
s=input('请输入字符串')
print(''.join([chr((ord(i)-97+a)%26+97) for i in s]))
'''
#解密
txt = input('请输入密文').strip()
n = input('是否需要推荐(Y/N)').strip()
for i in range(1,26):
plain=''
for j in txt:
if j.islower():
plain = plain + chr(97+(ord(j)-i-97)%26)
elif j.isupper():
plain = plain + chr(65+(ord(j)-i-65)%26)
else:
plain = plain + j
if n.lower() == 'y':
key = ('flag','ctf','key')
for m in key:
if m in plain:
print('明文可能是:',plain)
print()
break
elif n.lower() == 'n':
print(plain,end='')
print()
特点:密文很长
有可能是大写算a或b的一种,小写为另一种
也可能是文字的粗细关系
#培根24
a = [
"AAAAA", "AAAAB", "AAABA", "AAABB", "AABAA", "AABAB",
"AABBA", "AABBB", "ABAAA", "ABAAB", "ABABA", "ABABB",
"ABBAA", "ABBAB", "ABBBA", "ABBBB", "BAAAA", "BAAAB",
"BAABA", "BAABB", "BABAA", "BABAB", "BABBA", "BABBB",
]
b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '(ij)', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', '(uv)', 'w', 'x', 'y', 'z']
key = dict(zip(a,b))
txt = input('请输入密文:').replace(' ','').upper()
for i in range(0,len(txt),5):
print(key.get(txt[i:i+5]),end='')
#培根26
a = [
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba",
"aabbb", "abaaa", "abaab", "ababa", "ababb", "abbaa", "abbab",
"abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb",
"babaa", "babab", "babba", "babbb", "bbaaa", "bbaab",
]
b = 'abcdefghijklmnopqrstuvwxyz'
key = dict(zip(a,b))
txt = input('请输入密文:').replace(' ','').lower()
for i in range(0,len(txt),5):
print(key.get(txt[i:i+5]),end='')
#求乘法逆元
#y = (ax + b)%26,其中y为密文
#(a*m)%26 = 1,m为乘法逆元
txt = input('请输入密文:')
a = int(input('输入a的值:'))
b = int(input('输入b的值:'))
def get_inverse(a):
for i in range(1,27):
if a*i%26==1:
return i
def decipher(a, b, c):
a_inv = get_inverse(a)
p=[]
for i in c:
temp=(((ord(i)-97)-b)*a_inv)%26+97
p.append(chr(temp))
print(''.join(p))
#暴力破解
for i in txt:
for j in range(0,26):
if (a*j+b)%26 == ord(i)-97:#小写97,大写65
print(chr(j+97),end='')
#base64
import base64
txt = input('请输入密文:')
key = ''
for i in txt:
key = key + chr(ord(i)-4)
print(key)
txt = input('请输入密文:')
passward = input('请输入密钥:').lower()
key = [ord(i)-97 for i in passward]
flag = ''
for i in range(len(txt)):
if txt[i].islower():
flag += chr(97 + (ord(txt[i]) - 97 - key[i % len(key)]) % 26)
if txt[i].isupper():
flag += chr(65 + (ord(txt[i]) - 65 - key[i % len(key)]) % 26)
print(flag)
txt = input('请输入密文:')
key = input('请输入密钥:')
mi = []
for i in range(0,len(txt),7):
mi.append(txt[i:i+7])
for m,n in zip(mi,key):
print(chr(int(m,2) ^ ord(n)),end='')
#txt 为密文可以更换
txt = ['ZWAXJGDLUBVIQHKYPNTCRMOSFE',
'KPBELNACZDTRXMJQOYHGVSFUWI',
'BDMAIZVRNSJUWFHTEQGYXPLOCK',
'RPLNDVHGFCUKTEBSXQYIZMJWAO',
'IHFRLABEUOTSGJVDKCPMNZQWXY',
'AMKGHIWPNYCJBFZDRUSLOQXVET',
'GWTHSPYBXIZULVKMRAFDCEONJQ',
'NOZUTWDCVRJLXKISEFAPMYGHBQ',
'QWATDSRFHENYVUBMCOIKZGJXPL',
'WABMCXPLTDSRJQZGOIKFHENYVU',
'XPLTDAOIKFZGHENYSRUBMCQWVJ',
'TDSWAYXPLVUBOIKZGJRFHENMCQ',
'BMCSRFHLTDENQWAOXPYVUIKZGJ',
'XPHKZGJTDSENYVUBMLAOIRFCQW']
mi = 'HCBTSXWCRQGLES'
key = '2,5,1,3,6,4,9,7,8,14,10,13,11,12'
key = key.split(',')
#print(key) ['2', '5', '1', '3', '6', '4', '9', '7', '8', '14', '10', '13', '11', '12']
key = [int(i) for i in key]
#print(key) [2, 5, 1, 3, 6, 4, 9, 7, 8, 14, 10, 13, 11, 12]
flag = []
for m,n in zip(key,mi):#[txt[m-1].index(n):]切片
flag.append(txt[m-1][txt[m-1].index(n):] + txt[m-1][:txt[m-1].index(n)])
for i in range(26):
for j in flag:
print(j[i],end='')
print()
def zhalan(txt,key):
s = ''
for m in range(key):
for n in range(m,len(txt),key):
s = s + txt[n]
return s
if __name__ == '__main__':
txt = input('请输入密文:')
key = []
for i in range(2,len(txt)):
if len(txt)%i == 0:
key.append(i)
for j in key:
flag = zhalan(txt,j)
print(f'{j}栏:{flag}')
又称棋盘加密,将给定的明文加密为两两组合的数字
可以看作是 polybius 升级版,
其密码用A D F G X 代替了上述5个数字
明文:HELLO
密文:AD DA XX XX DX
赠CTF密码学离线工具
成功解压之后,点击 . b a t \color{RED}{.bat} .bat 文件即可
CTFcracktools
提取码:qb4f
需要词频分析离线软件的点击windecryptosetup
提取码:anto ↩︎