Cipher's Secret Message – TryHackMe Walkthrough

W
Waseem AkramVerified account
Researcher, Pentester, Dev
2025-07-06
3 min read
5,208 views
Featured image for Cipher's Secret Message – TryHackMe Walkthrough

🧩 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 (enumerate gives both index i and character c).
  • If the character is alphabetical:
    • Determine the base ('A' for uppercase, 'a' for lowercase).
    • Add the index i to the alphabetical offset of the character.
    • Take modulo 26 to wrap around the alphabet.
    • Convert back to a character.
  • 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, subtract i from 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

W

Waseem AkramVerified account

Researcher, Pentester, Dev

Cybersecurity expert and educator with a passion for sharing knowledge and helping others stay safe online.

Comments

Comments are currently disabled. Please share your thoughts on social media.

Related Articles