Skip to content

Commit ea726cd

Browse files
committed
allow parallelized encyption
In fact only the block solving cannot be parallelized, but the oracle function can.
1 parent 9c05a26 commit ea726cd

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,17 @@ plaintext = decrypt(
6464

6565
### Encryption
6666

67-
Below is an example demonstrating how to encrypt arbitrary bytes. For a detailed understanding of the process, please refer to [this Pull Request](https://github.com/djosix/padding_oracle.py/pull/4). Keep in mind that, unlike the decryption process, this functionality cannot be parallelized.
67+
Below is an example demonstrating how to encrypt arbitrary bytes. For a detailed understanding of the process, please refer to [this Pull Request](https://github.com/djosix/padding_oracle.py/pull/4).
6868

6969
```python
7070
from padding_oracle import encrypt
7171

72-
ciphertext = encrypt(b'YourTextHere', block_size=16, oracle=oracle)
72+
ciphertext = encrypt(
73+
b'YourTextHere',
74+
block_size=16,
75+
oracle=oracle,
76+
num_threads=16,
77+
)
7378
```
7479

7580
### Customized Logging

src/padding_oracle/padding_oracle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def encrypt(
6565
plaintext: bytes | str,
6666
block_size: int,
6767
oracle: OracleFunc,
68+
num_threads: int = 1,
6869
logger: Logger = default_logger,
6970
) -> bytes:
7071
plaintext = to_bytes(plaintext)
@@ -81,7 +82,7 @@ def encrypt(
8182
iv + cipher_blocks[i],
8283
block_size,
8384
oracle,
84-
1,
85+
num_threads,
8586
block_error_logger(logger),
8687
encrypt_progress_logger(logger, i+1, len(plain_blocks)),
8788
)

tests/test_padding_oracle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_padding_oracle_encrypt():
2727
plaintext,
2828
cryptor.block_size,
2929
cryptor.oracle,
30+
num_threads=4,
3031
)
3132

3233
assert cryptor.decrypt(encrypted) == plaintext

0 commit comments

Comments
 (0)