1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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(10000))
- 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)
- log.Println(p1.priv.x, p1.pub.p)
- log.Println(p2.priv.x, p2.pub.p)
- log.Println(p1.priv.secret(p2.pub))
- log.Println(p2.priv.secret(p1.pub))
- 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))
- aPair, err := p2.pub.attack(context.Background())
- if err != nil {
- t.Fatal(err)
- }
- p2.Map().LogPretty()
- aPair.Map().LogPretty()
- log.Println(p1.priv.secret(p2.pub))
- log.Println(p2.priv.secret(p1.pub))
- log.Println(aPair.priv.secret(p1.pub))
- data, err = p2.messageDecode(encoded, p1.pub)
- log.Println(string(data), err)
- data, err = aPair.messageDecode(encoded, p1.pub)
- log.Println(string(data), err)
- }
|