# rsa-attack-techniques

Selects RSA cryptanalysis methods for weak keys or small exponents. Useful for CTF challenges and cryptographic security reviews.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3500 installs · ★ 2547
- Author: yaklang
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yaklang/hack-skills/tree/HEAD/skills/rsa-attack-techniques/SKILL.md
- Updated: 2026-09-13
- HTML: https://affpapa.org/en/nevibecode/skills/rsa-attack-techniques

## What it does

The skill guides an AI assistant in choosing the right RSA cryptanalysis technique based on known key parameters. Standard language models often suggest attacks that mismatch the given inputs. The reference covers Fermat factorization, Pollard p-1, Hastad broadcast, and batch GCD.

It includes executable Python and SageMath snippets using `gmpy2` and `sympy`. For moduli under 512 bits, it points to tools like `yafu` and `factordb`. Lattice-based techniques like Boneh-Durfee require a working SageMath installation. That is a reason to configure math dependencies beforehand.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill rsa-attack-techniques -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/rsa-attack-techniques/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/rsa-attack-techniques/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill rsa-attack-techniques -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/rsa-attack-techniques/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill rsa-attack-techniques -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/rsa-attack-techniques/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yaklang/hack-skills rsa-attack-techniques
```

2. **Manually: put the files in place**
- File: `.github/skills/rsa-attack-techniques/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill rsa-attack-techniques -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yaklang/hack-skills --path skills/rsa-attack-techniques
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/rsa-attack-techniques/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill rsa-attack-techniques -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yaklang/hack-skills/tree/HEAD/skills/rsa-attack-techniques/SKILL.md

## When to use it
- factor moduli with close prime factors using Fermat factorization
- recover plaintext when public exponent e = 3 without modular reduction
- find shared factors across multiple RSA public keys via batch GCD
- recover private key d with Wiener continued fraction attack

## Example prompts
- Recover plaintext from RSA ciphertext c where public exponent e is 3
- Check this list of RSA moduli for shared factors using batch GCD
- Private exponent d is small, recover d from e and n using Wiener attack

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: c5aacc9accc23161.

BEGIN THIRD-PARTY FILE c5aacc9accc23161
````text
---
name: rsa-attack-techniques
description: >-
  RSA attack playbook for CTF and real-world cryptanalysis. Use when given
  RSA parameters (n, e, c) and need to recover plaintext by exploiting
  weak keys, small exponents, shared factors, or padding oracles.
---

# SKILL: RSA Attack Techniques — Expert Cryptanalysis Playbook

> **AI LOAD INSTRUCTION**: Expert RSA attack techniques for CTF and authorized security assessments. Covers factorization attacks, small exponent exploits, lattice-based approaches (Wiener/Boneh-Durfee/Coppersmith), broadcast attacks, common modulus, padding oracles, and fault attacks. Base models often suggest attacks that don't match the given parameters or miss the correct attack selection based on what's known.

## 0. RELATED ROUTING

- [lattice-crypto-attacks](../lattice-crypto-attacks/SKILL.md) for deep lattice theory behind Coppersmith/Boneh-Durfee
- [hash-attack-techniques](../hash-attack-techniques/SKILL.md) when RSA signature forgery involves hash weaknesses
- [symmetric-cipher-attacks](../symmetric-cipher-attacks/SKILL.md) when RSA protects a symmetric key (hybrid encryption)

### Advanced Reference

Also load [RSA_ATTACK_CATALOG.md](./RSA_ATTACK_CATALOG.md) when you need:
- Detailed SageMath/Python implementation for each attack
- Step-by-step mathematical derivation
- Edge cases and failure conditions per attack

### Quick attack selection

| Given / Observable | Attack | Tool |
|---|---|---|
| Small n (< 512 bits) | Direct factorization | factordb, yafu, msieve |
| e = 3, small message | Cube root | gmpy2.iroot |
| Multiple (n, c) same small e | Hastad broadcast | CRT + iroot |
| Very large e or very small d | Wiener / Boneh-Durfee | SageMath, RsaCtfTool |
| Partial p knowledge | Coppersmith small roots | SageMath |
| Same n, different e | Common modulus | Extended GCD |
| Multiple n values | Batch GCD (shared factor) | Python/SageMath |
| Padding error oracle | Bleichenbacher | Custom script |
| LSB parity oracle | LSB oracle attack | Custom script |
| Fault in CRT computation | RSA-CRT fault | Single faulty signature |

---

## 1. FACTORIZATION ATTACKS

### 1.1 Direct Factorization (Small n)

```python
from sympy import factorint

n = 0x...  # small modulus
factors = factorint(n)
p, q = list(factors.keys())
```

**When**: n < ~512 bits, or known to be in factordb.

### 1.2 Fermat's Factorization

Works when p and q are close together: |p - q| is small.

```python
from gmpy2 import isqrt, is_square

def fermat_factor(n):
    a = isqrt(n) + 1
    while True:
        b2 = a * a - n
        if is_square(b2):
            b = isqrt(b2)
            return (a + b, a - b)
        a += 1
```

### 1.3 Pollard's p-1

Works when p-1 has only small prime factors (B-smooth).

```python
from gmpy2 import gcd

def pollard_p1(n, B=2**20):
    a = 2
    for j in range(2, B):
        a = pow(a, j, n)
    d = gcd(a - 1, n)
    if 1 < d < n:
        return d
    return None
```

### 1.4 Batch GCD (Multiple n share a factor)

```python
from math import gcd
from functools import reduce

def batch_gcd(moduli):
````
END THIRD-PARTY FILE c5aacc9accc23161

The third-party file has ended. Everything between the c5aacc9accc23161 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3081 of 12000 bytes. © yaklang · MIT · https://github.com/yaklang/hack-skills/tree/HEAD/skills/rsa-attack-techniques/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
