Guest User

Untitled

a guest
May 4th, 2021
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import base64
  4. import sys
  5.  
  6. #================================================
  7. ### INPUT AREA ###
  8. # UID of NFC card to write to
  9. uid = '04512c7aca6680'
  10.  
  11. ## Token ID
  12. tid = 2
  13. # 1 = Figurine, 2 = Flat
  14.  
  15. ## Figurine ID
  16. fid = 0
  17. # Figurines:
  18. # 0 = Dragon, 1 = Fox, 2 = Ghost, 3 = Knight, 4 = ThankYou, 5 = Whale,
  19. # 6 = Black.Dragon, 7 = Black.Fox, 8 = Black.Knight, 9 = Black.Whale,
  20. # 10 = White.Dragon, 11 = White.Fox, 12 = White.Knight, 13 = White.Whale
  21. # Flats:
  22. # 0 = Generic Flat
  23. #================================================
  24.  
  25. ### PROGRAM CODE ###
  26. # Set fixed requirements
  27. figurines = [
  28.     'Dragon', 'Fox', 'Ghost', 'Knight', 'ThankYou', 'Whale', 'Black.Dragon',
  29.     'Black.Fox', 'Black.Knight', 'Black.Whale', 'White.Dragon', 'White.Fox',
  30.     'White.Knight', 'White.Whale',
  31. ]
  32. iv = bytes([0x80, 0x77, 0x51])  # always the same?
  33. nfc_secret = bytes([0x03, 0x9c, 0x25, 0x6f, 0xb9, 0x2e, 0xe8,
  34.     0x08, 0x09, 0x83, 0xd9, 0x33, 0x56])
  35.  
  36. # Print input parameters to screen
  37. print('UID to encode: ', uid)
  38. if tid == 1:
  39.     print('Token:          Figurine')
  40.     if fid < len(figurines):
  41.         print('Figurine:       ' + figurines[fid])
  42.     else:
  43.         sys.exit('Wrong Figurine ID! Aborting...')
  44. elif tid == 2:
  45.     print('Token:          Flat')
  46.     if fid == 0:
  47.         print('Figurine:       Generic Flat')
  48.     else:
  49.         sys.exit('Wrong Figurine ID! Aborting...')
  50. else:
  51.     sys.exit('Wrong Token ID! Aborting...')
  52.  
  53. # Convert uid to byte representation
  54. uid_b = []
  55. for i in range(0,len(uid),2):
  56.     uid_b.append(
  57.         int('0x'+uid[i:i+2], 16)
  58.     )
  59.  
  60. # Combine all input into d
  61. d = iv + tid.to_bytes(1, 'little') + fid.to_bytes(1, 'little') + bytes(uid_b)
  62.  
  63. # Use nfc_secret to encrypt d
  64. enc = []
  65. for i in range(0,12):
  66.     if i<3:
  67.         enc.append(d[i] ^ nfc_secret[i])
  68.     else:
  69.         enc.append(d[i] ^ nfc_secret[i] ^ d[i % 3])
  70.  
  71. # Encode encrypted string in base64
  72. result = base64.b64encode(bytes(enc))
  73.  
  74. # Print results to screen
  75. print('URL:            https://s.jooki.rocks/s/?s=' + result.decode('utf-8'))
Add Comment
Please, Sign In to add comment