Cryptography

Challenge
Link

Perfect Encryption (300 pts)

Sign Hell (300 pts)

Power Times (600 pts)

Perfect Encryption (300 pts)

Description

Given challenge below

from Crypto.Util.number import bytes_to_long, getStrongPrime
from random import getrandbits

FLAG = bytes_to_long(b"ASCWG{XXXX}")

p = getStrongPrime(512)
a, b, c = getrandbits(256), getrandbits(256), getrandbits(256)

x = getrandbits(512)
y = FLAG*x % p

f1 = (a*x*y + b*x - c*y + a*b) % p
f2 = (a*x*y - a*b*x + c*y - a*b*c) % p
f3 = (a*x*y + a*b*x - b*y + a*c) % p

print(f"{a=}\n{b=}\n{c=}\n{p=}")
print(f"{f1=}\n{f2=}\n{f3=}")

Solution

So we have equation below

f1=axy+bxβˆ’cy+abf2=axyβˆ’abx+cyβˆ’abcf3=axy+abxβˆ’by+acf1 = axy + bx - cy + ab\\ f2 = axy - abx + cy - abc\\ f3 = axy + abx - by + ac\\

So basically we need to recover x and y and we know a, b, and c. The idea i used to solve the challenge is by eliminating the variable. Here is the proof

f1βˆ’f2=kxβˆ’ly+df2βˆ’f3=mxβˆ’ny+ef1 - f2 = kx - ly + d\\ f2 - f3 = mx - ny + e\\

Variables k, m, l, n, d, and e are known so the next step is by doing lcm on one of the coefficent on x or y. After that just eliminate the variable and back to modulus part. For example i eliminate variable x so now we need to work only with variable y and some known constant which are k, d, and e.

kβˆ—yβˆ’d=eβ€Šmodβ€Špkβˆ—y=e+dβ€Šmodβ€Špy=(e+d)βˆ—kβˆ’1β€Šmodβ€Špk*y - d = e \bmod p\\ k*y = e + d \bmod p\\ y = (e + d)*k^{-1} \bmod p

After getting y next we just need to substitute y and one of initial equation to get x. To get flag we just need to inverse the x then multiply with y. Here is script i used to solve the challenge

Flag : ASCWG{4tt@ck_7h3_Id3@l_w0RlD_0f_Gr0e6N2r$$}

Sign Hell (300 pts)

Description

Given challenge below

Solution

So we can recover the flag by utilizing 2 pair of signature. First we need to substract s2 on each pair

S21=(M1βˆ’aβˆ—S1)βˆ—kβˆ’1S22=(M2βˆ’aβˆ—S1)βˆ—kβˆ’1S21βˆ’S22=(M1βˆ’M2)βˆ—kβˆ’1S_{21} = (M_1 - a*S_1) * k^{-1}\\ S_{22} = (M_2 - a*S_1) * k^{-1}\\ S_{21} - S_{22} = (M_1 - M_2) * k^{-1}

Since we know values of M1 and M2 we can eliminate it to get k

(S21βˆ’S22)βˆ’1=(M1βˆ’M2)βˆ—kk=(M1βˆ’M2)βˆ—(S21βˆ’S22)βˆ’1(S_{21} - S_{22})^{-1} = (M_1 - M_2) * k\\ k = (M_1 - M_2) * (S_{21} - S_{22})^{-1}

After getting k now we can recover a by doing equation below

(M1βˆ’aβˆ—S1)βˆ—kβˆ’1=S2(M1βˆ’aβˆ—S1)=S2βˆ—kaβˆ—S1=(S2βˆ—k)βˆ’M1βˆ’a=((S2βˆ—k)βˆ’M1)βˆ—S1βˆ’1βˆ’1βˆ—βˆ’a=βˆ’(((S2βˆ—k)βˆ’M1)βˆ—S1βˆ’1)(M_1 - a*S_1) * k^{-1} = S_2\\ (M_1 - a*S_1) = S_2 * k\\ a*S_1 = (S_2 * k) - M_1\\ - a = ((S_2 * k) - M_1) * S_1^{-1}\\ -1 * -a = - (((S_2 * k) - M_1) * S_1^{-1})

But since there is chance that s1 and k are not coprime with p-1 we can still get the flag by repeating request until get the flag. Here is script i used to solve the challenge

Flag : ASCWG{R3uS31n9_G4m4l_NoNc3_S19n1n9_1s_50o_B4d_d9ae71c5}

Power Times (600 pts)

Description

Given challenge below

Solution

We can see that generated prime is smooth, so we can do discrete log by using Pohlig-Hellman algorithm. In this challenge i use sage to do the discrete log. After getting x we just need to power c1 with x then inverse it. After that just multiply c2 with inverse value then get flag. Here is the script i used to solve the challenge

Flag : ASCWG{H0w_5m0o0zy_E1G4m4l_c@n_B3_e28b6f81}

Last updated