aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ecc.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/ecc.hs b/ecc.hs
index 6271864..200b613 100644
--- a/ecc.hs
+++ b/ecc.hs
@@ -13,3 +13,32 @@ add :: FieldElement -> FieldElement -> FieldElement
add (FieldElement a b) (FieldElement c d)
| b /= d = error "Distinct Fields"
| otherwise = FieldElement (mod (a + c) b) b
+
+sub :: FieldElement -> FieldElement -> FieldElement
+sub (FieldElement a b) (FieldElement c d)
+ | b /= d = error "Distinct Fields"
+ | otherwise = FieldElement (mod (a - c) b) b
+
+mul :: FieldElement -> FieldElement -> FieldElement
+mul (FieldElement a b) (FieldElement c d)
+ | b /= d = error "Distinct Fields"
+ | otherwise = FieldElement (mod (a * c) b) b
+
+assert :: Bool -> Bool
+assert False = error "WRONG"
+assert x = x
+
+aa =
+ let a = FieldElement 2 31
+ b = FieldElement 15 31
+ in assert
+ (and
+ [ add a b == FieldElement 17 31
+ , a /= b
+ , sub a b == FieldElement 18 31
+ ])
+
+bb =
+ let a = FieldElement 19 31
+ b = FieldElement 24 31
+ in mul a b