I was trying to implement some El Gamal cryptography in plutus, basic verification of statements. But while trying to implement an efficient modular exponential function I noticed that the current
PlutusTx.Prelude does not even provide a simple power function
(^). Digging even deeper I saw that the
PlutusTx.Prelude only povides an
even function and not even an
odd function. How can I contribute to add these function to
Is my implementation correct? I import
Prel. Do I also need to add the template haskell
inlinable pragma if I make this a library?
power :: Integer -> Integer -> Integer power x n |(n==1) = x | Prel.even n = (power x ( Prel.divide n 2))*(pow x ( Prel.divide n 2)) | Prel.even (n-1) = x * (power x (n-1)) expMod :: Integer -> Integer -> Integer -> Integer expMod b e m | b == 1 = b | e == 0 = 1 | e == 1 = b `Prel.modulo` m | even e = let p = expMod b (e `Prel.divide` 2) m `Prel.modulo` m in (power p (2::Integer)) `Prel.modulo` m | otherwise = (b * expMod b (e-1) m) `Prel.modulo` m
which seems to compile without the pragma in a validator.