29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
tracing=False
|
|
def trace(*args,**kwargs):
|
|
if tracing: print(*args,**kwargs)
|
|
|
|
def delimit(code,spacer=''):
|
|
if not spacer:
|
|
if len(code)==16: return code
|
|
if len(code)!=19: raise Exception('code length should be 19 for despacing, got',len(code),'from',code)
|
|
return code[0:4]+code[5:9]+code[10:14]+code[15:19]
|
|
if spacer:
|
|
if len(code)==19: return code
|
|
if len(code)!=16: raise Exception('code length should be 16 for spacing, got',len(code),'from',code)
|
|
return code[0:4]+spacer+code[4:8]+spacer+code[8:12]+spacer+code[12:16]
|
|
|
|
def scramble(code,unscramble=False):
|
|
n=int(code[0])
|
|
if unscramble: n=15-n # Because the 1st digit is left alone this needs to be +1
|
|
return code[0]+code[16-n:16]+code[1:16-n]
|
|
|
|
def combine(code,namehash=''):
|
|
if namehash: return code[0:2]+namehash[4:5]+code[2:6]+namehash[3:4]+code[6:8]+namehash[1:3]+code[8:11]+namehash[0:1]
|
|
charcode=code[0:2]+code[3:7]+code[8:10]+code[12:15]
|
|
namehash=code[15]+code[10:12]+code[7]+code[2]
|
|
return charcode,namehash
|
|
|
|
def fill0s(num,zeroes=0):
|
|
if not zeroes: return str(int(num))
|
|
n=str(num)
|
|
return '0'*(zeroes-len(n))+n |