Math not working on Server/Client

Basically, I’m trying to replicate the Diffie-Hellman Key Exchange within Roblox, just for my own personal entertainment, and basically I’ve gotten all the math to do everything correct, but when it comes to generating the Secret Key, the math stops mathing.

Now heres the actual formula used to generate the Secret Keys:
math.pow(Root, Key) % Prime
Root and Prime are both known across the Server and Client, while both of them have their own individual keys exclusive to themselves. The secret keys, result of the formula, gets sent between each other, and then held onto by the Server for the Middleman between them

The main issue, is that the formula will work on either the Client or Server, but not on both.

Things I’ve tried is using math.pow, using the exponent symbol (^), and making a function within a module to make it do the formula and return the result.

Generally, this occurs. Both will not do the correct math, and will return 0
image

You may say “oh you just have wrong number usage”, well you’d be wrong. for example heres Bobs ACTUAL secret key:
image
2 = Root, 11 = Prime, and 71 = Bobs Key

This would be Alice’s Secret Key:
image
Again, 2 = Root, 11 = Prime, and 65 = Alices Key

If anyone knows the issue as to why modulo doesn’t seem to work in this instance (unless I’m using the wrong symbol / function) please let me know when possible.

If you need more code to debug, let me know what you are needing and I’ll assist the best I can.

Edit: I created a Manual version of the Modulo function as well:

local FakeModulo = function(Num1, Num2)
	local Quotient = math.floor(Num1 / Num2);
	print("Fake Modulo: " .. Num1, Num2, Quotient)
	local Remainder = Num1 - (Num2 * Quotient)
	print("Remainder:", Remainder); return Remainder
end

Edit 2:
I’ve narrowed it down to where if I use the modulus function, including my manual version, it will work on one of the boundaries, but not the other. Seems strange.

Solved it myself. I learned that math.fmod is the same as modulo

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.