-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobib.py
More file actions
executable file
·57 lines (47 loc) · 1.72 KB
/
mobib.py
File metadata and controls
executable file
·57 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/env python3
import sys
from smartcard.System import readers
from smartcard.Exceptions import NoCardException
CALYPSO_CLA = [0x94]
SELECT_INS = [0xA4]
READ_RECORD_INS = [0xB2]
GET_RESPONSE_INS = [0xC0]
TICKETING_COUNTERS_FILE_ID = [0x20, 0x69]
def main():
local_readers = readers()
if local_readers:
if len(local_readers) == 1:
readerIndex = 0
else:
for i, reader in enumerate(local_readers):
print("[{}]: {}".format(i, reader))
readerIndex = int(input("Select a reader: "))
else:
print("No reader detected")
sys.exit(1)
try:
calypso = local_readers[readerIndex].createConnection()
calypso.connect()
except NoCardException:
print("No card connected")
sys.exit(1)
select_apdu = CALYPSO_CLA + SELECT_INS + [0x00, 0x00, 0x02] + TICKETING_COUNTERS_FILE_ID + [0x00]
data, sw1, sw2 = calypso.transmit(select_apdu)
if sw1 == 0x61:
get_response_apdu = [0x00] + GET_RESPONSE_INS + [0x00, 0x00, sw2]
data, sw1, sw2 = calypso.transmit(get_response_apdu)
read_record_apdu = CALYPSO_CLA + READ_RECORD_INS + [0x01, 0x04, 0x1D]
data, sw1, sw2 = calypso.transmit(read_record_apdu)
if sw1 == 0x90:
# FIXME: each chunk of remaining trips stored on 3 bytes?
#chunks = [data[x:x+3] for x in range(0, len(data), 3)]
#total = 0
#for chunk in chunks:
# total += chunk[2]
#print("Number of remaining trips: {}".format(tot = chunks[i][2] for i in chunks))
print("Number of remaining trips: {}".format(sum(data)))
else:
print("Error getting number of remaining trips")
sys.exit(1)
if __name__ == '__main__':
main()