1414class KeccakSHA3 :
1515 # Round constants
1616 _RC = [
17- 0x0000000000000001 , 0x0000000000008082 , 0x800000000000808A ,
18- 0x8000000080008000 , 0x000000000000808B , 0x0000000080000001 ,
19- 0x8000000080008081 , 0x8000000000008009 , 0x000000000000008A ,
20- 0x0000000000000088 , 0x0000000080008009 , 0x000000008000000A ,
21- 0x000000008000808B , 0x800000000000008B , 0x8000000000008089 ,
22- 0x8000000000008003 , 0x8000000000008002 , 0x8000000000000080 ,
23- 0x000000000000800A , 0x800000008000000A , 0x8000000080008081 ,
24- 0x8000000000008080 , 0x0000000080000001 , 0x8000000080008008
17+ 0x0000000000000001 ,
18+ 0x0000000000008082 ,
19+ 0x800000000000808A ,
20+ 0x8000000080008000 ,
21+ 0x000000000000808B ,
22+ 0x0000000080000001 ,
23+ 0x8000000080008081 ,
24+ 0x8000000000008009 ,
25+ 0x000000000000008A ,
26+ 0x0000000000000088 ,
27+ 0x0000000080008009 ,
28+ 0x000000008000000A ,
29+ 0x000000008000808B ,
30+ 0x800000000000008B ,
31+ 0x8000000000008089 ,
32+ 0x8000000000008003 ,
33+ 0x8000000000008002 ,
34+ 0x8000000000000080 ,
35+ 0x000000000000800A ,
36+ 0x800000008000000A ,
37+ 0x8000000080008081 ,
38+ 0x8000000000008080 ,
39+ 0x0000000080000001 ,
40+ 0x8000000080008008 ,
2541 ]
2642
2743 _ROT = [
2844 [0 , 36 , 3 , 41 , 18 ],
2945 [1 , 44 , 10 , 45 , 2 ],
3046 [62 , 6 , 43 , 15 , 61 ],
3147 [28 , 55 , 25 , 21 , 56 ],
32- [27 , 20 , 39 , 8 , 14 ]
48+ [27 , 20 , 39 , 8 , 14 ],
3349 ]
3450
3551 def __init__ (self , message : bytes , bits : int = 256 ):
@@ -92,9 +108,9 @@ def _absorb(self):
92108 padded = self ._pad (self .msg )
93109
94110 for off in range (0 , len (padded ), r ):
95- block = padded [off : off + r ]
111+ block = padded [off : off + r ]
96112 for i in range (0 , r , 8 ):
97- lane = struct .unpack ("<Q" , block [i : i + 8 ])[0 ]
113+ lane = struct .unpack ("<Q" , block [i : i + 8 ])[0 ]
98114 x = (i // 8 ) % 5
99115 y = (i // 8 ) // 5
100116 self .state [x ][y ] ^= lane
@@ -118,12 +134,14 @@ def _squeeze(self) -> bytes:
118134
119135# ================= CLI =================
120136
137+
121138def main ():
122139 parser = argparse .ArgumentParser (description = "SHA-3 hashing tool" )
123140 parser .add_argument ("-s" , "--string" , help = "String input" )
124141 parser .add_argument ("-f" , "--file" , help = "File input" )
125- parser .add_argument ("-l" , "--length" , type = int , default = 256 ,
126- choices = [224 , 256 , 384 , 512 ])
142+ parser .add_argument (
143+ "-l" , "--length" , type = int , default = 256 , choices = [224 , 256 , 384 , 512 ]
144+ )
127145
128146 args = parser .parse_args ()
129147
0 commit comments