[DEV] Thirty-two number system

Post Python examples to help other users.
User avatar
Sam
Junior Member
Posts: 19
Joined: Tue Jul 03, 2018 3:00 pm
Location: Russian Federation
Contact:

[DEV] Thirty-two number system

Postby Sam » Fri Aug 30, 2019 1:57 pm

Code: Select all

TTNS = [
   0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41,   # ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A']
   0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4B, 0x4D, 0x4E,   # ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'M', 'N']
   0x4F, 0x50, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,   # ['O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
]

def DNS2TTNS(I):
   x = int(I / len(TTNS))
   y = int(I % len(TTNS))
   if(x == 0):
      return chr(TTNS[y])
   return '{}{}'.format(DNS2TTNS(x), chr(TTNS[y]))

def TTNS2DNS(S):
   if not all([var in [ chr(x) for x in TTNS ] for var in S.upper()]):
      return -1
   return sum([[ chr(x) for x in TTNS ].index(var) * len(TTNS) ** i for i, var in enumerate(reversed(S.upper()))])


ret = 3740122863 # 0xDEEDBEEF
ret1 = DNS2TTNS(ret)
print('[+] DNS2TTNS({}) = {}'.format(ret, ret1)) # 2WISE8F
ret2 = TTNS2DNS(ret1)
print('[+] TTNS2DNS({}) = {}'.format(ret1, ret2)) # 3740122863


I believe this system can be applied to large numerical data. :smile: (I understand that this is not a 32 system, but it is better than 16 xP)
It's a trap!

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: No registered users and 0 guests