1
0
mirror of synced 2024-11-28 07:50:51 +01:00
bemaniutils/bemani/tests/test_CardCipher.py
Jennifer Taylor 509cb4f0d9 Convert most of the format() string calls to f-strings using libcst.
Exact commands run were:

  python3 -m libcst.tool codemod convert_format_to_fstring.ConvertFormatStringCommand . --no-format
  python3 setup.py build_ext --inplace
2020-01-07 21:29:07 +00:00

36 lines
1.4 KiB
Python

# vim: set fileencoding=utf-8
import unittest
from bemani.common import CardCipher
class TestCardCipher(unittest.TestCase):
def test_internal_cipher(self) -> None:
test_ciphers = [
([0x68, 0xFC, 0xA5, 0x27, 0x00, 0x01, 0x04, 0xE0], [0xC7, 0xD0, 0xB3, 0x85, 0xAD, 0x1F, 0xD9, 0x49]),
([0x2C, 0x10, 0xA6, 0x27, 0x00, 0x01, 0x04, 0xE0], [0x33, 0xC6, 0xE6, 0x2E, 0x6E, 0x33, 0x38, 0x74]),
]
for pair in test_ciphers:
inp = bytes(pair[0])
out = bytes(pair[1])
encoded = CardCipher._CardCipher__encode(inp) # type: ignore
self.assertEqual(encoded, out, f"Card encode {encoded} doesn't match expected {out}")
decoded = CardCipher._CardCipher__decode(out) # type: ignore
self.assertEqual(decoded, inp, f"Card decode {decoded} doesn't match expected {inp}")
def test_external_cipher(self) -> None:
test_cards = [
("S6E523E30ZK7ML1P", "E004010027A5FC68"),
("78B592HZSM9E6712", "E004010027A6102C"),
]
for card in test_cards:
back = card[0]
db = card[1]
decoded = CardCipher.decode(back)
self.assertEqual(decoded, db, f"Card DB {decoded} doesn't match expected {db}")
encoded = CardCipher.encode(db)
self.assertEqual(encoded, back, f"Card back {encoded} doesn't match expected {back}")