Cryptography 1
Cryptography 1
Challenge 1)
1. Run the challenge using
/challenge/run
2. Open a python file and run the following file with your information in the quotes
import base64
print(base64.b64decode(""))
python <filename>.py
Challenge 2)
1. Run the challenge using
/challenge/run
import base64
key = base64.b64decode("")
ct = base64.b64decode("")
for i in range(len(key)):
print(chr(ct[i] ^ key[i]), end="")
Challenge 3)
1. Run the challenge using
/challenge/run
3. Press ctrl + z
4. Use the following command and in the quotes place the value you got in the
previous step
Challenge 4)
1. Run the challenge using
2. Use the following python script to solve this challenge in the quotes place the 2
values that the challenge gives you
python <filename>.py
Challenge 5)
1. DO NOT RUN THE CHALLENGE
import pwn
import base64
chall= pwn.process("/challenge/run")
chall.readuntil(b"secret ciphertext (b64): ")
secret_ciphertext= chall.readline().decode()
ciphertext_decoded=base64.b64decode(secret_ciphertext)
for i in range(32,128):
chall.sendline(base64.b64encode(b"A"*numA+ bytes(currFlag, 'ascii')+ bytes([i])))
chall.readuntil("ciphertext (b64): ")
line=chall.readline().decode()
encryption=base64.b64decode(line)
if(new_encryption[:64] == encryption[:64]
return chr(i)
print(flag)
python <filename>.py
Challenge 6)
1. Run the challenge using
/challenge/run
3. Copy the secret cipher text it outputs into the following python script and run it
import base64
print(base64.b64decode(""))
python <filename>.py
/challenge/run
2. Use the following python script and enter the values from the challenge into the
corresponding variables
e_hex = '0x10001'
d_hex = '' #put your value for d here
n_hex = '' #put your value for n here
e = int(e_hex, 16)
d = int(d_hex, 16)
n = int(n_hex, 16)
ciphertext_bytes = base64.b64decode(ciphertext)
ciphertext_int = int.from_bytes(ciphertext_bytes, byteorder="little")
plaintext_bytes = decrypt_rsa(ciphertext_int, d, n)
print(plaintext_bytes.decode('utf-8'))
Challenge 8)
1. Run the challenge using
/challenge/run
import base64
from Crypto.PublicKey import RSA
from Crypto.Util.number import inverse
e = int('0x10001', 16)
p = int('', 16) #put your value for p here
q = int('', 16) #put your value for q here
phi = (p - 1) * (q - 1)
d = inverse(e, phi)
n = p * q
print(plaintext_bytes.decode('utf-8'))
python <filename>.py
/challenge/run
2. Run the python script with the prefix your challenge provides you
import hashlib
import os
import base64
from Crypto.Hash import SHA256 as SHA256Hash
def find_collision(secret_hash_prefix):
while True:
data = os.urandom(32)
hash = hashlib.sha256(data).digest()
if hash[:2] == secret_hash_prefix:
return data
collision = find_collision(secret_sha256_prefix)
collision_b64 = base64.b64encode(collision).decode('utf-8')
3. Run and enter the result of the python script into the prompt in the challenge in a
second terminal using the split icon (looks like 2 boxes) in the terminal area
/challenge/run
2. Use the following python script and enter your values into the corresponding
variables
import base64
import hashlib
import itertools
import string
3. Run the python script and enter it’s output into the prompt from the challenge
python <filename>.py
Challenge 11)
1. Run the challenge using
/challenge/run
2. Use the following script and enter your values into the corresponding variables
3. Run the python script using the following command and enter the response into the
challenge’s prompt
python <filename>.py
Challenge 12)
1. Run the challenge using
/challenge/run
2. We will run multiple ipython commands and some bash commands in this challenge
4. When that script errors we will run the following command in a split terminal
cp <filepath_from_error> <name_of_python_script_you_just_ran>.py
5. At the end of the file you just copied to append the following lines (you might have
to close your file and reopen it for the changes to take effect)
ipython <filename_where_you_copied_file>.py
Again each of these should be run individually and you should put the output into the
corresponding prompt in the challenge
import base64
hex(key.e)
hex(key.n)
hex(pow(,key.d,key.n))
binascii.unhexlify("0"+hex(pow(int(binascii.hexlify(base64.b64decode("")[::-1]), 16),key.
d,key.n))[2:])[::-1]
/challenge/run
2. In a split terminal run ipython with the file you created in challenge 12
key
cert = {"name": "fish", "key": {"e": key.e, "n":key.n}, "signer": "root"}
import json
import base64
import hashlib
base64.b64encode(json.dumps(cert).encode("ascii"))
d = #enter your root d value from the challenge here
3. Create another split terminal so now you will have 3 from left to right they should be
the challenge, ipython <filename>.py, and now this new one. In this new one you
will run ipython by itself then the following commands
ipython
import base64
base64.b64decode("") #insert your your root certificate (b64)
import os
import sys
import base64
import json
import pwn
process = pwn.process("/challenge/run")
process.readuntil("p: ")
p = int(process.readline(), 16)
process.readuntil("g: ")
g = int(process.readline(), 16)
root_certificate_binary = base64.b64decode(process.readline())
root_certificate = json.loads(root_certificate_binary)
root_certificate_signature = base64.b64decode(process.readline())
process.readuntil("A: ")
A = int(process.readline(), 16)
b = int.from_bytes(os.urandom(256), 'little')
B = pow(g, b, p)
process.readuntil("B: ")
process.writeline(hex(B).encode())
s = pow(A, b, p)
key = RSA.generate(1024)
user_certificate = {
"name": name,
"key": {
'e': key.e,
'n': key.n
},
"signer": "root"
user_certificate_binary = json.dumps(user_certificate).encode()
user_certificate_encrypted_b64 = base64.b64encode(user_certificate_encrypted)
user_certificate_hash_binary = SHA256Hash(user_certificate_binary).digest()
user_certificate_signature_binary = pow(
int.from_bytes(user_certificate_hash_binary, "little"),
root_private_key,
root_certificate['key']['n']
).to_bytes(256, "little")
user_certificate_signature_encrypted_b64 = base64.b64encode(user_certificate_signature_enc
rypted)
process.writeline(user_certificate_encrypted_b64)
process.writeline(user_certificate_signature_encrypted_b64)
user_signature_binary = (
name.encode().ljust(256, b"\0") +
A.to_bytes(256, "little") +
B.to_bytes(256, "little")
user_signature_hash_binary = SHA256Hash(user_signature_binary).digest()
user_signature_binary = pow(
int.from_bytes(user_signature_hash_binary, "little"),
key.d,
user_certificate['key']['n']
).to_bytes(256, "little")
user_signature_encrypted_b64 = base64.b64encode(user_signature_encrypted)
process.writeline(user_signature_encrypted_b64)
flag_cipher_text = base64.b64decode(process.readline())
flag = cipher_decrypt.decrypt(flag_cipher_text)
print(flag)