diff options
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 |
commit | 0f6af3be53e80f124a9c7d9294cccf8b4d1c272a (patch) | |
tree | 24d139ae431245c7bd2441c8cd98de18ff52be4a | |
parent | 1164a0447a5bbadff5b7445343f84e6191b23b36 (diff) | |
download | programmingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.tar.gz programmingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.tar.bz2 programmingbitcoin-0f6af3be53e80f124a9c7d9294cccf8b4d1c272a.zip |
Define FieldElement addition
-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 |