Add more Python utilities

This commit is contained in:
Andrew 2023-07-05 15:02:36 +03:00 committed by GitHub
parent 4350242e41
commit 87f567b602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

16
utilities/BitCounter.py Normal file
View File

@ -0,0 +1,16 @@
import math
def count_bits(number):
return round(math.log2(number)) + 1
if __name__ == "__main__":
number = int(input('Input a number: '))
print(count_bits(number))
number *= 2
number_bytes = int.to_bytes(number, 49, byteorder='big')
print(f"0x{number_bytes.hex().upper()}")

31
utilities/KeyDecoder.py Normal file
View File

@ -0,0 +1,31 @@
import math
def count(b):
p = 0
for i in range(25):
p += pow(24, 24 - i) * b[i]
return p
if __name__ == '__main__':
charset = "BCDFGHJKMPQRTVWXY2346789"
key1 = "JCF8T-2MG8G-Q6BBK-MQKGT-X3GBB"
key2 = "FFFFF-GGGGG-HHHHH-JJJJJ-KKKKK"
key3 = "99999-99999-99999-99999-99999"
b = []
for x in key2:
if x != '-':
b.append(charset.index(x))
result = count(b)
print(f'Byte array: {b}; Length: {len(b)}\n{hex(result).upper()}')
data = result.to_bytes(15, byteorder='little')
hex_string = "".join("%02X " % b for b in data)
print(hex_string)