crypto/basic_mod2

This commit is contained in:
Oystein Kristoffer Tveit 2024-09-02 23:42:46 +02:00
parent 8ad492d0a6
commit 222558e2e3
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1 @@
432 331 192 108 180 50 231 188 105 51 364 168 344 195 297 342 292 198 448 62 236 342 63

26
crypto/basic_mod2/solve.py Executable file
View File

@ -0,0 +1,26 @@
#!/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("}")