123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- # %%
- import csv
- # %%
- with open("vettSpec.csv", 'r') as file1:
- reader = csv.DictReader(file1)
- vettSpec = [row for row in reader]
- # %%
- testChar = 'Ҙ'
- print( testChar.encode("utf-32-le") )
- print( int.from_bytes(testChar.encode("utf-32-le"), 'little', signed=False) )
- pre = next((el['unicode'] for el in vettSpec if int(el['intcode']) == int.from_bytes(testChar.encode("utf-32-le"), 'little', signed=False)), None)
- res = bytes.fromhex(pre)
- while len(res)<4:
- res=res+b'\x00'
- print('pre-Res:', pre)
- print('Res-bytes:', res)
- print('Res:', res.decode("utf-32-le") )
- # %%
- # mmm...
- print('n'.encode("utf-32-be").hex().lstrip('0').upper())
- post = next((el['intcode'] for el in vettSpec if el['unicode'] == 'n'.encode("utf-32-be").hex().lstrip('0').upper()), None)
- print(post)
- byteini = int.to_bytes(int(post), 4, byteorder='little')
- byteini.decode('utf-32-le')
- # %%
- testoProva = 'C:/Users/Kora/Desktop/ndg2.gat4/ndg2.gat4/itxt/10n'
- # %%
- with open(testoProva, 'rb') as fille:
- azz = fille.read()
- # %%
- azz
- # %%
- def decode(char):
- pre = next((el['unicode'] for el in vettSpec if int(el['intcode']) == int.from_bytes(char.encode("utf-32-le"), 'little', signed=False)), None)
- resBytes = bytes.fromhex(pre)
- while len(resBytes)<4:
- resBytes=resBytes+b'\x00'
- res = resBytes.decode("utf-32-le")
- return res
- def decodeFromBytes(charBytes):
- pre = next((el['unicode'] for el in vettSpec if int(el['intcode']) == int.from_bytes(charBytes, 'little', signed=False)), None)
- resBytes = bytes.fromhex(pre)
- while len(resBytes)<4:
- resBytes=resBytes+b'\x00'
- res = resBytes.decode("utf-32-le")
- return res
- # %%
- str1 = ""
- for ind, char in enumerate(azz[:100]):
- print(char)
- str1 = str1+decode(char)
- print(str1)
- # %%
- print( azz[:4] )
- int.from_bytes(azz[:4], 'little', signed=False)
- # %%
- def decode(char):
- pre = next((el['unicode'] for el in vettSpec if int(el['intcode']) == int.from_bytes(char.encode("utf-32-le"), 'little', signed=False)), None)
- resBytes = bytes.fromhex(pre)
- while len(resBytes)<4:
- resBytes=resBytes+b'\x00'
- res = resBytes.decode("utf-32-le")
- return res
- testChar = 'Ҙ'
- print( testChar.encode("utf-32-le") )
- print( int.from_bytes(testChar.encode("utf-32-le"), 'little', signed=False) )
- pre = next((el['unicode'] for el in vettSpec if int(el['intcode']) == int.from_bytes(testChar.encode("utf-32-le"), 'little', signed=False)), None)
- print(pre)
- resBytes = bytes.fromhex(pre)
- print(resBytes)
- while len(resBytes)<4:
- resBytes=resBytes+b'\x00'
- print(resBytes)
- res = resBytes.decode("utf-32-le")
- print(res)
- # %%
|