55- https://en.wikipedia.org/wiki/RC4
66"""
77
8+
89def ksa (key : bytes ) -> list [int ]:
910 """
1011 Key Scheduling Algorithm (KSA) for RC4.
@@ -77,10 +78,12 @@ def rc4(key: bytes, data: bytes) -> bytes:
7778 """
7879 s_box = ksa (key )
7980 keystream = prga (s_box , len (data ))
80- output = bytes ([
81- data_byte ^ keystream_byte
82- for data_byte , keystream_byte in zip (data , keystream )
83- ])
81+ output = bytes (
82+ [
83+ data_byte ^ keystream_byte
84+ for data_byte , keystream_byte in zip (data , keystream )
85+ ]
86+ )
8487 return output
8588
8689
@@ -93,17 +96,13 @@ def rc4(key: bytes, data: bytes) -> bytes:
9396 parser .add_argument (
9497 "mode" , choices = ["encrypt" , "decrypt" ], help = "Mode: encrypt or decrypt"
9598 )
96- parser .add_argument (
97- "key" , type = str , help = "Encryption/Decryption key"
98- )
99- parser .add_argument (
100- "input" , type = str , help = "Input text"
101- )
99+ parser .add_argument ("key" , type = str , help = "Encryption/Decryption key" )
100+ parser .add_argument ("input" , type = str , help = "Input text" )
102101
103102 args = parser .parse_args ()
104103
105- key_bytes = args .key .encode (' ascii' )
106- input_bytes = args .input .encode (' ascii' )
104+ key_bytes = args .key .encode (" ascii" )
105+ input_bytes = args .input .encode (" ascii" )
107106
108107 result_bytes = rc4 (key_bytes , input_bytes )
109108
@@ -114,6 +113,6 @@ def rc4(key: bytes, data: bytes) -> bytes:
114113 # if user passed hex data, decode it
115114 input_bytes = bytes .fromhex (args .input )
116115 result_bytes = rc4 (key_bytes , input_bytes )
117- print (result_bytes .decode (' ascii' ))
116+ print (result_bytes .decode (" ascii" ))
118117 except ValueError :
119118 print ("Error: Input must be valid hex string when decrypting." )
0 commit comments