Repository navigation
Expand file tree
/
Copy pathtransit.py
More file actions
executable file
·133 lines (125 loc) · 4.49 KB
/
Copy pathtransit.py
File metadata and controls
executable file
·133 lines (125 loc) · 4.49 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python3
# transit.py - generate / decode FDI Matalec Transit 500 and Transit 999 UIDs
#
# Adam Laurie <adam@algroup.co.uk>
# http://rfidiot.org/
#
# This code is copyright (c) Adam Laurie, 2009, All rights reserved.
# For non-commercial use only, the following terms apply - for all other
# uses, please contact the author:
#
# This code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
import sys
# import os
# import string
import rfidiot
try:
card = rfidiot.card
except Exception as e:
print("Couldn't open reader! (%s)" % e)
sys.exit(True)
args = rfidiot.args
chelp = rfidiot.help
card.info("transit v3.0b")
precoded = False
if not chelp and len(args) > 0 and len(args[0]) == 64:
print("\nDecode: ", end="")
card.TRANSITIDPrint(args[0])
if len(args) == 2:
if args[1] == "WRITE":
precoded = True
else:
print("Unrecognised option: " + args[1])
sys.exit(True)
else:
print()
sys.exit(False)
if not chelp and ((len(args) > 0 and len(args[0]) == 8) or precoded):
if precoded:
out = args[0]
else:
print("\nEncode: ", end="")
out = card.TRANSITIDEncode(args[0])
print(out)
if (len(args) == 2 and args[1] == "WRITE") or precoded:
while True:
# Q5 must be forced into Q5 mode to be sure of detection so try that first
if card.readertype == card.READER_ACG:
card.settagtype(card.Q5)
card.select()
if card.readertype == card.READER_ACG:
if not card.tagtype == card.Q5:
card.settagtype(card.ALL)
card.waitfortag("Waiting for blank tag...")
print(" Tag ID: {card.data}")
if card.tagtype == card.Q5:
x = input(" *** Warning! This will overwrite TAG! Proceed (y/n)? ").uppper()
if x == "N":
sys.exit(False)
if x == "Y":
break
else:
x = input(" Incompatible TAG! Hit <RETURN> to retry...")
writetag = True
print()
else:
writetag = False
# now turn it all back to 4 byte hex blocks for writing
outbin = ""
outhex = ["", "", "", "", ""]
# control block for Q5:
# carrier 32 (2 * 15 + 2)
# rf/? (don't care) - set to 00
# data not inverted
# manchester
# maxblock 2
print(" Q5 Control Block: ", end="")
q5control = "6000F004"
print(q5control)
for x in range(0, len(out), 8):
outbin += chr(int(out[x : x + 8], 2))
for x in range(0, len(outbin), 4):
print(" Q5 Data Block %02d:" % (x / 4 + 1), end="")
outhex[x / 4 + 1] = card.ToHex(outbin[x : x + 4])
print(outhex[x / 4 + 1])
if writetag is True:
print()
outhex[0] = q5control
for x in range(2, -1, -1):
if x != 0:
print(" Writing block %02x:" % x, end="")
if not card.writeblock(x, outhex[x]):
# we expect a Q5 to fail after writing the control block as it re-reads
# it before trying to verify the write and switches mode so is now no longer in Q5 mode
if x == 0:
print(" Control: " + outhex[x])
print()
print(" Done!")
else:
print("Write failed!")
sys.exit(True)
else:
print(outhex[x])
if card.readertype == card.READER_ACG:
card.settagtype(card.ALL)
print()
sys.exit(False)
print()
print(sys.argv[0] + " - Q5 encode / decode TRANSIT compliant IDs")
print("\nUsage: " + sys.argv[0] + " [OPTIONS] <UID> [WRITE]")
print()
print("\tIf a single 64 Bit BINARY UID is provided, it will be decoded according to the TRANSIT standard.")
print("\tAlternatively, specifying a 8 HEX digit UID will encode the 64 Bit BINARY with LRC and sentinels.")
print()
print("\tIf the WRITE option is specified, a Q5 will be programmed to emulate a TRANSIT tag.")
print()
sys.exit(True)