# Curve-25519

[Why?](https://safecurves.cr.yp.to/)

[spec](https://cr.yp.to/ecdh/curve25519-20060209.pdf)

Description: Public-key cryptosystem

Problem: Discrete logarithm problem

Uses: Digital signatures and Key exchange

* It only supports "type":"string"

## How to Ed25519?

```python
import requests
import json
import os,binascii

def sending(message):
    url = 'http://127.0.0.1:6613/'
    response = requests.post(url, data=message)
    print response.content
    return response.content

def ed25519(data_js):
    req=json.loads(data_js)
    print "Send gen parameters : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ=json.loads(data_js_n)
    print "Recived  ed25519 gen: \n"+(json.dumps(answ)) +"\n\n\n"
    json_s=json_v='{ "version": 1 , "algorithm":"ED25519", "type":"string","plaintext": "Hello world!", "hex":0,"privkey": "" ,"operation":"sign"}'
    req=json.loads(json_s)
    req["privkey"]=answ["privkey"]
    print "Send sign : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_1=json.loads(data_js_n)
    print "Recived  sign done: \n"+(json.dumps(answ_1)) +"\n\n\n"
    json_v='{ "version": 1 , "algorithm":"ED25519", "type":"string","plaintext": "Hello world!", "hex":0,"pubkey": "" ,"sign":"","operation":"verify"}'
    req=json.loads(json_v)
    req["pubkey"]=answ["pubkey"]
    req["sign"]=answ_1["sign"]
    print "Send verify : \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_2=json.loads(data_js_n)
    print "Recived  verify done: \n"+(json.dumps(answ_2)) +"\n\n\n"

ed25519_gen='{ "version": 1 , "algorithm":"ED25519", "operation":"gen"}'
ed25519(ed25519_gen)
```

Json to gen

```javascript
{"operation": "gen", "version": 1, "algorithm": "ED25519"}
```

Json to sign

```javascript
{"algorithm": "ED25519", "plaintext": "your string", "hex": BOOL, "version": 1, "operation": "sign", 
"type": "string", "privkey": "your hex privkey"}
```

Json to verify

```javascript
{"algorithm": "ED25519", "plaintext": "Hello world!", "pubkey": "your hex pubkey", "hex": BOOL, 
"sign": "your hex signature", "version": 1, "operation": "verify", "type": "string"}
```

## How to X25519?

```python
import socket
import json
import os,binascii

def sending(message):
    ip = '127.0.0.1'
    port = 6613
    BUFFER_SIZE = 65536
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((ip, port))
    s.send(message)
    data = s.recv(BUFFER_SIZE)
    s.close()
    return data

def x25519():
    x25519_gen='{ "version": 1 , "algorithm":"X25519", "operation":"gen"}'
    req=json.loads(x25519_gen)
    print "Send gen parameters (A): \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ=json.loads(data_js_n)
    print "Recived gen parameters donde (A): \n" + (json.dumps(answ)) +"\n\n\n"
    data_js_n=sending(json.dumps(req))
    print "Send gen parameters (B): \n " + json.dumps(req) +"\n"
    answ_1=json.loads(data_js_n)
    print "Recived gen parameters donde (B): \n" + (json.dumps(answ_1)) +"\n\n\n"
    agree='{ "version":1 , "algorithm":"X25519", "privkey":"","sharedpub":"", "operation":"agree"}'
    req=json.loads(agree)
    req["privkey"]=answ["privkey"]
    req["sharedpub"]=answ_1["pubkey"]
    print "Send agreetment (A): \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_2=json.loads(data_js_n)
    print "Recived agreetment donde (A): \n" + (json.dumps(answ_2)) +"\n\n\n"
    req["privkey"]=answ_1["privkey"]
    req["sharedpub"]=answ["pubkey"]
    print "Send agreetment (B): \n " + json.dumps(req) +"\n"
    data_js_n=sending(json.dumps(req))
    answ_3=json.loads(data_js_n)
    print "Recived agreetment donde (B): \n" + (json.dumps(answ_3)) +"\n\n\n"

x25519()
```

Json to gen

```javascript
{"operation": "gen", "version": 1, "algorithm": "X25519"}
```

Json to agree

```javascript
{"operation": "agree", "version": 1, "sharedpub": "your partnert hex pubkey", 
"algorithm": "X25519", "privkey": "your hex privkey"}
```


---

# Agent Instructions: 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://coherence.3vidence.com/curve-25519.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.
