Sitemap

Member-only story

THM - Cipher’s Secret Message

2 min readJul 6, 2025

--

A writeup for the room “Cipher’s Secret Message” on TryHackMe

Sharpen your cryptography skills by analyzing code to get the flag.

https://tryhackme.com/room/hfb1cipherssecretmessage

Analysis

The challenge involves an encrypted message based on a substitution cipher.

The position of each letter in the plaintext determines the distance by which it is shifted to the right.

The reverse of the shift operation is achieved by performing the same shift in the opposite direction.

Solution

The encryption formula can be used for decryption with a single change, namely by subtracting the position i instead of adding it.

This is done to perform a left shift and return to the original character.

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)

Code

Here is the final script for solving the challenge.

If you enjoyed this article, feel free to leave a clap and follow me for more content like this.

Let me know in the comments if you have any questions or doubts.

Happy hacking! 🧑‍💻

--

--

Francesco Pastore
Francesco Pastore

Written by Francesco Pastore

An engineering student in Milan and a web developer for an IT company. Write about programming and cybersecurity topics.

No responses yet