on mouseUp ask "Number:" put it into base ask "Exponent:" put it into exponent ask "Modulus:" put it into modulus put base & "^" & exponent & " (mod " & modulus & ") = " & powmod(base &","& exponent &","& modulus) end mouseUp function powmod params put item 1 of params into number put item 2 of params into exp put item 3 of params into modulus put 1 into accum put number into pow2 repeat while (exp > 0) if ((exp mod 2) is 1) then put ((accum * pow2) mod modulus) into accum put ((pow2 * pow2) mod modulus) into pow2 put trunc(exp/2) into exp end repeat return accum end powmod