Skip to content

Commit

Permalink
(crypto) added 2 Challs (beginner&easy)
Browse files Browse the repository at this point in the history
Added 
beginner: rotten-salad
easy: babyrsa
  • Loading branch information
souvlakias authored Jul 1, 2024
1 parent 57b6ce8 commit fbc55aa
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crypto/babyrsa/challenge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "babyrsa"
author: "souvlakia"
category: crypto

description: |
Fundamentals of RSA. Can you decrypt the message?
value: 500
type: dynamic
extra:
initial: 500
minimum: 50
decay: 25

flags:
- GTBQ{g0tt4_l0v3_GCD_&_mult1_Pr1me_rs4}

files:
- public/source.py
- public/output.txt

tags:
- crypto
- beginner

state: visible
version: "0.1"
5 changes: 5 additions & 0 deletions crypto/babyrsa/public/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n = 136129039934906799245883537600820362325696322589710411590186897335243686579104762065743976573291702750635108717889410733229115423708058508480236948810672363347991651420293334839308943729580241028725894733461551038888847568419901086597954491530529868885698368322552732418869647636401840431554294300907359920151
v = 145336505618051732550698474645594181799147590575859902257619187994378559013363268655950104864569764056670639713801017855616689453650198563048002837724039970159502938997236965318015229229549970355881337278281585150146306096405515477715640494716527445680613383929607132555875322057128548552200870650696580132521
w = 20612907913751940701434586234377070995512938354700166339929030278278014092311579879497093885185859184642701850534088712075806695131108284229597532840569152216986793187613838685954549359681582763903398538637932366747956519457275203090897430583637500207802799220582108236286968780561616121115054842835633027356029114516812021084434276111757860109305675350998033334000574804620501872783275490902197769254918685821157170228694510593644625793650591298037557438014165246072463794441871325588124086650937138575432899096783647585355882931580034904138718605575594187984051923588891709878571484103146803169259247375536859708763
c2 = 40999996801873802742121997119730707835375659336586118409913738383370584468803123294259818676510856232905858635994052230030123318196378107746038600276544711492946157137781760844236859181993407369879174109744518026199170698597057199969985775158762539533164627602726855551347620475705167278122876349988039969692
c3 = 3139944035622906500446122298196738357051827709726750721775633031452787107263389042610582535666920737943985088630120852223041567466431979061050093583701100302275054497243398106197255754467807652090694088800711075375412435711585892522866917133467033013010802142851893437909298773235587564677457793658655780592766302182404628855729480554049343600184461607330760299602586313139207785995916257882342396276534435829220426449740533729325143603438108068736676574488481496262952017763353301317940181413229422681271004713688641645933690837569274536827363723993636423240827193221091820001434531563287145275345624041360425385072
37 changes: 37 additions & 0 deletions crypto/babyrsa/public/source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from Crypto.Util.number import getPrime, bytes_to_long, long_to_bytes
from secret import FLAG

def encrypt(m:str, e, n): # encrypt message with public key
m=m.encode() # convert to bytes
m=bytes_to_long(m) # convert to integer
return pow(m, e, n)

def decrypt(c:int, n, prime_factors:list): # decrypt message if we know the prime factors of n
phi=1
for p in prime_factors:
phi*=(p-1)
d=pow(e, -1, phi)
m=pow(c, d, n)
return long_to_bytes(m).decode()


if __name__ == '__main__':
e=65537
p=getPrime(512)
q=getPrime(512)
n=p*q


r=getPrime(512)
v=q*r

k=getPrime(512)
w=p*q*r*k

print(f'{n = }')
print(f'{v = }')
print(f'{w = }')

# print(f'c1 = {encrypt(FLAG, e, n)}')
print(f'c2 = {encrypt(FLAG[:20], e, v)}')
print(f'c3 = {encrypt(FLAG[20:], e, w)}')
5 changes: 5 additions & 0 deletions crypto/babyrsa/setup/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n = 136129039934906799245883537600820362325696322589710411590186897335243686579104762065743976573291702750635108717889410733229115423708058508480236948810672363347991651420293334839308943729580241028725894733461551038888847568419901086597954491530529868885698368322552732418869647636401840431554294300907359920151
v = 145336505618051732550698474645594181799147590575859902257619187994378559013363268655950104864569764056670639713801017855616689453650198563048002837724039970159502938997236965318015229229549970355881337278281585150146306096405515477715640494716527445680613383929607132555875322057128548552200870650696580132521
w = 20612907913751940701434586234377070995512938354700166339929030278278014092311579879497093885185859184642701850534088712075806695131108284229597532840569152216986793187613838685954549359681582763903398538637932366747956519457275203090897430583637500207802799220582108236286968780561616121115054842835633027356029114516812021084434276111757860109305675350998033334000574804620501872783275490902197769254918685821157170228694510593644625793650591298037557438014165246072463794441871325588124086650937138575432899096783647585355882931580034904138718605575594187984051923588891709878571484103146803169259247375536859708763
c2 = 40999996801873802742121997119730707835375659336586118409913738383370584468803123294259818676510856232905858635994052230030123318196378107746038600276544711492946157137781760844236859181993407369879174109744518026199170698597057199969985775158762539533164627602726855551347620475705167278122876349988039969692
c3 = 3139944035622906500446122298196738357051827709726750721775633031452787107263389042610582535666920737943985088630120852223041567466431979061050093583701100302275054497243398106197255754467807652090694088800711075375412435711585892522866917133467033013010802142851893437909298773235587564677457793658655780592766302182404628855729480554049343600184461607330760299602586313139207785995916257882342396276534435829220426449740533729325143603438108068736676574488481496262952017763353301317940181413229422681271004713688641645933690837569274536827363723993636423240827193221091820001434531563287145275345624041360425385072
1 change: 1 addition & 0 deletions crypto/babyrsa/setup/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLAG='GTBQ{g0tt4_l0v3_GCD_&_mult1_Pr1me_rs4}'
37 changes: 37 additions & 0 deletions crypto/babyrsa/setup/source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from Crypto.Util.number import getPrime, bytes_to_long, long_to_bytes
from secret import FLAG

def encrypt(m:str, e, n): # encrypt message with public key
m=m.encode() # convert to bytes
m=bytes_to_long(m) # convert to integer
return pow(m, e, n)

def decrypt(c:int, n, prime_factors:list): # decrypt message if we know the prime factors of n
phi=1
for p in prime_factors:
phi*=(p-1)
d=pow(e, -1, phi)
m=pow(c, d, n)
return long_to_bytes(m).decode()


if __name__ == '__main__':
e=65537
p=getPrime(512)
q=getPrime(512)
n=p*q


r=getPrime(512)
v=q*r

k=getPrime(512)
w=p*q*r*k

print(f'{n = }')
print(f'{v = }')
print(f'{w = }')

# print(f'c1 = {encrypt(FLAG, e, n)}')
print(f'c2 = {encrypt(FLAG[:20], e, v)}')
print(f'c3 = {encrypt(FLAG[20:], e, w)}')
30 changes: 30 additions & 0 deletions crypto/babyrsa/sol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Solution:
- We can find all the factors one by one by getting the GCD of the moduli.


```python
from Crypto.Util.number import bytes_to_long, long_to_bytes, GCD
n = ...
v = ...
w = ...
c2 = ...
c3 = ...
e = 65537

def decrypt(c:int, n, prime_factors:list): # decrypt message if we know the prime factors of n
phi=1
for p in prime_factors:
phi*=(p-1)
d=pow(e, -1, phi)
m=pow(c, d, n)
return long_to_bytes(m).decode()


q= GCD(n, v)
p= n//q
r= v//q
k= w//(p*q*r)

print(decrypt(c2, v, [q,r]), end='')
print(decrypt(c3, w, [p,q,r,k]))
```
24 changes: 24 additions & 0 deletions crypto/babyrsa/sol/solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from Crypto.Util.number import bytes_to_long, long_to_bytes, GCD
n = 136129039934906799245883537600820362325696322589710411590186897335243686579104762065743976573291702750635108717889410733229115423708058508480236948810672363347991651420293334839308943729580241028725894733461551038888847568419901086597954491530529868885698368322552732418869647636401840431554294300907359920151
v = 145336505618051732550698474645594181799147590575859902257619187994378559013363268655950104864569764056670639713801017855616689453650198563048002837724039970159502938997236965318015229229549970355881337278281585150146306096405515477715640494716527445680613383929607132555875322057128548552200870650696580132521
w = 20612907913751940701434586234377070995512938354700166339929030278278014092311579879497093885185859184642701850534088712075806695131108284229597532840569152216986793187613838685954549359681582763903398538637932366747956519457275203090897430583637500207802799220582108236286968780561616121115054842835633027356029114516812021084434276111757860109305675350998033334000574804620501872783275490902197769254918685821157170228694510593644625793650591298037557438014165246072463794441871325588124086650937138575432899096783647585355882931580034904138718605575594187984051923588891709878571484103146803169259247375536859708763
c2 = 40999996801873802742121997119730707835375659336586118409913738383370584468803123294259818676510856232905858635994052230030123318196378107746038600276544711492946157137781760844236859181993407369879174109744518026199170698597057199969985775158762539533164627602726855551347620475705167278122876349988039969692
c3 = 3139944035622906500446122298196738357051827709726750721775633031452787107263389042610582535666920737943985088630120852223041567466431979061050093583701100302275054497243398106197255754467807652090694088800711075375412435711585892522866917133467033013010802142851893437909298773235587564677457793658655780592766302182404628855729480554049343600184461607330760299602586313139207785995916257882342396276534435829220426449740533729325143603438108068736676574488481496262952017763353301317940181413229422681271004713688641645933690837569274536827363723993636423240827193221091820001434531563287145275345624041360425385072
e = 65537

def decrypt(c:int, n, prime_factors:list): # decrypt message if we know the prime factors of n
phi=1
for p in prime_factors:
phi*=(p-1)
d=pow(e, -1, phi)
m=pow(c, d, n)
return long_to_bytes(m).decode()


q= GCD(n, v)
p= n//q
r= v//q
k= w//(p*q*r)

print(decrypt(c2, v, [q,r]), end='')
print(decrypt(c3, w, [p,q,r,k]))
26 changes: 26 additions & 0 deletions crypto/rotten-salad/challenge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Rotten Salad"
author: "souvlakia"
category: crypto

description: |
Caesar came up with a cipher to protect the salad recipe his cyber Chef made. Can you help Brutus decrypt it?
value: 500
type: dynamic
extra:
initial: 500
minimum: 50
decay: 25

flags:
- GTBQ{3t_Tu_bRut3?}

files:
- public/salad.txt

tags:
- crypto
- beginner

state: visible
version: "0.1"
5 changes: 5 additions & 0 deletions crypto/rotten-salad/public/salad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Vtx(t' ft!tw exv|%xM
e$"t|#x !x))*vx
ct'"x(t# v{xx(x
V'|(% v'$*)$#(
ZgUd0F)rg*rue*)FR2
1 change: 1 addition & 0 deletions crypto/rotten-salad/setup/salad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[salad](https://gchq.github.io/CyberChef/#recipe=ROT47(19)&input=Q2Flc2FyIFNhbGFkIFJlY2lwZToKUm9tYWluZSBsZXR0dWNlClBhcm1lc2FuIGNoZWVzZQpDcmlzcCBjcm91dG9ucwpHVEJRezN0X1R1X2JSdXQzP30&oenc=65001)
1 change: 1 addition & 0 deletions crypto/rotten-salad/sol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[salad](https://gchq.github.io/CyberChef/#recipe=ROT47_Brute_Force(100,0,true,'GTBQ%7B')&input=VnR4KHQnIGZ0IXR3IGV4dnwleE0KZSQidHwjeCAheCkpKnZ4CmN0JyJ4KHQjIHZ7eHgoeApWJ3woJSB2JyQqKSQjKApaZ1VkMEYpcmcqcnVlKilGUjI&oenc=65001)

0 comments on commit fbc55aa

Please sign in to comment.