44
55import pyfiglet
66
7+
78def encrypt (input_string : str , key : int , alphabet : str | None = None ) -> str :
89 """
910 encrypt
@@ -74,7 +75,7 @@ def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
7475
7576 # Create a shifted version of the alphabet by the key
7677 # This rotated alphabet will be used for mapping original characters to encrypted characters
77- shifted = alpha [key % len (alpha ):] + alpha [:key % len (alpha )]
78+ shifted = alpha [key % len (alpha ) :] + alpha [: key % len (alpha )]
7879
7980 # Create a translation table: original alphabet -> shifted alphabet
8081 table = str .maketrans (alpha , shifted )
@@ -96,8 +97,7 @@ def encrypt_file(
9697 alpha = alphabet or ascii_letters
9798
9899 # Open input file for reading and output file for writing
99- with open (input_path , 'r' ) as fin , open (output_path , 'w' ) as fout :
100-
100+ with open (input_path , "r" ) as fin , open (output_path , "w" ) as fout :
101101 # Read the input file line by line to avoid loading the entire file into memory
102102 for line in fin :
103103 # Encrypt the current line using the encrypt function
@@ -192,8 +192,7 @@ def decrypt_file(
192192 alpha = alphabet or ascii_letters
193193
194194 # Open input file for reading and output file for writing
195- with open (input_path , 'r' ) as fin , open (output_path , 'w' ) as fout :
196-
195+ with open (input_path , "r" ) as fin , open (output_path , "w" ) as fout :
197196 # Read the input file line by line to avoid loading the entire file into memory
198197 for line in fin :
199198 # Encrypt the current line using the encrypt function
0 commit comments