generated from sigpwny/ctf-chal-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|