@@ -537,22 +537,21 @@ 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- 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 )} " )
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 )} " )
0 commit comments