# -*- coding: UTF-8 -*-
from myXtea import myEncode, myDecode
import os

def string2JEX(string):
    return ' '.join("{:02X}".format(ord(c)) for c in string)

if __name__ == '__main__':
    
    print("Hello")
    key = [0x83, 0x5A, 0x4A, 0xED]
    
    """ Il faut concidérer la clé dans l'autre sens """
    
    key[0], key[1], key[2], key[3] = key[3], key[2], key[1], key[0]    
    
    this_path = os.path.dirname(__file__) + '/crypt/'
    
    for fichier in sorted(os.listdir(this_path)) :
        if '1261' in fichier :
            with open(this_path + fichier , 'r') as infile:
                buff = infile.read()
    #             print("Le fichier contient >>>>{}<<<<".format(buff))
                print("\n\nLe fichier {} contient >>>>{}<<<<".format( fichier ,  string2JEX(buff)))
                
                data_decode = myDecode(key , buff[8:])
                
                print("Je décrypte, ça donne >>>>{}<<<<".format( data_decode ))
                print("Je décrypte, ça donne >>>>{}<<<<".format(string2JEX( data_decode )))

