HackMyVM-Challenges-Crypto部分
城南花已开 Lv5

046

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def caesar_decrypt(ciphertext, cipher_alphabet, plain_alphabet):
"""
使用凯撒密码解密文本。

:param ciphertext: 加密的文本
:param cipher_alphabet: 密文字母表
:param plain_alphabet: 明文字母表
:return: 解密后的文本
"""
plaintext = ""
cipher_dict = {cipher_char: plain_char for cipher_char, plain_char in zip(cipher_alphabet, plain_alphabet)}

# 遍历每个字符
for char in ciphertext:
# 如果字符在密文字母表中
if char in cipher_dict:
# 添加解密后的字符
plaintext += cipher_dict[char]
else:
# 如果不是字母,直接添加
plaintext += char

return plaintext

# 密文字母表
cipher_alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
# 明文字母表
plain_alphabet = 'zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'

# 加密文本
ciphertext = 'HV1Dv3QoB3Ebx2oeym0P'
# 解密
plaintext = caesar_decrypt(ciphertext, cipher_alphabet, plain_alphabet)
print("解密后的文本:", plaintext)

061

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def three_to_decimal(three_str):
"""将三进制字符串转换为十进制整数"""
decimal = 0
for i, digit in enumerate(reversed(three_str)):
decimal += int(digit) * (3 ** i)
return decimal

def decode_three_binaries(three_binaries_str):
"""将多个ASCII字符拼接成一个字符串"""
three_binaries = three_binaries_str.split('t') # 将字符串分割成列表
decoded_chars = []
for three_str in three_binaries:
#将十进制整数转换为ASCII字符并加入到列表中
decoded_chars.append(chr(three_to_decimal(three_str)))
print(three_str)
return ''.join(decoded_chars)

# 示例
three_binaries_str = "2200t2212t10012t11120t10001t2222t2202t2001t10112t1211t10112t2200t1210t2222t1220t10112t10022t1210t10011t10112t2111t11020t1221t2111t2210t1220t2112t10112t1211t2001t11122t"
# 这是一个三进制数字符串,以`t`为分隔符
decoded_string = decode_three_binaries(three_binaries_str)
print(f"解码后拼接的字符串是: {decoded_string}")

066

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 定义替换规则
replacements = {
'fú': 'f',
'dī': 'd',
'bī': 'b',
'cī': 'c',
'ē': 'e',
'零': '0',
'一': '1',
'二': '2',
'三': '3',
'四': '4',
'五': '5',
'六': '6',
'七': '7',
'八': '8',
'九': '9'
}

# 原始数据
data = [
"四八 六三 六五 五fú 六四 六九 七二",
"四dī 六九 六五 七四 六五 六ē 六九",
"五六 六一 七四 六fú 六一 六五 六五",
"七bī 六cī 六九 五fú 七二 七三 六ē",
"五三 五fú 六ē 六dī 五fú 六五 六四",
"七零 六七 六七 七九 四三 五fú 七三",
"六五 七二 七三 五fú 六八 六六 七dī",
]

# 替换函数
def replace_text(text):
for key, value in replacements.items():
text = text.replace(key, value)
return text

# 处理数据并打印结果
for item in data:
result = replace_text(item)
print(result)

071

原文和密文有些地方没处理好,导致有些bug,所以在代码中手动添加了两个字符对应关系

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from collections import Counter

# 原文
original_text = 'Anonymous is a decentralized international activist and hacktivist collective and movement primarily known for its various cyberattacks against several governments, government institutions and government agencies, corporations and the Church of Scientology. Anonymous originated in 2003 on the imageboard 4chan representing the concept of many online and offline community users simultaneously existing as an "anarchic", digitized "global brain" or "hivemind". Anonymous members (known as anons) can sometimes be distinguished in public by the wearing of Guy Fawkes masks in the style portrayed in the graphic novel and film V for Vendetta.'
# 密文
cipher_text = 'JalanClmd Ad X fVyVazIXtAxVf AazVIaXzAlaXt XyzAiAdz Xaf oXyUzAiAdz ylttVyzAiV Xaf CliVCVaz TIACXIAtn Ualva glI Azd iXIAlmd ynEVIXzzXyUd XOXAadz dViVIXt OliVIaCVazd, OliVIaCVaz AadzAzmzAlad Xaf OliVIaCVaz XOVayAVd, ylITlIXzAlad Xaf zoV somIyo lg YyAVazltlOn. JalanClmd lIAOAaXzVf Aa 2003 la zoV ACXOVElXIf 4yoXa IVTIVdVazAaO zoV ylayVTz lg CXan latAaV Xaf lggtAaV ylCCmaAzn mdVId dACmtzXaVlmdtn VKAdzAaO Xd Xa "XaXIyoAy", fAOAzAxVf "OtlEXt EIXAa" lI "oAiVCAaf". JalanClmd CVCEVId (Ualva Xd Xalad) yXa dlCVzACVd EV fAdzAaOmAdoVf Aa TmEtAy En zoV vVXIAaO lg Qmn uXvUVd CXdUd Aa zoV dzntV TlIzIXnVf Aa zoV OIXToAy aliVt Xaf gAtC w glI wVafVzzX.'

# 统计原文中每个字符的出现次数
original_counter = Counter(original_text)

# 统计密文中每个字符的出现次数
cipher_counter = Counter(cipher_text)

# 创建一个空字典来存储字符对应关系
char_mapping = {}

# 找出字符对应关系
for cipher_char, count in cipher_counter.items():
# 找到原文中出现次数相同的字符
for orig_char, orig_count in original_counter.items():
if orig_char not in char_mapping and count == orig_count:
char_mapping[cipher_char] = orig_char
original_counter.subtract({orig_char: orig_count}) # 减去已匹配的字符
break
char_mapping['X'] = 'a'
char_mapping['t'] = 'l'
# 打印对应关系
for cipher_char, orig_char in char_mapping.items():
print(f"{cipher_char}:{orig_char}")

# 使用字典解密新的密文
new_cipher_text = "{Ad_zoV_EVdz_vVEdAzV_glI_imtaVIXEtV_iAIzmXt_CXyoAaVd}"

decrypted_text = ''
for char in new_cipher_text:
if char in char_mapping:
decrypted_text += char_mapping[char]
else:
decrypted_text += char

print("解密后的文本:", decrypted_text)

082

人都做麻了😭,慢慢尝试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
e2 92 bd 3c d8 5c dd ff 36 7b 00 00 00 00 01 d4 77 f0 9d 95 a0 35 d8 a0 de d8 35 dd be ff d5 01 00 00 00 00 5f f0 9d 99 a4 35 d8 27 de 00 5f 35 ff 00 00 00 01 d4 13 f0 9d 93 95 7d

e2 92 bd:Ⓗ #UTF-8(65001)|#UTF-7(65000)
3c d8 5c dd :🅜 #UTF-16BE(1200)
ff 36 :V #UTF-16BE(1201)

7b :{

00 01 d4 77:𝑷 #UTF-32BE(12001)
f0 9d 95 a0:𝕠 #UTF-7(65000)
35 d8 a0 de:𝚠 #UTF-16BE(1200)
d8 35 dd be:𝖾 #UTF-16BE(1201)
ff d5 01:𝗿 #UTF-32LE(12001)
5f :_ #UTF-8(65001)
f0 9d 99 a4:𝙤 #UTF-8(65001)
35 d8 27 de:𝘧 #UTF-16BE(1200)
5f :_ #UTF-8(65001)
35 ff:U #UTF_32LE(12000)
00 01 d4 13:𝐓 #UTF-32BE(12001)
f0 9d 93 95:𝓕 #UTF-7(65000)

7d:}

拼凑即可得到hmv{power_of_utf}
由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 258.9k