Skip to content

Commit 41d1965

Browse files
committed
Merge pull request ondryaso#5 from penguintutor/master
Update to work with Python 3
2 parents e43f514 + 5d52ba8 commit 41d1965

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

ChipReader/KeyChange.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@
99

1010
def end_read(signal,frame):
1111
global run
12-
print "\nCtrl+C captured, ending read."
12+
print ("\nCtrl+C captured, ending read.")
1313
run = False
1414
rdr.cleanup()
1515

1616
signal.signal(signal.SIGINT, end_read)
1717

18-
print "Starting"
18+
print ("Starting")
1919
while run:
2020
(error, data) = rdr.request()
2121
if not error:
22-
print "\nDetected: " + format(data, "02x")
22+
print ("\nDetected: " + format(data, "02x"))
2323

2424
(error, uid) = rdr.anticoll()
2525
if not error:
26-
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
26+
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))
2727

28-
print "Setting tag"
28+
print ("Setting tag")
2929
util.set_tag(uid)
30-
print "\nAuthorizing"
30+
print ("\nAuthorizing")
3131
util.auth(rdr.auth_a, [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF])
32-
print "\nWriting modified bytes"
32+
print ("\nWriting modified bytes")
3333
util.rewrite(4, [None, None, 0x69, 0x24, 0x40])
3434
util.read_out(4)
3535
"""
36-
print "\nWriting zero bytes"
36+
print ("\nWriting zero bytes")
3737
util.rewrite(2, [None, None, 0, 0, 0])
3838
util.read_out(2)
39-
print "\nDeauthorizing"
39+
print ("\nDeauthorizing")
4040
util.deauth()
4141
"""
4242

4343
util.write_trailer(1, (0x12, 0x34, 0x56, 0x78, 0x96, 0x92), (0x0F, 0x07, 0x8F), 105, (0x74, 0x00, 0x52, 0x35, 0x00, 0xFF))
4444
util.deauth()
4545

46-
time.sleep(1)
46+
time.sleep(1)

ChipReader/RFIDUtil.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def set_tag(self, uid):
3232
Returns called select_tag() error state.
3333
"""
3434
if self.debug:
35-
print "Selecting UID " + str(uid)
35+
print ("Selecting UID " + str(uid))
3636

3737
if self.uid != None:
3838
self.deauth()
@@ -48,7 +48,7 @@ def auth(self, auth_method, key):
4848
self.key = key
4949

5050
if self.debug:
51-
print "Changing used auth key to " + str(key) + " using method " + ("A" if auth_method == self.rfid.auth_a else "B")
51+
print ("Changing used auth key to " + str(key) + " using method " + ("A" if auth_method == self.rfid.auth_a else "B"))
5252

5353
def deauth(self):
5454
"""
@@ -59,12 +59,12 @@ def deauth(self):
5959
self.last_auth = None
6060

6161
if self.debug:
62-
print "Changing auth key and method to None"
62+
print ("Changing auth key and method to None")
6363

6464
if self.rfid.authed:
6565
self.rfid.stop_crypto()
6666
if self.debug:
67-
print "Stopping crypto1"
67+
print ("Stopping crypto1")
6868

6969
def is_tag_set_auth(self):
7070
return (self.uid != None) and (self.key != None) and (self.method != None)
@@ -77,13 +77,13 @@ def do_auth(self, block_address, force=False):
7777
auth_data = (block_address, self.method, self.key, self.uid)
7878
if (self.last_auth != auth_data) or force:
7979
if self.debug:
80-
print "Calling card_auth on UID " + str(self.uid)
80+
print ("Calling card_auth on UID " + str(self.uid))
8181

8282
self.last_auth = auth_data
8383
return self.rfid.card_auth(self.method, block_address, self.key, self.uid)
8484
else:
8585
if self.debug:
86-
print "Not calling card_auth - already authed"
86+
print ("Not calling card_auth - already authed")
8787
return False
8888

8989
def write_trailer(self, sector, key_a=(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), auth_bits=(0xFF, 0x07, 0x80),
@@ -111,13 +111,13 @@ def rewrite(self, block_address, new_bytes):
111111
for i in range(len(new_bytes)):
112112
if new_bytes[i] != None:
113113
if self.debug:
114-
print "Changing pos " + str(i) + " with current value " + str(data[i]) + " to " + str(new_bytes[i])
114+
print ("Changing pos " + str(i) + " with current value " + str(data[i]) + " to " + str(new_bytes[i]))
115115

116116
data[i] = new_bytes[i]
117117

118118
error = self.rfid.write(block_address, data)
119119
if self.debug:
120-
print "Writing " + str(data) + " to " + self.sector_string(block_address)
120+
print ("Writing " + str(data) + " to " + self.sector_string(block_address))
121121

122122
return error
123123

@@ -131,9 +131,9 @@ def read_out(self, block_address):
131131
error = self.do_auth(block_address)
132132
if not error:
133133
(error, data) = self.rfid.read(block_address)
134-
print self.sector_string(block_address) + ": " + str(data)
134+
print (self.sector_string(block_address) + ": " + str(data))
135135
else:
136-
print "Error on " + self.sector_string(block_address)
136+
print ("Error on " + self.sector_string(block_address))
137137

138138
def dump(self, sectors=16):
139139
for i in range(sectors * 4):

ChipReader/Read.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@
99

1010
def end_read(signal,frame):
1111
global run
12-
print "\nCtrl+C captured, ending read."
12+
print ("\nCtrl+C captured, ending read.")
1313
run = False
1414
rdr.cleanup()
1515

1616
signal.signal(signal.SIGINT, end_read)
1717

18-
print "Starting"
18+
print ("Starting")
1919
while run:
2020
(error, data) = rdr.request()
2121
if not error:
22-
print "\nDetected: " + format(data, "02x")
22+
print ("\nDetected: " + format(data, "02x"))
2323

2424
(error, uid) = rdr.anticoll()
2525
if not error:
26-
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
26+
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))
2727

28-
print "Setting tag"
28+
print ("Setting tag")
2929
util.set_tag(uid)
30-
print "\nAuthorizing"
30+
print ("\nAuthorizing")
3131
#util.auth(rdr.auth_a, [0x12, 0x34, 0x56, 0x78, 0x96, 0x92])
3232
util.auth(rdr.auth_b, [0x74, 0x00, 0x52, 0x35, 0x00, 0xFF])
33-
print "\nReading"
33+
print ("\nReading")
3434
util.read_out(4)
35-
print "\nDeauthorizing"
35+
print ("\nDeauthorizing")
3636
util.deauth()
3737

38-
time.sleep(1)
38+
time.sleep(1)

ChipReader/UtilExample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#Request tag
1212
(error, data) = rdr.request()
1313
if not error:
14-
print "\nDetected"
14+
print ("\nDetected")
1515

1616
(error, uid) = rdr.anticoll()
1717
if not error:
1818
#Print UID
19-
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
19+
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))
2020

2121
#Set tag as used in util. This will call RFID.select_tag(uid)
2222
util.set_tag(uid)
@@ -46,4 +46,4 @@
4646
#We must stop crypto
4747
util.deauth()
4848

49-
time.sleep(1)
49+
time.sleep(1)

0 commit comments

Comments
 (0)