Skip to content

Commit b803ab6

Browse files
committed
Fixed syntax errors
1 parent 3d92601 commit b803ab6

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

ciphers/caesar_cipher.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
2+
23
from string import ascii_letters
3-
import os
4+
45
import pyfiglet
56

7+
68
def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
79
"""
810
encrypt
@@ -71,8 +73,9 @@ def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
7173
# Use the provided alphabet if given, otherwise default to ascii_letters (a-z + A-Z)
7274
alpha = alphabet or ascii_letters
7375

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

7881
# Create a translation table: original alphabet -> shifted alphabet
@@ -93,7 +96,7 @@ def encrypt_file(input_path: str, output_path: str, key: int, alphabet: str | No
9396
alpha = alphabet or ascii_letters
9497

9598
# Open input file for reading and output file for writing
96-
with open(input_path, 'r') as fin, open(output_path, 'w') as fout:
99+
with open(input_path) as fin, open(output_path, 'w') as fout:
97100

98101
# Read the input file line by line to avoid loading the entire file into memory
99102
for line in fin:
@@ -187,7 +190,7 @@ def decrypt_file(input_path: str, output_path: str, key: int, alphabet: str | No
187190
alpha = alphabet or ascii_letters
188191

189192
# Open input file for reading and output file for writing
190-
with open(input_path, 'r') as fin, open(output_path, 'w') as fout:
193+
with open(input_path) as fin, open(output_path, 'w') as fout:
191194

192195
# Read the input file line by line to avoid loading the entire file into memory
193196
for line in fin:
@@ -265,10 +268,9 @@ def brute_force(input_string: str, alphabet: str | None = None) -> dict[int, str
265268

266269

267270
if __name__ == "__main__":
271+
banner = pyfiglet.figlet_format("Caesar Cipher", font="big")
272+
print(banner)
268273
while True:
269-
os.system('cls' if os.name == 'nt' else 'clear')
270-
banner = pyfiglet.figlet_format("Caesar Ciphar", font="big")
271-
print(banner)
272274
print(f"\n{'-' * 10}\n Menu\n{'-' * 10}")
273275
print("Please select from the following options: ")
274276
print(*["1.Encrypt", "2.Encrypt a File", "3.Decrypt", "4.Decrypt a File", "5.BruteForce", "6.Quit", ], sep="\n")

0 commit comments

Comments
 (0)