diff --git a/saison-2/sources/espionnage/bordurie/encrypt.py b/saison-2/sources/espionnage/bordurie/encrypt.py deleted file mode 100644 index 62f6ea8..0000000 --- a/saison-2/sources/espionnage/bordurie/encrypt.py +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 5178a6e..0000000 --- a/saison-2/sources/espionnage/bordurie/test_chiffre.py +++ /dev/null @@ -1,33 +0,0 @@ -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/chiffre.py b/saison-2/sources/espionnage/chiffre.py new file mode 100644 index 0000000..11c465b --- /dev/null +++ b/saison-2/sources/espionnage/chiffre.py @@ -0,0 +1,37 @@ +import string +import sys + + +def enlever_les_espaces(msg): + msg_compact = "" + for lettre in msg: + if lettre.isalpha(): + msg_compact += lettre + return msg_compact + + +def mettre_en_maj(msg): + msg_maj = msg.upper() + return msg_maj + + +def chiffre(pas, msg): + mesg_chiffre = "" + for lettre in msg: + mesg_chiffre += decale_lettre(pas, lettre) + return mesg_chiffre + + +def decale_lettre(pas, lettre): + let = ((ord(lettre) - 65) + pas) % 26 + return chr(let + 65) + + +def main(): + message_compact = enlever_les_espaces(sys.argv[2]) + message_maj = mettre_en_maj(message_compact) + message_chiffre = chiffre(int(sys.argv[1]), message_maj) + print(message_chiffre) + + +main() diff --git a/saison-2/sources/espionnage/chiffre2.py b/saison-2/sources/espionnage/chiffre2.py new file mode 100644 index 0000000..7c78e74 --- /dev/null +++ b/saison-2/sources/espionnage/chiffre2.py @@ -0,0 +1,44 @@ +import string +import sys + + +def enlever_les_espaces(msg): + msg_compact = "" + for lettre in msg: + if lettre.isalpha(): + msg_compact += lettre + return msg_compact + + +def mettre_en_maj(msg): + msg_maj = msg.upper() + return msg_maj + + +def chiffre(chaine, msg): + + mesg_chiffre = "" + i = 0 + + for lettre in msg: + pas = ord(chaine[i % len(chaine)]) - 65 + + mesg_chiffre += decale_lettre(pas, lettre) + i += 1 + return mesg_chiffre + + +def decale_lettre(pas, lettre): + let = ((ord(lettre) - 65) + pas) % 26 + return chr(let + 65) + + +def main(): + message_compact = enlever_les_espaces(sys.argv[2]) + message_maj = mettre_en_maj(message_compact) + # argv1 contient une chaine + message_chiffre = chiffre(sys.argv[1], message_maj) + print(message_chiffre) + + +main() diff --git a/saison-2/sources/espionnage/dechiffre.py b/saison-2/sources/espionnage/dechiffre.py new file mode 100644 index 0000000..e2cc99e --- /dev/null +++ b/saison-2/sources/espionnage/dechiffre.py @@ -0,0 +1,40 @@ +import string +import sys +import random + + + + + +def chiffre(chaine, msg): + + mesg_chiffre="" + i=0 + + for lettre in msg: + pas=ord(chaine[i%len(chaine)])-65 + + mesg_chiffre += decale_lettre(pas,lettre) + i+=1 + return mesg_chiffre + + +def decale_lettre(pas, lettre): + let=((ord(lettre)-65) + pas ) % 26 + return chr(let+65) + + +def main(): + for i in string.ascii_uppercase: + for j in string.ascii_uppercase: + for k in string.ascii_uppercase: + cle=i+j+k + msg_dechiffre = chiffre(cle, "IHDXUVZKRISCBNJWBXIDUWVVODUBPRFQRIRGBUR") + if "PLEKSZYGLADZ" in msg_dechiffre: + print (cle,msg_dechiffre) + #return te sort du main + return + +main() + +#IHDXUVZKRISCBNJWBXIDUWVVODUBPRFQRIRGBUR diff --git a/saison-2/sources/espionnage/syldavie/message-2.txt b/saison-2/sources/espionnage/encrypted-message.txt similarity index 100% rename from saison-2/sources/espionnage/syldavie/message-2.txt rename to saison-2/sources/espionnage/encrypted-message.txt diff --git a/saison-2/sources/espionnage/notes b/saison-2/sources/espionnage/notes deleted file mode 100644 index a821ac2..0000000 --- a/saison-2/sources/espionnage/notes +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 22f7bba..0000000 --- a/saison-2/sources/espionnage/syldavie/decrypt.py +++ /dev/null @@ -1,62 +0,0 @@ -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 deleted file mode 100644 index 0732791..0000000 --- a/saison-2/sources/espionnage/syldavie/message-1.txt +++ /dev/null @@ -1 +0,0 @@ -GVAGVAFRFGRZCNERQHFCRPGERCERARMYRFZRFHERFARPRFFNVERF