diff --git a/crypto/basic_mod2/message.txt b/crypto/basic_mod2/message.txt new file mode 100644 index 0000000..fef97b1 --- /dev/null +++ b/crypto/basic_mod2/message.txt @@ -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 \ No newline at end of file diff --git a/crypto/basic_mod2/solve.py b/crypto/basic_mod2/solve.py new file mode 100755 index 0000000..6c55b91 --- /dev/null +++ b/crypto/basic_mod2/solve.py @@ -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("}")