Skip to content

Commit 0a89f86

Browse files
committed
formatting issues
forgot to check formatting was ok, have fixed some issues with it. flake8 is not happy with the formatting
1 parent d5d618d commit 0a89f86

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/padding_oracle/legacy.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'padding_oracle',
3434
]
3535

36+
3637
def padding_oracle(payload: Union[bytes, str],
3738
block_size: int,
3839
oracle: OracleFunc,
@@ -93,14 +94,14 @@ def padding_oracle(payload: Union[bytes, str],
9394
payload = to_bytes(payload)
9495
null_byte = to_bytes(null_byte)
9596

96-
9797
# Does the user want the encryption routine
9898
if (mode == 'encrypt'):
9999
return encrypt(payload, block_size, oracle, num_threads, null_byte, pad_payload, logger)
100100

101101
# If not continue with decryption as normal
102102
return decrypt(payload, block_size, oracle, num_threads, null_byte, return_raw, logger)
103103

104+
104105
def decrypt(payload, block_size, oracle, num_threads, null_byte, return_raw, logger):
105106
# Wrapper to handle exceptions from the oracle function
106107
def wrapped_oracle(ciphertext: bytes):
@@ -171,21 +172,22 @@ def bytes_xor(byte_string_1: bytes, byte_string_2: bytes):
171172

172173
plaintext_blocks = blocks(payload)
173174
ciphertext_blocks = [null_byte * block_size for _ in range(len(plaintext_blocks)+1)]
174-
175+
175176
solve_index = '1'
176177
block_total = str(len(plaintext_blocks))
177178

178179
for index in range(len(plaintext_blocks)-1, -1, -1):
179180
plaintext = solve(b'\x00' * block_size + ciphertext_blocks[index+1], block_size, wrapped_oracle,
180-
num_threads, result_callback, plaintext_callback)
181+
num_threads, result_callback, plaintext_callback)
181182
ciphertext_blocks[index] = bytes_xor(plaintext_blocks[index], plaintext)
182183
solve_index = str(int(solve_index)+1)
183-
184+
184185
ciphertext = b''.join(ciphertext_blocks)
185186
logger.info(f"forged ciphertext: {ciphertext}")
186187

187188
return ciphertext
188189

190+
189191
def get_logger():
190192
logger = logging.getLogger('padding_oracle')
191193
formatter = logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s')

src/padding_oracle/solve.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'add_padding'
4040
]
4141

42+
4243
class Pass(NamedTuple):
4344
block_index: int
4445
solved: List[int]
@@ -266,10 +267,11 @@ def remove_padding(data: Union[str, bytes, List[int]]) -> bytes:
266267
data = to_bytes(data)
267268
return data[:-data[-1]]
268269

270+
269271
def add_padding(data: Union[str, bytes, List[int]], block_size: int) -> bytes:
270272
'''
271273
Add PKCS#7 padding bytes.
272274
'''
273275
data = to_bytes(data)
274276
pad_len = block_size - len(data) % block_size
275-
return data + (bytes([pad_len]) * pad_len)
277+
return data + (bytes([pad_len]) * pad_len)

0 commit comments

Comments
 (0)