Skip to content

Instantly share code, notes, and snippets.

@GrayXu
Created September 7, 2023 10:53
Show Gist options
  • Save GrayXu/bba6cb7b2595d22a6fafdec0ef68c795 to your computer and use it in GitHub Desktop.
Save GrayXu/bba6cb7b2595d22a6fafdec0ef68c795 to your computer and use it in GitHub Desktop.
num2uid.py
import struct
num = 1111111111 # only for test
reverted = struct.pack('>L', num)
asChar = list(reverted)
result = asChar[0] ^ asChar[1] ^ asChar[2] ^ asChar[3]
uidr = hex(num)[2:]
assert(len(uidr)==8)
uid = uidr[6:8]+uidr[4:6]+uidr[2:4]+uidr[0:2]
valid = hex(result)[2:]
print(uid, valid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment