Skip to content

Commit

Permalink
level3
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Sep 26, 2024
1 parent fb59d0e commit 2916b15
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion cryptography/level-3/.config

This file was deleted.

8 changes: 8 additions & 0 deletions cryptography/level-3/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The previous challenge gave you the one time pad to decrypt the ciphertext.
If you did not know the one time pad, and it was only ever used for one message, the previous challenge would be unsolvable!
In this level, we'll explore what happens if the latter condition is violated.
You don't get the key this time, but we'll let you encrypt as many messages as you want.
Can you decrypt the flag?

----
**Hint:** understand deeply about how XOR works, and consider that it is a distributative, commutative, and associative operation...
1 change: 0 additions & 1 deletion cryptography/level-3/run

This file was deleted.

16 changes: 16 additions & 0 deletions cryptography/level-3/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/opt/pwn.college/python

import base64
from Crypto.Random import get_random_bytes
from Crypto.Util.strxor import strxor

flag = open("/flag", "rb").read()

key = get_random_bytes(256)
ciphertext = strxor(flag, key[:len(flag)])
print(f"secret ciphertext: {base64.b64encode(ciphertext).decode()}")

while True:
plaintext = base64.b64decode(input("plaintext (b64): "))
ciphertext = strxor(plaintext, key[:len(plaintext)])
print(f"ciphertext: {base64.b64encode(ciphertext).decode()}")
3 changes: 1 addition & 2 deletions cryptography/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ challenges:
- id: level-2
name: One Time Pad
- id: level-3
name: level3
description: Decrypt a secret encrypted with a one-time pad, where the key is reused for arbitrary data
name: Many Time Pad
- id: level-4
name: level4
description: Decrypt a secret encrypted with AES using the ECB mode of operation
Expand Down

0 comments on commit 2916b15

Please sign in to comment.