11.7随缘每日一题----[SWPUCTF 2021 新生赛]我的银行卡密码
一道很有意思的题,misc少一点,更多是古典密码
下载附件,得到一个需要密码的pwd.md
题目描述:
这个压缩包又忘了密码,好像是我银行卡密码来着(6位)
直接ARCHPR爆破
密码是768521
打开pwd.md文件
下面是重头戏
看到这串数字也是想了一下ascii,但又不对,没什么思路,想到了之前专门做的keyboard的题----9键
'''前一个数是9键,后一个数是次数'''
c = '93 53 63 71 51 63 41 51 83 63 23 23 93 62 61 94 93 71 41 92 41 71 63 41 51 31 83 43 41 21 81 22 21 74 42'
table = ['ABC','DEF','GHI','JKL','MNO','PQRS','TUV','WXYZ']
c = c.split(' ')
for i in range(len(c)):
print(table[int(c[i][0])-2][int(c[i][1])-1],end='')
得到字符串YLOPJOGJVOCCYNMZYPGXGPOGJDVIGATBASH
md文档里还有一句话提示
The encryption scheme of next stage is decided by the last letters.
意思是下一阶段的加密方案由最后的字母决定。
发现刚才得到的字符串末尾有atbash----埃特巴什解密
去掉ATBASH,上脚本atbash.exp
# Python program to implement Atbash Cipher
# This script uses dictionaries to lookup various alphabets
lookup_table = {'A' : 'Z', 'B' : 'Y', 'C' : 'X', 'D' : 'W', 'E' : 'V',
'F' : 'U', 'G' : 'T', 'H' : 'S', 'I' : 'R', 'J' : 'Q',
'K' : 'P', 'L' : 'O', 'M' : 'N', 'N' : 'M', 'O' : 'L',
'P' : 'K', 'Q' : 'J', 'R' : 'I', 'S' : 'H', 'T' : 'G',
'U' : 'F', 'V' : 'E', 'W' : 'D', 'X' : 'C', 'Y' : 'B', 'Z' : 'A'}
def atbash(message):
cipher = ''
for letter in message:
# checks for space
if(letter != ' '):
#adds the corresponding letter from the lookup_table
cipher += lookup_table[letter]
else:
# adds space
cipher += ' '
return cipher
# Driver function to run the program
def main():
#encrypt the given message
'''加密'''
message = ''
print(atbash(message.upper()))
#decrypt the given message
'''解密'''
message = 'YLOPJOGJVOCCYNMZYPGXGPOGJDVIG'
print(atbash(message.upper()))
# Executes the main function
if __name__ == '__main__':
main()
得到新的字符串BOLKQLTQELXXBMNABKTCTKLTQWERT
末尾是qwert,键盘解密,去掉qwert
qwert.exp
#qwe密码解密,输入字符串,返回解密的明文
def encrypt_qwe(s):
DIC_QWE = "qwertyuiopasdfghjklzxcvbnm"
DIC_ABC = "abcdefghijklmnopqrstuvwxyz"
result=""
for i in s:
for j in range(len(DIC_ABC)):
if i==DIC_QWE[j]:
result=result+DIC_ABC[j]
return result
s="bolkqltqelxxbmnabktctklt"
s=s.lower()#统一转化为小写
s=s.strip().replace(" ","")#去掉空格
print(encrypt_qwe(s))
又获得新的字符串
xisraseacsuuxzykxreverse
reverse就是逆向,倒置
去掉reverse
reverse.exp
a="xisraseacsuuxzykx"
print(a[::-1])
得到xkyzxuuscaesarsix
发现caesarsix,是凯撒解密,移位6
去掉caesarsix
caesarsix.exp
def getMode():
while 1:
print('请选择加密或解密模式:')
print('加密e')
print('解密d')
mode = input()
if mode in "e d".split(' ',1):
return mode
else:
print("请重新输入:")
def getMessage():
print('请输入要执行的信息:')
return input()
def getKey():
print("请输入密钥:")
key = int(input())
return key
def encrypt(mode,message,key):
if mode == 'd':
key = -key
d = {}
for c in (65, 97):
for i in range(26):
d[chr(i+c)] = chr((i+key) % 26 + c)
print("结果为:")
print("".join([d.get(c, c) for c in message])) #这里套用了this.py文件
mode = getMode()
message = getMessage()
key = getKey()
encrypt(mode,message,key)
得到字符串restroom
最后再reverse一次
b="restroom"
print(b[::-1])
最终flag:
NSSCTF{moortser}
bingo完结撒花!!!
ps:急功近利不讨好,每日一题活神仙
简单提一下几个古典加密:
1.ATBASH----埃特巴什
a–z b–y c–x …x–c y–b z–a
替换加密的一种
2.qwert----键盘加密
qwert…vbnm以键盘从上到下的顺序依次替换a-z的26个英文字母
3.reverse倒过来就好
4.caesar凯撒这个不会建议从头来过