from Crypto.Cipher import AES from Crypto.Random import get_random_bytes from Crypto.Random.random import randrange from Crypto.Util.strxor import strxor as xor from Crypto.Util.number import bytes_to_long, long_to_bytes from hashlib import md5, sha3_256, sha1 def Enc(bloc, clef): if not isinstance(bloc, bytes) or not isinstance(clef, bytes): raise TypeError("le bloc et la clef doivent ĂȘtre de type bytes") if len(bloc) != 16 or len(clef) != 16: raise ValueError("le bloc et la clef doivent faire 16 octets") return AES.new(clef,AES.MODE_ECB).encrypt(bloc) def Dec(bloc, clef): if not isinstance(bloc, bytes) or not isinstance(clef, bytes): raise TypeError("le bloc et la clef doivent ĂȘtre de type bytes") if len(bloc) != 16 or len(clef) != 16: raise ValueError("le bloc et la clef doivent faire 16 octets") return AES.new(clef,AES.MODE_ECB).decrypt(bloc)