> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/cryptography/b00tl3grsa4.md).

# b00tl3grsa4

### The Challenge

Connect via netcat and receive:

```
c: 7821284413607156999099037941922718048546728118501714272754771531395454643151598402388981985486801198547064160448354343192049702172597137904962684049730561514562954160260555429640805667950809463084835189307739372171319177103480437837078192632150029075584424462537181384488291190637736218814332379653805074526802285414240329671605717588215896850
n: 9879962505429438587327716228010413610187726687076936201862843964715927081688957105676422143610974577253586418350462983077401072435906147211091220678606751124707241014836299352086515681960133377148052245298519266399792554702601503772160669040949324189657930936491310231878947582680294977822434251894991564050215801208332193134930374674608505677
e: 65537
```

***

### Why Standard RSA Decryption Fails

Normal RSA assumes `n = p × q` (two primes). Decryption requires:

```
φ(n) = (p-1)(q-1)
d = e⁻¹ mod φ(n)
m = c^d mod n
```

Here `n` is 343 digits long and can't be factored by trial division. But unlike standard RSA, this `n` is actually a product of **many small primes** — 34 of them! This makes it vulnerable because tools like factordb and alpertron can break it quickly.

***

### The Vulnerability — Too Many Factors

Standard RSA uses exactly 2 large primes. This `n` uses **34 small primes**, all around 10 digits each:

```
n = 8603565937 × 8635146629 × 8660513317 × ... × 16873275253
```

Small primes are easy to find using **ECM (Elliptic Curve Method)** factorization. The security of RSA comes from using two *huge* primes — small ones offer no protection.

***

### Solution

#### Step 1 — Connect and grab the values

```bash
nc fickle-tempest.picoctf.net 57484
```

Copy `c`, `n`, and `e`.

#### Step 2 — Factor n using Alpertron

Go to **<https://www.alpertron.com.ar/ECM.HTM>**

Paste `n` in the Value box and click **Factor**.

In about 3 seconds it returns all 34 prime factors AND — crucially — **Euler's totient φ(n)** directly:

```
φ(n) = 9879962477328754116973777764013580703505702722284524485956731509359599386015813859615735068213797065665803992307497112624191113661855910950399801471484915576710565840360877525764509091261718011153685744369465609699611735670197797367791318782970419983861521168743529376153488393126743775449005101718624908833935581093200414111604251033600000000
```

No need to multiply out `(p-1)(q-1)` for all 34 factors — alpertron does it for you.

#### Step 3 — Decrypt

```python
c = 7821284413607156999099037941922718048546728118501714272754771531395454643151598402388981985486801198547064160448354343192049702172597137904962684049730561514562954160260555429640805667950809463084835189307739372171319177103480437837078192632150029075584424462537181384488291190637736218814332379653805074526802285414240329671605717588215896850
n = 9879962505429438587327716228010413610187726687076936201862843964715927081688957105676422143610974577253586418350462983077401072435906147211091220678606751124707241014836299352086515681960133377148052245298519266399792554702601503772160669040949324189657930936491310231878947582680294977822434251894991564050215801208332193134930374674608505677
e = 65537

phi = 9879962477328754116973777764013580703505702722284524485956731509359599386015813859615735068213797065665803992307497112624191113661855910950399801471484915576710565840360877525764509091261718011153685744369465609699611735670197797367791318782970419983861521168743529376153488393126743775449005101718624908833935581093200414111604251033600000000

d = pow(e, -1, phi)
m = pow(c, d, n)
h = hex(m)[2:]
if len(h) % 2: h = '0' + h
print(bytes.fromhex(h).decode())
```

***

### Output

```
picoCTF{too_many_fact0rs_3023548}
```

***

### Key Takeaways

RSA security depends on **two large primes**. Using many small primes instead breaks it in two ways:

1. **Small primes are easy to find** — ECM factorization cracks them in seconds
2. **More factors = smaller individual primes** — the more factors, the weaker each one is

The flag says it all — `too_many_fact0rs`. Stick to two large primes or you're done.

***

**Flag:** `picoCTF{too_many_fact0rs_3023548}`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/cryptography/b00tl3grsa4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
