aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
blob: 9e19d358889d3eb57cd637f3a946ffa5fc676223 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import "fmt"

func main() {
	fmt.Println("=== secp256k1 from scratch ===")
	fmt.Println()

	// Test field arithmetic with small numbers first
	fmt.Println("Testing field arithmetic:")

	a := NewFieldElementFromInt64(7)
	b := NewFieldElementFromInt64(5)

	fmt.Printf("a = %d\n", 7)
	fmt.Printf("b = %d\n", 5)
	fmt.Printf("a + b = %s (should end in ...c)\n", a.Add(b).String())
	fmt.Printf("a - b = %s (should end in ...2)\n", a.Sub(b).String())
	fmt.Printf("a * b = %s (should end in ...23, which is 35)\n", a.Mul(b).String())

	// Test division: 10 / 5 = 2
	ten := NewFieldElementFromInt64(10)
	five := NewFieldElementFromInt64(5)
	fmt.Printf("10 / 5 = %s (should end in ...2)\n", ten.Div(five).String())

	// Test inverse: 5 * inverse(5) should = 1
	inv := five.Inverse()
	product := five.Mul(inv)
	fmt.Printf("5 * inverse(5) = %s (should end in ...1)\n", product.String())

	fmt.Println()
	fmt.Println("Field arithmetic works!")
}