diff --git a/saison-2/sources/espionnage/bordurie/encrypt.py b/saison-2/sources/espionnage/bordurie/encrypt.py new file mode 100644 index 0000000..62f6ea8 --- /dev/null +++ b/saison-2/sources/espionnage/bordurie/encrypt.py @@ -0,0 +1,43 @@ +import sys + + +def rotate(x, y): + return (x + y) % 26 + + +def shift(letter, n): + x = ord(letter) - ord("A") + y = rotate(x, n) + return chr(ord("A") + y) + + +def rot13(message): + message = "".join([x for x in message if x.isalpha()]) + message = message.upper() + res = "" + for c in message: + res += shift(c, 13) + return res + + +def encrypt(key, message): + message = "".join([x for x in message if x.isalpha()]) + message = message.upper() + res = "" + i = 0 + for c in message: + x = ord(key[i % len(key)]) - ord("A") + res += shift(c, x) + i += 1 + return res + + +def main(): + cle = sys.argv[1] + message = sys.argv[2] + res = encrypt(cle, message) + print(res) + + +if __name__ == "__main__": + main() diff --git a/saison-2/sources/espionnage/bordurie/test_chiffre.py b/saison-2/sources/espionnage/bordurie/test_chiffre.py new file mode 100644 index 0000000..5178a6e --- /dev/null +++ b/saison-2/sources/espionnage/bordurie/test_chiffre.py @@ -0,0 +1,33 @@ +def rotate(x, y): + return (x + y) % 26 + + +def shift(letter, n): + x = ord(letter) - ord('A') + y = rotate(x, n) + return chr(ord('A') + y) + + +def rot13(message): + message = "".join([x for x in message if x.isalpha()]) + message = message.upper() + res = "" + for c in message: + res += shift(c, 13) + return res + + +def test_rotate(): + assert rotate(1, 3) == 4 + assert rotate(25, 3) == 2 + + +def test_shift(): + assert shift('A', 2) == 'C' + assert shift('E', 2) == 'G' + assert shift('Y', 3) == 'B' + + +def test_rot13(): + assert rot13('hello') == 'URYYB' + assert rot13('URYYB') == 'HELLO' diff --git a/saison-2/sources/espionnage/notes b/saison-2/sources/espionnage/notes new file mode 100644 index 0000000..a821ac2 --- /dev/null +++ b/saison-2/sources/espionnage/notes @@ -0,0 +1,6 @@ +Message-1 was encrypted with the key 'M'. Decrypt it + +Message-2 was encrypted with an unknown, 3 letters key. Decrypt it too, +knowing that it contains the string 'Plekszy-Gladz' + +spoiler: xdr diff --git a/saison-2/sources/espionnage/syldavie/decrypt.py b/saison-2/sources/espionnage/syldavie/decrypt.py new file mode 100644 index 0000000..22f7bba --- /dev/null +++ b/saison-2/sources/espionnage/syldavie/decrypt.py @@ -0,0 +1,62 @@ +import sys +import string + + +def rotate(x, y): + return (x - y) % 26 + + +def shift(letter, n): + x = ord(letter) - ord("A") + y = rotate(x, n) + return chr(ord("A") + y) + + +def rot13(message): + message = "".join([x for x in message if x.isalpha()]) + message = message.upper() + res = "" + for c in message: + res += shift(c, 13) + return res + + +def decrypt(key, message): + message = "".join([x for x in message if x.isalpha()]) + message = message.upper() + res = "" + i = 0 + for c in message: + x = ord(key[i % len(key)]) - ord("A") + res += shift(c, x) + i += 1 + return res + + +def try_with_key(key, message): + res = decrypt(key, message) + if "PLEKSZYGLADZ" in res: + return res + + +def main(): + message = sys.argv[1] + print(decrypt('N', message)) + + """ + message = sys.argv[1] + letters = string.ascii_uppercase + for a in letters: + for b in letters: + for c in letters: + key = a + b + c + res = try_with_key(key, message) + if res: + print(res) + print("key:", key) + return + """ + + +if __name__ == "__main__": + main() diff --git a/saison-2/sources/espionnage/syldavie/message-1.txt b/saison-2/sources/espionnage/syldavie/message-1.txt new file mode 100644 index 0000000..0732791 --- /dev/null +++ b/saison-2/sources/espionnage/syldavie/message-1.txt @@ -0,0 +1 @@ +GVAGVAFRFGRZCNERQHFCRPGERCERARMYRFZRFHERFARPRFFNVERF diff --git a/saison-2/sources/espionnage/syldavie/message-2.txt b/saison-2/sources/espionnage/syldavie/message-2.txt new file mode 100644 index 0000000..413ee11 --- /dev/null +++ b/saison-2/sources/espionnage/syldavie/message-2.txt @@ -0,0 +1 @@ +IHDXUVZKRISCBNJWBXIDUWVVODUBPRFQRIRGBUR