diff options
Diffstat (limited to 'lib/rsa_test.go')
-rw-r--r-- | lib/rsa_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/rsa_test.go b/lib/rsa_test.go index ee71755..4f65468 100644 --- a/lib/rsa_test.go +++ b/lib/rsa_test.go @@ -50,3 +50,27 @@ func TestEGCD(t *testing.T) { } } + +func TestInvMod(t *testing.T) { + a := big.NewInt(17) + b := big.NewInt(3120) + e := big.NewInt(2753) // Expected inverse. + i, err := invmod(a, b) + if err != nil { + t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + } + if i.Cmp(e) != 0 { + t.Errorf("gcd(%v,%v) != %v", a, b, e) + } + + a = big.NewInt(240) + b = big.NewInt(47) + e = big.NewInt(19) // Expected inverse. + i, err = invmod(a, b) + if err != nil { + t.Errorf("invmod(%v,%v) failed: %v", a, b, err) + } + if i.Cmp(e) != 0 { + t.Errorf("gcd(%v,%v) != %v", a, b, e) + } +} |