diff options
author | Óscar Nájera <hi@oscarnajera.com> | 2021-07-06 22:04:02 +0200 |
---|---|---|
committer | Óscar Nájera <hi@oscarnajera.com> | 2021-07-06 22:04:02 +0200 |
commit | 7067e6f770dc5ff0ce511ae23fb2cf31172b51eb (patch) | |
tree | 981c161666bb6fd6cf5c995314f1e1f3838dcb36 | |
parent | 92c83aae833d979a9e39cfaee109ce06d94dbb34 (diff) | |
download | programmingbitcoin-7067e6f770dc5ff0ce511ae23fb2cf31172b51eb.tar.gz programmingbitcoin-7067e6f770dc5ff0ce511ae23fb2cf31172b51eb.tar.bz2 programmingbitcoin-7067e6f770dc5ff0ce511ae23fb2cf31172b51eb.zip |
Binary expansion semigroup
-rw-r--r-- | ecc.hs | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -95,11 +95,11 @@ add p q in ECPoint new_x new_y (a p) (b p) -binaryExpansion :: (Eq a, Fractional a) => Integer -> ECPoint a -> ECPoint a -> ECPoint a +binaryExpansion :: (Semigroup a) => Integer -> a -> a -> a binaryExpansion m value result | m == 0 = result - | otherwise = binaryExpansion (m `shiftR` 1) (add value value) accumulator + | otherwise = binaryExpansion (m `shiftR` 1) (value <> value) accumulator where - accumulator = if m .&. 1 == 1 then add result value else result + accumulator = if m .&. 1 == 1 then result <> value else result scalarProduct :: (Eq a, Fractional a) => Integer -> ECPoint a -> ECPoint a scalarProduct m ec = binaryExpansion m ec Infinity |