Skip to content

Commit 0684d78

Browse files
committed
Fixed minor errors
1 parent 7fc5ca6 commit 0684d78

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

ciphers/caesar_cipher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pyfiglet
66

7-
87
def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
98
"""
109
encrypt
@@ -73,8 +72,9 @@ def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
7372
# Use the provided alphabet if given, otherwise default to ascii_letters (a-z + A-Z)
7473
alpha = alphabet or ascii_letters
7574

76-
# Create a shifted version of the alphabet by the key
77-
# This rotated alphabet will be used for mapping original characters to encrypted characters
75+
# Create a shifted version of the alphabet by the key.
76+
# This rotated alphabet will be used for mapping original characters
77+
# to encrypted characters.
7878
shifted = alpha[key % len(alpha) :] + alpha[: key % len(alpha)]
7979

8080
# Create a translation table: original alphabet -> shifted alphabet
@@ -97,7 +97,7 @@ def encrypt_file(
9797
alpha = alphabet or ascii_letters
9898

9999
# Open input file for reading and output file for writing
100-
with open(input_path, "r") as fin, open(output_path, "w") as fout:
100+
with open(input_path) 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,7 +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:
195+
with open(input_path) as fin, open(output_path, "w") as fout:
196196
# Read the input file line by line to avoid loading the entire file into memory
197197
for line in fin:
198198
# Encrypt the current line using the encrypt function

0 commit comments

Comments
 (0)