Cipher's Secret Message Walkthrough

Challenge Statement#

image

Solution#

Going throught the code, we can see that it shifts each character of the plaintext by its position in the message. The function adjusts alphabetic characters, while non-alphabetic ones stay the same.

To decrypt the message, we just need to reverse the process, by shifting the characters backwords by their position in the message. I wrote the following Python code for the decryption process.

def decrypt(ciphertext):
    result = []
    for i, c in enumerate(ciphertext):
        if c.isalpha():
            base = ord('A') if c.isupper() else ord('a')
            result.append(chr((ord(c) - base - i) % 26 + base))
        else:
            result.append(c)
    return "".join(result)

ciphertext = "a_up4qr_kaiaf0_bujktaz_qm_su4ux_cpbq_ETZ_rhrudm"

decoded_message = decrypt(ciphertext)
flag = f"THM{{{decoded_message}}}"
print("Flag:", flag)

Adapted from harishkannan05/THM-HackfinityBattle-Writeup under MIT.

Find us elsewhere

Merch, stickers, and moreSupport the work at the Solvere Labs shop