11import RFID
22
3- class RFIDUtil :
3+
4+ class RFIDUtil (object ):
45 rfid = None
56 method = None
67 key = None
@@ -20,19 +21,20 @@ def block_addr(self, sector, block):
2021
2122 def sector_string (self , block_address ):
2223 """
23- Returns sector and it's block representation of block address, eg. S01B03 for sector trailer in second sector
24+ Returns sector and it's block representation of block address, eg.
25+ S01B03 for sector trailer in second sector.
2426 """
2527 return "S" + str ((block_address - (block_address % 4 )) / 4 ) + "B" + str (block_address % 4 )
2628
2729 def set_tag (self , uid ):
2830 """
29- Sets tag for further operations.
30- Calls deauth() if card is already set.
31+ Sets tag for further operations.
32+ Calls deauth() if card is already set.
3133 Calls RFID select_tag().
3234 Returns called select_tag() error state.
3335 """
3436 if self .debug :
35- print ("Selecting UID " + str (uid ))
37+ print ("Selecting UID " + str (uid ))
3638
3739 if self .uid != None :
3840 self .deauth ()
@@ -48,7 +50,7 @@ def auth(self, auth_method, key):
4850 self .key = key
4951
5052 if self .debug :
51- print ("Changing used auth key to " + str (key ) + " using method " + ("A" if auth_method == self .rfid .auth_a else "B" ))
53+ print ("Changing used auth key to " + str (key ) + " using method " + ("A" if auth_method == self .rfid .auth_a else "B" ))
5254
5355 def deauth (self ):
5456 """
@@ -59,12 +61,12 @@ def deauth(self):
5961 self .last_auth = None
6062
6163 if self .debug :
62- print ("Changing auth key and method to None" )
64+ print ("Changing auth key and method to None" )
6365
6466 if self .rfid .authed :
6567 self .rfid .stop_crypto ()
6668 if self .debug :
67- print ("Stopping crypto1" )
69+ print ("Stopping crypto1" )
6870
6971 def is_tag_set_auth (self ):
7072 return (self .uid != None ) and (self .key != None ) and (self .method != None )
@@ -77,13 +79,13 @@ def do_auth(self, block_address, force=False):
7779 auth_data = (block_address , self .method , self .key , self .uid )
7880 if (self .last_auth != auth_data ) or force :
7981 if self .debug :
80- print ("Calling card_auth on UID " + str (self .uid ))
82+ print ("Calling card_auth on UID " + str (self .uid ))
8183
8284 self .last_auth = auth_data
8385 return self .rfid .card_auth (self .method , block_address , self .key , self .uid )
8486 else :
8587 if self .debug :
86- print ("Not calling card_auth - already authed" )
88+ print ("Not calling card_auth - already authed" )
8789 return False
8890
8991 def write_trailer (self , sector , key_a = (0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ), auth_bits = (0xFF , 0x07 , 0x80 ),
@@ -111,13 +113,13 @@ def rewrite(self, block_address, new_bytes):
111113 for i in range (len (new_bytes )):
112114 if new_bytes [i ] != None :
113115 if self .debug :
114- print ("Changing pos " + str (i ) + " with current value " + str (data [i ]) + " to " + str (new_bytes [i ]))
116+ print ("Changing pos " + str (i ) + " with current value " + str (data [i ]) + " to " + str (new_bytes [i ]))
115117
116118 data [i ] = new_bytes [i ]
117-
119+
118120 error = self .rfid .write (block_address , data )
119121 if self .debug :
120- print ("Writing " + str (data ) + " to " + self .sector_string (block_address ))
122+ print ("Writing " + str (data ) + " to " + self .sector_string (block_address ))
121123
122124 return error
123125
@@ -131,9 +133,9 @@ def read_out(self, block_address):
131133 error = self .do_auth (block_address )
132134 if not error :
133135 (error , data ) = self .rfid .read (block_address )
134- print (self .sector_string (block_address ) + ": " + str (data ))
136+ print (self .sector_string (block_address ) + ": " + str (data ))
135137 else :
136- print ("Error on " + self .sector_string (block_address ))
138+ print ("Error on " + self .sector_string (block_address ))
137139
138140 def dump (self , sectors = 16 ):
139141 for i in range (sectors * 4 ):
0 commit comments