diff options
-rw-r--r-- | ecc.hs | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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 |