Skip to content

Instantly share code, notes, and snippets.

@eccstartup
Created December 12, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eccstartup/006bcf3109fffe4ca705 to your computer and use it in GitHub Desktop.
Save eccstartup/006bcf3109fffe4ca705 to your computer and use it in GitHub Desktop.
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