Skip to content

Commit 664a701

Browse files
committed
Upload finals challenges
1 parent 922e024 commit 664a701

File tree

119 files changed

+4260
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4260
-5
lines changed

crypto/4RSA/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 4RSA
2+
3+
**`Author:`** [4rk0](https://www.linkedin.com/in/abderahmane-oubahi-a72240243/)
4+
5+
## Description
6+
7+
> Welcome to 4RSA ( 4rk0, Rivest, Shamir and Adleman ) cryptosystem.
8+
> Have fun!
9+
10+
11+
12+
13+
- **Files**
14+
- [enc.txt](challenge/enc.txt)
15+
16+
17+
18+
19+
20+
## Solution
21+
Solution of the challenge can be found [here](solution/).

crypto/4RSA/challenge/enc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C = 611142254405063827592801146302447289406583406739037319967831929495820356540197143799949439570575545193567545373382063508745891664959358452805982104434526
2+
e = 0x10001
3+
Phi = 5766519321732303614602774063039817994229059369350942586704472004284400792639050641102051094143465282172553506082870684687445379400436177178525327208209136

crypto/4RSA/solution/solve.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from Crypto.Util.number import *
2+
from itertools import combinations
3+
import math
4+
5+
phi = 5766519321732303614602774063039817994229059369350942586704472004284400792639050641102051094143465282172553506082870684687445379400436177178525327208209136
6+
7+
# since the bit length of phi is 511 the bit length of the primes should be 255 or 256
8+
print(phi.bit_length()) # 511
9+
10+
# https://www.dcode.fr/decomposition-nombres-premiers
11+
factors = [
12+
2,
13+
2,
14+
2,
15+
2,
16+
11,
17+
53,
18+
1231,
19+
3011,
20+
6311,
21+
42764336533,
22+
6092059936124221,
23+
302778436501851567289,
24+
15891009937926808303685601511,
25+
155281495565701884820879394479,
26+
135773862498011055774105095957930299,
27+
]
28+
29+
assert all(isPrime(p) for p in factors), "we need all the factors to be primes so we can get the public modulus"
30+
31+
p=1
32+
out = False
33+
l = len(factors)
34+
for i in range(1, l + 1):
35+
for combo in combinations(factors, i):
36+
product = math.prod(combo)
37+
if isPrime(product + 1) and (product + 1).bit_length() in [255, 256]:
38+
out = True
39+
p = product + 1
40+
print(p)
41+
break
42+
if out:
43+
break
44+
45+
assert p!=1, "attack failed"
46+
q = phi // (p - 1) + 1
47+
print(q)
48+
e = 0x10001
49+
c = 611142254405063827592801146302447289406583406739037319967831929495820356540197143799949439570575545193567545373382063508745891664959358452805982104434526
50+
d = inverse(e,phi)
51+
n = p * q
52+
m = pow(c, d, n)
53+
print(long_to_bytes(m).decode())

crypto/phi/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Phi
2+
3+
**`Author:`** [0mr_Hz](https://github.com/OmrHz)
4+
5+
## Description
6+
7+
> An unusual modulus has been used in encryption.
8+
9+
10+
11+
12+
- **Files**
13+
- [cipher](challenge/cipher)
14+
15+
16+
17+
18+
19+
## Solution
20+
Solution of the challenge can be found [here](solution/).

crypto/phi/challenge/cipher

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
N=45109760255834684754983589295969725310626328534802429650039558168167072337918473534586289686536635992885101263834302951907737904559260123769463991894980774542481
2+
e=65537
3+
Cipher: 37358207842489278501844590204436061248784995840567905372310756710267273487596583866873282674084579361285279392052165188243528456115376968934859883995305365787773

crypto/phi/solution/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Challenge name
2+
Phi_φ(n)
3+
## Write-up
4+
In this challenge, the modulus `N` has 16 factors, and one of them is a prime raised to the power of 3 (``p^3``), which is unusual for RSA since ``N`` is usually the product of two primes. This causes issues when calculating the Euler's totient (``φ(N)``), which is crucial for decryption. After some research [here](https://cp-algorithms.com/algebra/phi-function.html), we find the correct totient properties to resolve this.
5+
#### 1. If `P` is prime, then : φ(p<sup>k</sup>) = p<sup>k</sup> - p<sup>k-1</sup> = p<sup>k-1</sup>(p - 1)
6+
#### 2. If `a` and `b` are relatively prime, then : φ(a*b) =φ(a) * φ(b)
7+
check [solve.py](solve.py)
8+
## Flag
9+
`shellmates{3A$Y_t0T1Ent_when_$aMe_OR_m4nY_PR1me$_4RE_u$ed}`

crypto/phi/solution/solve.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from Crypto.Util.number import *
2+
3+
N=45109760255834684754983589295969725310626328534802429650039558168167072337918473534586289686536635992885101263834302951907737904559260123769463991894980774542481
4+
e=65537
5+
Cipher= 37358207842489278501844590204436061248784995840567905372310756710267273487596583866873282674084579361285279392052165188243528456115376968934859883995305365787773
6+
# use https://factordb.com/ or https://www.alpertron.com.ar/ECM.HTM to factorize N
7+
phi= (865092131**2)*( 865092131- 1)* (567438481 - 1)*( 606925769 - 1)*( 616037419 - 1)*( 632480843 - 1)*( 717907921 - 1)*( 830813623 - 1)*( 842597461 - 1)*( 878387431 - 1)*( 926136593 - 1)*( 957106811 - 1)*( 1046408651- 1)*( 1058492087- 1)*( 1058962693- 1)*( 1061140099- 1)*( 1066149767 - 1)
8+
d= inverse(e, phi)
9+
flag= pow(Cipher, d, N)
10+
print(long_to_bytes(flag))

crypto/small_e_BIG_E_2/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# small_e_BIG_E_2
2+
3+
**`Author:`** [0mr_Hz](https://github.com/OmrHz)
4+
5+
## Description
6+
7+
> The flag is divided into two parts.
8+
9+
10+
11+
12+
13+
14+
- **Files**
15+
- [cipher](challenge/cipher)
16+
17+
18+
19+
20+
21+
## Solution
22+
Solution of the challenge can be found [here](solution/).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
n = 29563270538086143002493713133242710911277389545174171979360937022260711548809566754991339099758796679985706321613966054969681887602589884648623825745668458837445834185193063630643954030023995152766828380984307286631613409521218198097771181078259717332328406870138980135857993307521984208658806489755339470589276028922666975676812812740253581012003167633689981369923875040409212617867191091682882027502513562593887237579479288835315968446747373849118802138237014138387111862922509374362634591599247863144915827599828073015706407992838346248443950397896330971520858172678181332976146233287226738376984007092092777160231
2+
e = 16
3+
c = 10858541195308715144166660034250554587839442817215103488562366650892066617385911705060729091239110702901641721250143902855824912961593409849086522004705402359663460818112822849183317024175658557832539557995189037564264861591374415480242602387565161587454983971616566019043649080241934265895840842604899768513282259102889652528500517412740774861977513480723509810797420121739582246506728235019389082284739384568112355004105348680787356507177573645215782049119291542980955639754262123765379779499258567428967570514953947042071405312130633900019143997749997940498076765446303629609408046007432273694203177327435310454854
4+
N = 0xb9eefe9302fa1a4e6aa43980fac2b7d1b66a7586b9263b3091510a44a301d45f43315744eb7d1ec81a8bf1bae5aaa80099d728d67ca886010087ae39fdb64efa2bd547d99cf60af3978a1bb968ba261830700b6b92c5c738b381f36c2a2a809c02d12dae4fc830056194b673265266fc1492b1820df61344c310cda3fc79805b20c4afc937fe8f25598f8e81f6f1484d105c029eafe7433d0f72729ce4b3abd0226ced14cb008df97a06ca6becd995373783d517b1909e473d0b5e3de0b3f5f9ad2a0b6b7f0ee3fb7a8d584d3badf7518fff17b2db230d836c541e106b55a0822b6ff771123b3aa65b2066d9d4785c7781a9700b4c46679a525896c9e318f2e1
5+
E = 0x3f37fc9f480f6fdee4f1ffb3fffdb1653d9ebd38f972873b0efa6a6bfb4702fc6380a53717d4231846382b7b869a9b42ec1306ff5946160c4af122d5c8b7b2fb241af29bb65b30627493abc6363d8506be21c6e4a4d925f26cab72379b0bc565edf9a40ebe331f3745bc40901f1e3ddbd685954c7c4d9d8d7079d86608a839afa1cf4a1b4155da38f3405788a43d5b5c4e25aaf6c5a423707b0e2f9e5924b8c7c1ab384f94140e15d37ff3b59f73c821358f8d5e208d5a1d7addd95f97f1050985401113855124a4fea95a9c9521a5bab6576c31505568dda8b23d0886dfefa796b361453ee2628193d9992b697705e0f8792513e706de3fff8a36d6b0b45a43
6+
C = 0x5d70e965bbfbb6b30511210da584bacc5c0d89fe8a702257ed4865d8fc0bed85c91e0d1a72319f0511621e79f562e407589ab0742b10fd2f1019250ee33263cccb56fb2c8c37390d3c7b2ffe94d51e54d902ccd87960a99d3edb85eac802923e2bbf7ecce6ce43c9fccc520ab6814887325f813decdcb3c3a3f8c1d6af37fb3f8235a12050952767c488d48173f1d50a4dd3b9cd194c262cd215cbbc93c142fa394ea9ade0a0369a76240c641414428e75c452bc69efd657fc25d55efe0d206efd8cedd4740934f977647558301bec9462754c34814aa326c3b3e2f96c9343e5a85a374906f09e40558753ef210d414dcb4a664a6fddfd18102824322a41740c
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Challenge name
2+
3+
## Write-up
4+
5+
### first part
6+
We observe that n is a prime number and e is a power of 2.
7+
This allows us to take consecutive square roots (where possible) to find the 𝑒-th root.
8+
### second part
9+
Solved with Boneh and Durfee attack
10+
11+
check [solve.py](sol.py)
12+
## Flag
13+
14+
`shellmates{B1G_$0Lut10N$_$tarT_W1Th_$maLL_Res1Du3S}`

0 commit comments

Comments
 (0)