Skip to content

Commit 95eb1e9

Browse files
Add encrypt method using apply_keystream method
1 parent 8ef3861 commit 95eb1e9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crypto/ChaCha20.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,19 @@ def _apply_keystream(self, data: bytes) -> bytes:
103103
xor_block.append(input_byte ^ keystream_byte)
104104
result += bytes(xor_block)
105105
return result
106+
def encrypt(self, plaintext: bytes) -> bytes:
107+
"""
108+
Encrypts the given plaintext using the ChaCha20 stream cipher.
109+
110+
This method uses the ChaCha20 keystream generated from the
111+
key, nonce, and counter to XOR with the plaintext, producing ciphertext.
112+
113+
Args:
114+
plaintext (bytes): The plaintext data to be encrypted.
115+
116+
Returns:
117+
bytes: The resulting ciphertext.
118+
"""
119+
return self._apply_keystream(plaintext)
120+
121+

0 commit comments

Comments
 (0)