├── LICENSE ├── README.md └── Xor ├── Main.py └── start.bat /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 LeRatGondin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xor-Encoder-Python 2 | ### Langage utilisé 3 | Python 3.9.4 4 | ## Systeme de chiffrage 5 | Le systeme de chiffrage est le [XOR](https://fr.wikipedia.org/wiki/Fonction_OU_exclusif) qui a pour principe d'utiliser la fonction binaire OU exclusif (A⊕B). 6 | 7 | # Comment ça marche ? 8 | ## Pour le chiffrage 9 | Le script converti le message en binaire et il converti la clé en [sha256](https://fr.wikipedia.org/wiki/SHA-2) , puis en binaire ensuite il utilise la fonction XOR 10 | pour creer le code chiffré 11 | ## Pour le dechiffrage 12 | Le script converti la clé en sha256 , et il refait le chifrement XOR mais dans l'autre sens pour pouvoir le decoder grâce a la clé et au message chiffré 13 | ### Screenshot 14 | ![Alt text](https://www.zupimages.net/up/21/16/i2qp.png) 15 | -------------------------------------------------------------------------------- /Xor/Main.py: -------------------------------------------------------------------------------- 1 | """ 2 | MIT License 3 | Copyright (c) 2021 LeRatGondin 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. 19 | """ 20 | from hashlib import sha256 , md5 , sha224 , sha512 , sha1 21 | 22 | import binascii 23 | import os 24 | def encode(): 25 | message = input(" Entrez le message a chiffrer : ") 26 | key = input(" Entrez la clé : ") 27 | 28 | keys1 = str(sha256(key.encode ('ascii')).hexdigest()) 29 | keys2 = str(md5(key.encode ('ascii')).hexdigest()) 30 | keys3 = str(sha224(key.encode ('ascii')).hexdigest()) 31 | keys4 = str(sha512(key.encode ('ascii')).hexdigest()) 32 | keys5 = str(sha1(key.encode ('ascii')).hexdigest()) 33 | 34 | keys = keys1 + keys2 + keys3 + keys4 + keys5 35 | keys = keys + keys4 + keys3 + keys2 +keys1 + keys 36 | 37 | 38 | message_en_binaire = '0' + bin(int.from_bytes(message.encode(), 'big'))[2:] 39 | keys_en_binaire = '0' + bin(int.from_bytes(keys.encode(), 'big'))[2:] 40 | while len(message_en_binaire) >> len(keys_en_binaire): 41 | keys_en_binaire += keys_en_binaire 42 | liste_message = list(message_en_binaire) 43 | liste_key = list(keys_en_binaire) 44 | 45 | longueur_message = len(message_en_binaire) 46 | 47 | try: 48 | a = 0 49 | resultat_binaire = "" 50 | for loop in range(longueur_message): 51 | if liste_key[a] == liste_message[a]: 52 | resultat_binaire = resultat_binaire + "0" 53 | else: 54 | resultat_binaire = resultat_binaire + "1" 55 | a = a + 1 56 | 57 | result = resultat_binaire 58 | print(f' Voici votre message chiffré {result}') 59 | except IndexError: 60 | print(" Votre clé est trop petite pour votre message veuillez l'agrandir") 61 | 62 | def decode(): 63 | message = input(" Entrez le message a dechiffrer : ") 64 | key = input(" Entrez la clé : ") 65 | 66 | keys1 = str(sha256(key.encode ('ascii')).hexdigest()) 67 | keys2 = str(md5(key.encode ('ascii')).hexdigest()) 68 | keys3 = str(sha224(key.encode ('ascii')).hexdigest()) 69 | keys4 = str(sha512(key.encode ('ascii')).hexdigest()) 70 | keys5 = str(sha1(key.encode ('ascii')).hexdigest()) 71 | 72 | keys = keys1 + keys2 + keys3 + keys4 + keys5 73 | keys = keys + keys4 + keys3 + keys2 +keys1 + keys 74 | 75 | message_en_binaire = message 76 | keys_en_binaire = '0' + bin(int.from_bytes(keys.encode(), 'big'))[2:] 77 | while len(message_en_binaire) >> len(keys_en_binaire): 78 | keys_en_binaire += keys_en_binaire 79 | liste_message = list(message_en_binaire) 80 | liste_key = list(keys_en_binaire) 81 | 82 | longueur_message = len(message_en_binaire) 83 | 84 | 85 | a = 0 86 | resultat_binaire = "" 87 | for loop in range(longueur_message): 88 | if liste_key[a] == liste_message[a]: 89 | resultat_binaire = resultat_binaire + "0" 90 | else: 91 | resultat_binaire = resultat_binaire + "1" 92 | a = a + 1 93 | try: 94 | binary_int = int(resultat_binaire, 2) 95 | byte_number = binary_int.bit_length() + 7 // 8 96 | binary_array = binary_int.to_bytes(byte_number, "big") 97 | result = binary_array.decode() 98 | result_list = list(result) 99 | first_char = result_list[1] 100 | while result.startswith(first_char): 101 | result = result[1:] 102 | print(f' Voici votre message decodé : {result}') 103 | except ValueError: 104 | print('Vous devez entrer une clé et/ou un message valide') 105 | pass 106 | 107 | 108 | 109 | if __name__ == '__main__': 110 | os.system('cls') 111 | mode = input(""" 112 | __ __ ______ _ 113 | \ \ / / | ____| | | 114 | \ V / ___ _ __ | |__ _ __ ___ ___ __| | ___ _ __ 115 | > < / _ \| '__| | __| | '_ \ / __/ _ \ / _` |/ _ \ '__| 116 | / . \ (_) | | | |____| | | | (__ (_) | (_| | __/ | 117 | /_/ \_\___/|_| |______|_| |_|\___\___/ \__,_|\___|_| 118 | by LeRatGondin 119 | 120 | Dechiffrer message : 1 121 | Chiffrer message : 2 122 | 123 | >>> """) 124 | if mode == "2": 125 | encode() 126 | if mode == "1": 127 | decode() 128 | -------------------------------------------------------------------------------- /Xor/start.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | python Main.py 3 | pause --------------------------------------------------------------------------------