diff options
-rw-r--r-- | ecc.hs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -0,0 +1,15 @@ + +data FieldElement = + FieldElement + { number :: Int + , prime :: Int + } + deriving (Eq) + +instance Show FieldElement where + show a = "FieldElement_" ++ show (prime a) ++ " " ++ show (number a) + +add :: FieldElement -> FieldElement -> FieldElement +add (FieldElement a b) (FieldElement c d) + | b /= d = error "Distinct Fields" + | otherwise = FieldElement (mod (a + c) b) b |