Skip to content

Commit

Permalink
Finished up challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
s0phialiu committed Mar 15, 2024
1 parent cda1630 commit 54f3e1d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
5 changes: 2 additions & 3 deletions chals/crypto/easy_rsa/challenge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ description: |-
TODO: some description
**author**: Sophia
value: 250
value: 200
type: dynamic
tags:
- easy
extra:
initial: 250
initial: 200
decay: 50
minimum: 50
flags:
- sigpwny{rsA_FtW:P}
files:
- chal.py
- gen.py
hints:
- I noticed a [library](https://pycryptodome.readthedocs.io/en/latest/src/public_key/rsa.html) included in the source code...
27 changes: 26 additions & 1 deletion chals/crypto/easy_rsa/gen.py
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
#add later
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
import sympy

flags = ["sigpwn","y{rsA_","FtW:P}"]

# Randomly generating two primes
p = 70979368125456165107
q = 62874279226076849807
e = 65539
n = p*q #4462776610810429874302099425257433084349
totn = int(sympy.totient(n))
d = pow(e,-1,totn) #2524360373456480207131100680183211940587

# Generate public and private keys
pubkey = RSA.construct((n,e))
cipher = PKCS1_v1_5.new(pubkey)
priv = RSA.construct((n,e,d))
ciph = PKCS1_v1_5.new(priv)

# Prints encryption for each flag chunk
for flag in flags:
ciphertext = cipher.encrypt(flag.encode('utf-8'))
print(ciphertext)
plaintext = ciph.decrypt(ciphertext, None)
print(plaintext.decode("utf-8"))
1 change: 0 additions & 1 deletion chals/crypto/safe-cracking/sol.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ description: |-
`nc chal.cryptoctf.sigpwny.com 7001`
**author**: Sophia
value: 150
value: 200
type: dynamic
tags:
- easy
extra:
initial: 150
initial: 200
decay: 50
minimum: 50
flags:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def print_notes():
print("The shared key of each problem corresponds to one part of the safe combination.")
print("1. Anna and Beatrice perform a Diffie-Hellman key exchange where p = 17 and g = 3. Privately, Anna selects 5 and Beatrice chooses 11. What's their shared secret key?")
print("2. The two perform another key exchange. Now, p = 157 and g = 2. Anna's new private key is 67, while Beatrice's public key is 73. What is Anna's public key?")
print("3. Anna forgot her private key and wants to solve for it. However, we know the following:\n\tTheir shared secret key, s, is equal to xx.\n\tThe values of p and g are 67 and 2, respectively.\n\tThe result of Anna's public key is x.\n") #finish later
print("3. Anna forgot her private key and wants to solve for it. However, we know the following:\n\tTheir shared secret key, s, is equal to 605790.\n\tThe values of p and g are 3042161 and 5, respectively.\n\tThe result of Beatrice's private key is 73.\n")
print("Get ready to start guessing!")
time.sleep(1)

Expand All @@ -33,7 +33,8 @@ def main():
print_notes()
else:
print("Might want to view the notes...")

time.sleep(1)
print("Get ready to start guessing!")
if prompt():
print("You have unlocked the safe! Please don't take anything except for this flag:", FLAG)
else:
Expand Down
30 changes: 30 additions & 0 deletions chals/crypto/safe_cracking/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PART 1 and PART 2
# Multiple ways of getting here, can just use an online generator

# --- PART 3 ---
# Part 3: Finding A

p = 3042161
b = 73
shared_secret = 605790

def find_base(p, b, shared_secret):
for base in range(1, p):
if pow(base, b, p) == shared_secret:
return base
return None

# Part 3: Finding a
base = 5
A = find_base(p, b, shared_secret)

def find_exponent(p, base, A):
for x in range(1, p):
if pow(base, x, p) == A:
return x
return None

a = find_exponent(p, base, A)

print("Third number to unlock safe:", a)

0 comments on commit 54f3e1d

Please sign in to comment.