apppublic/appPublic/uniqueID.py

37 lines
564 B
Python
Raw Normal View History

2019-07-16 16:33:07 +08:00
import uuid
2022-02-24 21:55:20 +08:00
from nanoid import generate
2019-07-16 16:33:07 +08:00
def setNode(n='ff001122334455'):
2022-02-24 21:55:20 +08:00
pass
2019-07-16 16:33:07 +08:00
2022-02-24 21:55:20 +08:00
def getID(size=21):
return generate(size=size)
2019-07-16 16:33:07 +08:00
2023-05-30 16:11:46 +08:00
def validate_code(id, cnt=6):
b = int(len(id) / cnt)
j = 0
code = []
v = 0
print(f'{b=}, {cnt=}')
for c in id:
if j >= b:
v = v % 10
code.append(str(v))
j = 0
v += ord(c)
j += 1
if len(code) >= cnt:
break
2023-05-30 19:30:00 +08:00
return ''.join(code)
2023-05-30 16:11:46 +08:00
def check_code(id, code):
c = validate_code(id)
return c==code
if __name__ == '__main__':
id = getID()
code = validate_code(id)
b = check_code(id, code)
print(id, code, b)