Hey i am attempting to make a RSA encryption but there is a problem with the encryption. i have figured out it is my pow() function that is not working correctly
I have based my RSA encryption off of this YouTube video (made in python, attempting to port in LUA)
The problem with the pow function, in python you could do:
pow(101, 13, 143)
# returns 140
I have attempted to implement the pow function as such:
local function pow(x, y, z)
return (x ^ y) % z
end
pow(101, 13, 143)
when calling it with the arguments: 101, 13, 143 it just returns 0
Running the code in python it works fine
def custompow(x, y, z):
return (x ** y) % z # python ** is the same as ^ in LUA
Is there anything I have done wrong (e.g used wrong operator)? Any help is appreciated
Lua 5.1 from the manual 2.5.1, modulus is defined as: a % b == a - math.floor(a/b)*b, I think the problem comes from this algorithm.
This is almost certainly a bug and it returns the correct result in Lua 5.3.
(You can use math.fmod which doesn’t have this problem)
I didnt actually know this, guess i will have to do some more researching. Got any other algorithms? Preferably one that works similar to RSA (Public-key cryptography)