Created
December 12, 2015 15:17
-
-
Save eccstartup/006bcf3109fffe4ca705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Numeric | |
main = putStrLn $ showHex (fastpow c d n) "" | |
c = 0x599f55a1b0520a19233c169b8c339f10695f9e61c92bd8fd3c17c8bba0d5677e | |
d = 0x431d844bdcd801460488c4d17487d9a5ccc95698301d6ab2e218e4b575d52ea3 | |
n = 0x64ac4671cb4401e906cd273a2ecbc679f55b879f0ecb25eefcb377ac724ee3b1 | |
fastpow :: Integer -> Integer -> Integer -> Integer | |
fastpow base exp modulo = fastpow' (base `mod` modulo) exp modulo 1 | |
where fastpow' b 0 m r = r | |
fastpow' b e m r = fastpow' (b * b `mod` m) (e `div` 2) m (if even e then r else (r * b `mod` m)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment