Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions DDC-2024/quarter-finals/crypto/dist-Independence/chal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from Crypto.Util.number import *

FLAG = open('flag.txt', 'rb').read()

def encrypt(m, pubkey, privkey):
g, p = pubkey
x, _ = privkey
h = pow(g, x, p)
C = []
while m:
y = getRandomRange(2, p)
c1 = pow(g, y, p)
y = (y<<1) | (m & 1)
c2 = pow(h, y, p)
C += [(c1, c2)]
m >>= 1
return C

def keygen(nbits=512):
p = getStrongPrime(nbits)
g = getRandomRange(2, p)
x = getRandomRange(2, p)
pub = (g, p)
priv = (x, p)
return pub, priv

pub, priv = keygen()
m = bytes_to_long(FLAG)
print(m)
c = encrypt(m, pub, priv)

with open('out1.txt', 'w') as f:
f.write(f'{pub = }\n')
f.write(f'out = {str(c)}')
2 changes: 2 additions & 0 deletions DDC-2024/quarter-finals/crypto/dist-Independence/out.txt

Large diffs are not rendered by default.

Binary file not shown.
25 changes: 25 additions & 0 deletions DDC-2024/quarter-finals/crypto/dist-Independence/solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from Crypto.Util.number import long_to_bytes

with open('out.txt', 'r') as f:
data = f.read()


pub = (5464549774190809852923763408523051958716400587576327799474715226373287205246183801056700913652415087121976663782311766735601091617825037804761387911068511, 9581257592556018473305786754018994054986440370491067910997313283399579058244765977967617476919486211692103485121526918608638896652486174462300514168144287)
g, q = pub
# Extract the encrypted message
bin_flag=[]
out_start = data.find('out = ') + len('out = ')
c = eval(data[out_start:])
for cipher in c:
c1, c2 = cipher
if pow(c2,(q-1)//2, q) == 1:
bin_flag.append(0)
else:
bin_flag.append(1)

m = 0
for bit in reversed(bin_flag):
m = (m << 1) | bit

flag = long_to_bytes(m)
print(flag.decode('utf-8'))
Binary file added DDC-2024/semi-final/Crypto/dist-wonton/Readme.md
Binary file not shown.