> For the complete documentation index, see [llms.txt](https://docs.cooku222.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cooku222.kr/security/crypto/cryptohack/cryptohack-elliptic-curves-point-addition.md).

# \[CryptoHack] Elliptic Curves, Point Addition

<figure><img src="https://blog.kakaocdn.net/dna/bkc8Op/btsOGl73ztT/AAAAAAAAAAAAAAAAAAAAAGC0XBIRj4qZg_dhLPL0KrwFxCNR3jZh1nq3qS0yl1uL/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=sWQuTHCEaXfI9jUBdGRXJM9A4%2Fg%3D" alt="" height="640" width="1487"><figcaption></figcaption></figure>

<figure><img src="https://blog.kakaocdn.net/dna/GomzO/btsOEjRWxiI/AAAAAAAAAAAAAAAAAAAAAM7baziFjKUrbSAtU4i-JgRIM0KrV71zoitsgk0FmBFd/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=4uxKuUe%2BWdsoalMmIz7Wxp%2BuzWI%3D" alt="" height="772" width="1512"><figcaption></figcaption></figure>

```
from sympy import mod_inverse

# Define parameters
p = 9739
a = 497
b = 1768

# Elliptic curve: y^2 = x^3 + a*x + b mod p
def point_add(P, Q):
    if P == Q:
        return point_double(P)

    if P is None:
        return Q
    if Q is None:
        return P

    x1, y1 = P
    x2, y2 = Q

    if x1 == x2 and (y1 + y2) % p == 0:
        return None

    m = ((y2 - y1) * mod_inverse(x2 - x1, p)) % p
    x3 = (m**2 - x1 - x2) % p
    y3 = (m * (x1 - x3) - y1) % p

    return (x3, y3)

def point_double(P):
    if P is None:
        return None

    x, y = P
    m = ((3 * x**2 + a) * mod_inverse(2 * y, p)) % p
    x3 = (m**2 - 2 * x) % p
    y3 = (m * (x - x3) - y) % p

    return (x3, y3)

# Given points
P = (493, 5564)
Q = (1539, 4742)
R = (4403, 5202)

# Compute S = P + P + Q + R
P2 = point_double(P)
PQ = point_add(P2, Q)
S = point_add(PQ, R)
```

이전문제까지는 익스 안 짜도 됐는데.. 여기서부턴 계산 복잡해져서 익스를 무조건 짜야한다<br>

```
crypto{4215,2162}
```


---

# 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:

```
GET https://docs.cooku222.kr/security/crypto/cryptohack/cryptohack-elliptic-curves-point-addition.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
