1
0
mirror of synced 2024-11-24 06:20:12 +01:00

Slight tweaks to card cipher.

This commit is contained in:
Jennifer Taylor 2024-04-21 00:40:20 +00:00
parent f63247b605
commit c15ca02731
2 changed files with 5 additions and 7 deletions

View File

@ -21,6 +21,7 @@ class CardCipher:
INTERNAL_CIPHER = DES3.new(DES_KEY, DES3.MODE_ECB) INTERNAL_CIPHER = DES3.new(DES_KEY, DES3.MODE_ECB)
VALID_CHARS: Final[str] = "0123456789ABCDEFGHJKLMNPRSTUWXYZ" VALID_CHARS: Final[str] = "0123456789ABCDEFGHJKLMNPRSTUWXYZ"
REVERSE_CHARS: Final[Dict[str, int]] = {char: off for off, char in enumerate("0123456789ABCDEFGHJKLMNPRSTUWXYZ")}
CONV_CHARS: Final[Dict[str, str]] = { CONV_CHARS: Final[Dict[str, str]] = {
"I": "1", "I": "1",
"O": "0", "O": "0",
@ -28,9 +29,9 @@ class CardCipher:
@staticmethod @staticmethod
def __type_from_cardid(cardid: str) -> int: def __type_from_cardid(cardid: str) -> int:
if cardid[:2].upper() == "E0": if cardid[:4].upper() == "E004":
return 1 return 1
if cardid[:2].upper() == "01": if cardid[:2].upper() == "0":
return 2 return 2
raise CardCipherException("Unrecognized card type") raise CardCipherException("Unrecognized card type")
@ -123,10 +124,7 @@ class CardCipher:
groups = [0] * 16 groups = [0] * 16
for i in range(0, 16): for i in range(0, 16):
for j in range(0, 32): groups[i] = CardCipher.REVERSE_CHARS[cardid[i]]
if cardid[i] == CardCipher.VALID_CHARS[j]:
groups[i] = j
break
# Verify scheme and checksum # Verify scheme and checksum
if groups[14] != 1 and groups[14] != 2: if groups[14] != 1 and groups[14] != 2:

View File

@ -1,3 +1,3 @@
#! /bin/bash #! /bin/bash
flake8 bemani/ --ignore E203,E501,E252,E741,W503,W504,B006,B008,B009 | grep -v "migrations\/" flake8 bemani/ --ignore E203,E501,E252,E704,E741,W503,W504,B006,B008,B009 | grep -v "migrations\/"