Advertisement
Guest User

aswreg_v2.py

a guest
Apr 18th, 2020
1,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | None | 0 0
  1. #!/usr/bin/python
  2. from bitstring import BitArray
  3. from sys import argv
  4.  
  5. import aswreg_v2core as core
  6.  
  7.  
  8. def textcode_to_bincode(textcode):
  9.     textcode = textcode.upper()
  10.     if len(textcode.replace('-','')) > 12:
  11.         return
  12.  
  13.     # no 0,1,O,I -- causes confusion, plus this amount allows for 5-bit indexing (32 values)
  14.     ref = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'
  15.     r30 = BitArray(32)
  16.     r29 = BitArray(32)
  17.  
  18.     for i in range(0,len(textcode)):
  19.         if (textcode[i] == '-'):
  20.             continue
  21.         r5 = BitArray('0b' + format(ref.index(textcode[i]),'032b'))
  22.         r3 = r30 << 5
  23.         r4 = r29 << 5
  24.         r3[27:32] ^= r29[0:5]
  25.         r0 = r5 >> 31
  26.         r29 = r4 | r5
  27.         r30 = r3 | r0
  28.  
  29.     return r30 + r29
  30.  
  31. def bincode_to_textcode(bincode):
  32.     ref = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'
  33.     textcode = ''
  34.  
  35.     for i in range(4,64,5):
  36.         textcode += ref[int(bincode[i:i+5].bin,2)]
  37.         if i == 19 or i == 39:
  38.             textcode += '-'
  39.  
  40.     return textcode
  41.  
  42.  
  43. def date_code(code,name,number,game,decade=0):
  44.     bincode = textcode_to_bincode(code)
  45.     hash1 = core.get_hash1(name,number,game)
  46.     hash2 = bincode ^ hash1
  47.     return core.timestamp_to_datetime(core.get_hash2_time(hash2),decade)
  48.  
  49.  
  50. def renew_code(code,name,number,game):
  51.     bincode = textcode_to_bincode(code)
  52.     hash1 = core.get_hash1(name,number,game)
  53.     hash2 = bincode ^ hash1
  54.     if game == 'Garendall': # Pillars of Garendall bug, just use 0xff
  55.         hash2 = core.set_hash2_time(hash2,BitArray('0xff'))
  56.     else:
  57.         hash2 = core.set_hash2_time(hash2,core.get_current_timestamp())
  58.     hash2 = core.make_hash2_valid(hash2)
  59.     return bincode_to_textcode(hash2 ^ hash1)
  60.  
  61.  
  62. def generate_code(name,number,game):
  63.     if game != 'EV Nova':
  64.         print 'Warning: generated codes will likely fail except for "EV Nova"'
  65.     hash1 = core.get_hash1(name,number,game)
  66.     hash2 = core.get_hash2(name,number,game)
  67.     return bincode_to_textcode(hash1 ^ hash2)
  68.  
  69.  
  70. if __name__ == '__main__':
  71.     try:
  72.         if argv[1] == 'date' and (len(argv) == 7 or len(argv) == 6):
  73.             if len(argv) == 7:
  74.                 print date_code(argv[2],argv[3],int(argv[4]),argv[5],int(argv[6]))
  75.             else:
  76.                 print date_code(argv[2],argv[3],int(argv[4]),argv[5])
  77.         elif argv[1] == 'renew' and len(argv) == 6:
  78.             print renew_code(argv[2],argv[3],int(argv[4]),argv[5])
  79.         elif argv[1] == 'generate' and len(argv) == 5:
  80.             print generate_code(argv[2],int(argv[3]),argv[4])
  81.         else:
  82.             raise
  83.     except:
  84.         usage = """Usage\n-----\n
  85. Renew codes with "renew" command:
  86. renew <code> "<name>" <number> "<game>"\n
  87. Check approximate date of a code with "date" command:
  88. date <code> "<name>" <number> "<game>" (optional: decade_offset)\n
  89. Generate codes with "generate" command
  90. generate "<name>" <number> "<game>"\n"""
  91.         print usage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement