Add more Python utilities
This commit is contained in:
parent
4350242e41
commit
87f567b602
|
@ -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()}")
|
|
@ -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)
|
Loading…
Reference in New Issue