🧩 TryHackMe: Cipher's Secret Message – Detailed Walkthrough
🗂️ Room Overview
- Room Name: Cipher's Secret Message
- Category: Crypto
- Difficulty: Easy
- Objective: Decrypt a secret message encrypted with a shifting Caesar cipher and retrieve the flag.
🧠 Challenge Prompt
We are given:
-
An encrypted message:
a_up4qr_kaiaf0_bujktaz_qm_su4ux_cpbq_ETZ_rhrudm
The encryption logic:
Advertisement
from secret import FLAG
def enc(plaintext):
return "".join(
chr((ord(c) - (base := ord('A') if c.isupper() else ord('a')) + i) % 26 + base)
if c.isalpha() else c
for i, c in enumerate(plaintext)
)
with open("message.txt", "w") as f:
f.write(enc(FLAG))
- Instruction: Wrap the decoded message in the flag format
THM{}.
🔍 Step 1: Understand the Algorithm
The function enc() describes a modified Caesar cipher:
- It loops through each character in the message (
enumerategives both indexiand characterc). - If the character is alphabetical:
- Determine the base (
'A'for uppercase,'a'for lowercase). - Add the index
ito the alphabetical offset of the character. - Take modulo 26 to wrap around the alphabet.
- Convert back to a character.
- Determine the base (
- If it's not a letter (like a digit or underscore), it remains unchanged.
📌 Implication:
This cipher shifts each letter forward by its index position.
🔁 Step 2: Reversing the Cipher (Decryption Logic)
To decode:
Advertisement
- For every character at index
i, subtractifrom its position in the alphabet. - Use modulo 26 to handle negative wraparound.
- Preserve non-alphabetic characters.
✅ Decryption Function in Python:
def decrypt(ciphertext):
result = []
for i, c in enumerate(ciphertext):
if c.isalpha():
base = ord('A') if c.isupper() else ord('a')
decoded_char = chr((ord(c) - base - i) % 26 + base)
result.append(decoded_char)
else:
result.append(c)
return ''.join(result)
🧪 Step 3: Run the Decryption
🔐 Input:
a_up4qr_kaiaf0_bujktaz_qm_su4ux_cpbq_ETZ_rhrudm
🧾 Output:
a_sm4ll_crypt0_message_to_st4rt_with_THM_cracks
🏁 Step 4: Format the Flag
As per the instructions, wrap the result in THM{}:
🎯 Final Flag:
THM{a_sm4ll_crypt0_********************************}
✅ Summary
| Aspect | Value |
|---|---|
| Cipher Type | Caesar Variant (Index-based shifting) |
| Approach | Decryption by reversing the positional shift |
| Tools Used | Python |
| Skills Practiced | Cryptographic logic, Python iteration, ASCII math |
This walkthrough demonstrates how analyzing Python logic in challenges can help decode obfuscated or encrypted messages. Happy hacking!
Advertisement


![Roundcube RCE Vulnerability Explained [CVE-2025-49113] - TryHackMe Walkthrough](/_next/image?url=https%3A%2F%2Fc31ugca21tq8xtx5.public.blob.vercel-storage.com%2FPosts%2Froundcube-Dh1BChTvtXmws7bqTPo0g1xtuGH1vY.webp%3Fheight%3D600%26width%3D1200&w=1080&q=75)
