$ cat writeup.md…
$ cat writeup.md…
hackthebox
Task: Decrypt a message encrypted with an affine cipher (ct = 123*pt + 18 mod 256). Solution: Find the modular inverse of 123 mod 256 using the Extended Euclidean Algorithm and reverse the transformation.
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
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?
Files:
chall.py — encryption scriptmsg.enc — encrypted messageimport 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()
The encryption uses an affine cipher — a linear transformation of each byte:
ct = (123 * pt + 18) % 256
Where:
pt — plaintext bytect — ciphertext byte123 — multiplier (a)18 — shift (b)256 — modulus (byte size)This is a reversible transformation if gcd(123, 256) = 1 (which is true since 123 is odd).
To reverse the formula:
ct = (123 * pt + 18) % 256
ct - 18 = 123 * pt % 256
pt = (ct - 18) * inv(123) % 256
We need to find the modular inverse of 123 modulo 256.
Using the Extended Euclidean Algorithm:
...
$ grep --similar