#!/usr/bin/env python3 # Take each number mod 41 and find the modular inverse for the result. Then map to the following character set: 1-26 are the alphabet, 27-36 are the decimal digits, and 37 is an underscore. with open('message.txt') as file: content = file.read().strip() print("picoCTF{", end="") for n in content.split(' '): number = int(n) number %= 41 # NOTE: modular inverse number = pow(number, -1, 41) if number >=1 and number < 27: print(chr(number - 1 + ord('A')), end="") elif number >= 27 and number < 37: print(number - 27, end="") elif number == 37: print('_', end="") else: print() print(f"Code author seems to have forgotten a number.... {number}") exit(1) print("}")