User talk:118.148.86.242

function modular_pow(base, exponent, modulus) is   if modulus = 1 then return 0 Assert :: (modulus - 1) * (modulus - 1) does not overflow base result := 1 base := base mod modulus while exponent > 0 do       if (exponent mod 2 == 1) then result := (result * base) mod modulus exponent := exponent >> 1 base := (base * base) mod modulus return result

Desk check:

modular_pow(4,13,497)

Result should be 445. 118.148.86.242 (talk) 09:14, 21 July 2021 (UTC)