aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ecc.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/ecc.hs b/ecc.hs
new file mode 100644
index 0000000..6271864
--- /dev/null
+++ b/ecc.hs
@@ -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