Skip to content

Commit 654e008

Browse files
Add decrypt method using apply_keystream method
1 parent 95eb1e9 commit 654e008

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crypto/ChaCha20.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,17 @@ def encrypt(self, plaintext: bytes) -> bytes:
118118
"""
119119
return self._apply_keystream(plaintext)
120120

121-
121+
def decrypt(self, ciphertext: bytes) -> bytes:
122+
"""
123+
Decrypts the given ciphertext using the ChaCha20 stream cipher.
124+
125+
Since ChaCha20 uses XOR for encryption, decryption is performed
126+
using the same keystream and XOR operation.
127+
128+
Args:
129+
ciphertext (bytes): The ciphertext data to be decrypted.
130+
131+
Returns:
132+
bytes: The resulting plaintext.
133+
"""
134+
return self.apply_keystream(ciphertext)

0 commit comments

Comments
 (0)