I am doing some math calculations with os.time() to calculate what I need to divide another value by just returns inf since it is bigger then the 2^53 limit or whatever, how can I fix this? (For reference this is what I am doing)
local time = os.time()
local g = math.pow(time, #key - i) -- 0-32
character * g -- num * g
then trying to undo it
local g = math.pow(time, #key - i);
g = character / g;
print(g) -- prints inf, should be the original "character" value...
The only way I can replicate your error is by having the second argument of math.pow() be greater than 1.365. You should print #key - i to ensure that it really is -32. Unless you mean that it will count from 0 to 32 in which case, that’s the problem.
How large is #key
wow… why is the term 31-1chars not allowed? Sometimes I need a clarification in under that amount of chars and it’s a brief explanation of the extra characters. Ohh well, my mini rant was enough to get me past the minimum character limit
Actually why do you need to use math.pow on time? I’m pretty sure that’s your issue, but without context I can’t really see why you need it. Can’t you just not encrypt the data? Then you wouldn’t need to unencrypt it.
for i = #key, 1, -1 do
local character = string.sub(key, #key - i + 1, #key - i + 1); -- if #key is 10, and i = 7, then it is 4
if #key - i + 1 > #key then
character = string.sub(key, #key, #key);
end
if tonumber(character) then
hashedKey[i] = character;
local g = math.pow(LockService.Salt[player.UserId], #key - i); -- if #key is 10, and i = 7, then it is 3
--local num = string.byte(character) * g;
hashedKey[i] = character * g;
else
hashedKey[i] = character
end
end
the “salt” is os.time(), basically the key to encrypting and decrypting
Decrypting:
for i = #key, 1, -1 do
local character = key[i];
print(character)
if tonumber(character) then
local g = math.pow(salt, #key - i); -- 10, i = 7, g = 3
g = character / g;
print(g)
decrypt = decrypt .. tostring(g);
elseif character ~= nil then
decrypt = decrypt .. character;
print(character, "string")
else
print("Neither?", character);
end
end
This is not unusual. os.time() returns a fairly large number, around ten digits, whose negative power is a number so small that it exceeds the lower limit of an IEEE 64-bit floating-point number. It is so small that it is simply interpreted as zero. So any number divided by zero is Infinity.
You might consider using a fraction of os.time() or scaling it in some way to avoid that overflow.