Skip to content

Commit 5f3761b

Browse files
committed
made changes for ruff test
Signed-off-by: grpathak22 <[email protected]>
2 parents 9fd5b47 + 23a8425 commit 5f3761b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: ciphers/aes_128.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'''
1616

1717

18+
1819
def aes_encrypt(plaintext: str, key: str) -> str:
1920
"""
2021
AES-128 Encryption using CBC mode and PKCS7 padding.
@@ -30,9 +31,10 @@ def aes_encrypt(plaintext: str, key: str) -> str:
3031
>>> aes_decrypt(enc, key) == msg
3132
True
3233
"""
33-
cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC)
34-
ciphertext = cipher.encrypt(pad(plaintext.encode('utf-8'), AES.block_size))
35-
return base64.b64encode(cipher.iv + ciphertext).decode('utf-8')
34+
cipher = AES.new(key.encode("utf-8"), AES.MODE_CBC)
35+
ciphertext = cipher.encrypt(pad(plaintext.encode("utf-8"), AES.block_size))
36+
return base64.b64encode(cipher.iv + ciphertext).decode("utf-8")
37+
3638

3739
def aes_decrypt(ciphertext: str, key: str) -> str:
3840
"""
@@ -50,8 +52,9 @@ def aes_decrypt(ciphertext: str, key: str) -> str:
5052
True
5153
"""
5254
raw = base64.b64decode(ciphertext)
53-
cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv=raw[:AES.block_size])
54-
return unpad(cipher.decrypt(raw[AES.block_size:]), AES.block_size).decode('utf-8')
55+
cipher = AES.new(key.encode("utf-8"), AES.MODE_CBC, iv=raw[: AES.block_size])
56+
return unpad(cipher.decrypt(raw[AES.block_size :]), AES.block_size).decode("utf-8")
57+
5558

5659
def main() -> None:
5760
key = input("Enter 16-character key (AES-128): ")
@@ -68,7 +71,9 @@ def main() -> None:
6871
decrypted_message = aes_decrypt(encrypted_message, key)
6972
print("Decrypted message:", decrypted_message)
7073

74+
7175
if __name__ == "__main__":
7276
import doctest
77+
7378
doctest.testmod()
7479
main()

0 commit comments

Comments
 (0)