SirSheepe

Untitled

Nov 3rd, 2018 (edited)
173
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local bigint = require("../bigint")
  3.  
  4. local mod = 1247946709
  5. local a = 24
  6.  
  7. local function modPow(b, e, m)
  8.     if m == 1 then
  9.         return 0
  10.     else
  11.         b = bigint.new(b)
  12.         e = bigint.new(e)
  13.         m = bigint.new(m)
  14.         local z = bigint.new(0)
  15.         local u = bigint.new(1)
  16.         local d = bigint.new(2)
  17.         local r = bigint.new(1)
  18.         b = b % m
  19.         print(bigint.unserialize(e / bigint.new(2), "s"))
  20.         while bigint.compare(e, z, ">") do
  21.             if bigint.compare(e % d, u, "==") then
  22.                 r = (r * b) % m
  23.             end
  24.             e = e / d
  25.             b = (b ^ d) % m
  26.         end
  27.         return bigint.unserialize(r, "s")
  28.     end
  29. end
  30.  
  31. print(modPow(a, 1000, mod))
RAW Paste Data