aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2021-04-03 20:35:06 +0200
committerÓscar Nájera <hi@oscarnajera.com>2021-04-03 20:35:06 +0200
commit0f6af3be53e80f124a9c7d9294cccf8b4d1c272a (patch)
tree24d139ae431245c7bd2441c8cd98de18ff52be4a
parent1164a0447a5bbadff5b7445343f84e6191b23b36 (diff)
downloadprogrammingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.tar.gz
programmingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.tar.bz2
programmingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.zip
Define FieldElement addition
-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