Skip to content

Commit 1c95f07

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 85bfc12 commit 1c95f07

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

‎ciphers/des_ecb.py‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,22 @@ def decrypt(key: str, cipher_text: str) -> str:
537537
if mode not in ["e", "d", "k", "q"]:
538538
print("Invalid option. Please try again.")
539539
continue
540-
if mode == "q":
541-
break
542-
elif mode == "k":
543-
print(f"Generated key: {Des.generate_key()}")
544-
elif mode == "e":
545-
key = input("Enter the key: ").strip()
546-
if len(key) != 16 and not all(char in "0123456789abcdef" for char in key):
547-
print("Invalid key. Please try again.")
548-
continue
549-
input_string = input("Enter the string to encrypt: ").strip()
550-
print(f"Encrypted string: {Des.encrypt(key, input_string)}")
551-
elif mode == "d":
552-
key = input("Enter the key: ").strip()
553-
if len(key) != 16 and not all(char in "0123456789abcdef" for char in key):
554-
print("Invalid key. Please try again.")
555-
continue
556-
cipher_text = input("Enter the cipher text to decrypt: ").strip()
557-
print(f"Decrypted string: {Des.decrypt(key, cipher_text)}")
540+
match mode:
541+
case "q":
542+
break
543+
case "k":
544+
print(f"Generated key: {Des.generate_key()}")
545+
case "e":
546+
key = input("Enter the key: ").strip()
547+
if len(key) != 16 and not all(char in "0123456789abcdef" for char in key):
548+
print("Invalid key. Please try again.")
549+
continue
550+
input_string = input("Enter the string to encrypt: ").strip()
551+
print(f"Encrypted string: {Des.encrypt(key, input_string)}")
552+
case "d":
553+
key = input("Enter the key: ").strip()
554+
if len(key) != 16 and not all(char in "0123456789abcdef" for char in key):
555+
print("Invalid key. Please try again.")
556+
continue
557+
cipher_text = input("Enter the cipher text to decrypt: ").strip()
558+
print(f"Decrypted string: {Des.decrypt(key, cipher_text)}")

0 commit comments

Comments
 (0)