Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdoupe committed Oct 30, 2023
1 parent 740a929 commit 5d2b9a7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cryptography/run
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ def show_b64(name, value):
def show_hex_block(name, value, byte_block_size=16):
value_to_show = ""

for i in range(len(value)):
value_to_show += f"{hex(value[i])[2:]}"
if i != 0 and i % byte_block_size == 0:
value_to_show += " "
for i in range(0, len(value), byte_block_size):
value_to_show += f"{value[i:i+byte_block_size].hex()}"
value_to_show += " "
show(f"{name} (hex)", value_to_show)


Expand Down Expand Up @@ -129,13 +128,15 @@ def level5():
key = get_random_bytes(16)
cipher = AES.new(key=key, mode=AES.MODE_ECB)

print(f"{pad(flag, cipher.block_size)}")
ciphertext = cipher.encrypt(pad(flag, cipher.block_size))
show_b64("secret ciphertext", ciphertext)
show_hex_block("secret ciphertext", ciphertext)

while True:
plaintext_prefix = input_b64("plaintext prefix")
ciphertext = cipher.encrypt(pad(plaintext_prefix + flag, cipher.block_size))
print(f"{pad(plaintext_prefix + flag, cipher.block_size)}")
show_b64("ciphertext", ciphertext)
show_hex_block("ciphertext", ciphertext)

Expand Down

0 comments on commit 5d2b9a7

Please sign in to comment.