1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package dhellman
- import (
- "context"
- "log"
- "math/big"
- "testing"
- "git.ali33.ru/fcg-xvii/curve/v2/tools"
- )
- func TestMessage(t *testing.T) {
- c, err := tools.NewCurve(
- big.NewInt(2),
- big.NewInt(4),
- )
- if err != nil {
- t.Fatal(err)
- }
- p := tools.SearchPrime(big.NewInt(1000))
- if err = c.SetP(p); err != nil {
- t.Fatal(err)
- }
- if err = c.SetGRandom(context.Background()); err != nil {
- t.Fatal(err)
- }
- p1, _ := randomCurveKeyPair(c)
- p2, _ := randomCurveKeyPair(c)
- message := []byte("Hello, WORLD!!!")
- encoded, err := p1.messageEncode(message, p2.pub)
- if err != nil {
- t.Fatal(err)
- }
- log.Println(encoded)
- data, err := p2.messageDecode(encoded, p1.pub)
- if err != nil {
- t.Fatal(err)
- }
- log.Println(string(data))
- }
|