Challenge Description
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?
Provided Files
chall.py
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()
msg.enc
6e0a9372ec49a3f6930ed8723f9df6f6720ed8d89dc4937222ec7214d89d1e0e352ce0aa6ec82bf622227bb70e7fb7352249b7d893c493d8539dec8fb7935d490e7f9d22ec89b7a322ec8fd80e7f8921
Solution
To solve the challenge we can either bruteforce:
decrypt.py
def decryption(msg):
result = ''
for char in msg:
for i in range(0, 127):
if((123 * i + 18) % 256) == char:
result += (chr(i))
break
return result
f = open('./msg.enc','r')
msg = bytes.fromhex(f.read())
f.close()
result = decryption(msg)
print(result)
$ python3 decrypt.py
Th3 nucl34r w1ll 4rr1v3 0n fr1d4y.
HTB{l00*********************************475}
or reverse the steps:
decrypt_rev.py
def decryption(msg):
result = ''
for char in msg:
char = char - 18
# 179 = 123^-1 mod 256
char = 179 * char % 256
result += (chr(char))
return result
f = open('./msg.enc', 'r')
msg = bytes.fromhex(f.read())
f.close()
result = decryption(msg)
print(result)
$ python3 decrypt_rev.py
Th3 nucl34r w1ll 4rr1v3 0n fr1d4y.
HTB{l00*********************************475}