Problem: [SWPUCTF 2021 新生赛]ez_caesar
[[toc]]
思路
- 解题大致思路
- aesar函数实现了一个简单的凯撒密码算法,其中每个字母都向后移动了5个位置。为了解密,我们需要将每个字母向前移动5个位置,要在其中加一个base64解码
EXP
- 具体攻击代码
import base64 def caesar_decrypt(ciphertext): str_list = list(ciphertext) i = 0 while i < len(ciphertext): if not str_list[i].isalpha(): str_list[i] = str_list[i] else: a = "A" if str_list[i].isupper() else "a" str_list[i] = chr((ord(str_list[i]) - ord(a) - 5) % 26 + ord(a)) i = i + 1 return ''.join(str_list) def decode_base64(encoded_str): base64_bytes = encoded_str.encode('ascii') message_bytes = base64.b64decode(base64_bytes) message = message_bytes.decode('ascii') return message encoded_str = "U1hYSFlLe2R0em1mYWpwc3RiaGZqeGZ3fQ==" flag = decode_base64(encoded_str) decrypted_flag = caesar_decrypt(flag) print(decrypted_flag)

总结
- 认识常见编码特征
