Description
Can you get sense of this code file and write the function that will decode the given encrypted file content. Find the encrypted file here flag_info and code file might be good to analyze and get the flag.
Setup
Local script
Download enc_flag and custom_encryption.py locally.
Inspect the script to understand the generator parameters, XOR key ("trudeau"), and how the cipher list was produced.
wget https://artifacts.picoctf.net/c_titan/18/enc_flag && \
wget https://artifacts.picoctf.net/c_titan/18/custom_encryption.py
Solution
This custom cryptography challenge involves reversing Diffie-Hellman and XOR operations. For another custom cipher challenge, check out C3, which uses a cyclical differential cipher.
- Step 1Rebuild the shared keycustom_encryption.py prints the values of a and b during test(). Plug them into generator(g, x, p) to recover the same shared key that encrypt() used.
- Step 2Invert encrypt()Write a decrypt() that divides each cipher entry by key * 311. This yields the "semi_cipher" string prior to the dynamic XOR stage.
- Step 3Reverse dynamic_xor_encryptCreate dynamic_xor_decrypt that runs the text_key XOR three times in reverse order (mirroring the encrypt function). Applying it to semi_cipher with key "trudeau" reveals the flag.python3 solver.py # uses decrypt + dynamic_xor_decrypt
Flag
picoCTF{custom_d2cr0pt6d_751a...}
The decrypted semi_cipher plus the reversed XOR routine yields the flag above.