HackTheBox BabyEncryption WriteUp

题目

You are after an organised crime group which is responsible for the illegal weapon market in your country. As a secret agent, you have infiltrated the group enough to be included in meetings with clients. During the last negotiation, you found one of the confidential messages for the customer. It contains crucial information about the delivery. Do you think you can decrypt it?

思路

题目给出了密文和加密代码,加密代码如下:

import string
from secret import MSG

def encryption(msg):
    ct = []
    for char in msg:
        ct.append((123 * char + 18) % 256)
    return bytes(ct)

ct = encryption(MSG)
f = open('./msg.enc','w')
f.write(ct.hex())
f.close()

可以看出是对原文的ASCII码进行了一些计算。考虑到ASCII码的取值范围也就那么大,直接把原有的加密方式抄过来然后遍历就好了。

解题

解密代码:

msg = open('msg.enc','r').readline()

def judge(byte):
    for i in range(0,255,1):
        x = ((123 * i + 18) % 256)
        if x == byte:
            return chr(i)

bts = bytes.fromhex(msg)

flag = ''
for byte in bts:
    flag += judge(byte)

print(flag)

flag

后记

第一道Crypto题目,挺简单的。