Bit32 Lua library is now available

You can’t practically “unhash” a hash algorithm using a secure algorithm without an infeasible amount of time because of the use of trapdoor functions, which are also used in cryptosystems such as RSA, so any consideration of being able to “unhash” a hash is irrelevant because no human alive has that ability and probably wont for many thousands of years. There’s a big wikipedia article if you want to read up on how trapdoor functions are used in hashing and asymmetric encryption: https://en.wikipedia.org/wiki/Trapdoor_function

1 Like

As some other people were saying an encryption library (AES, Base64, SHA, …) would be a nice feature to have even if it somewhat extreme for roblox it could have its uses

Hmm, I’m thinking of hashing a string and then rehashing it because online decryptions for SHA-1 (and etc) are logged and recorded?

When will the documentation for this be on the dev hub?

1 Like

So this means we have improvements and better LUA? Well that’s awesome

Would we have any methods documented so far that could determine if a given number is structured as an integer or a float? It seems that these methods basically runs all decimal numbers to their nearest integers.

I believe bit32 throws errors when there’s no integer representation for the number rather than truncating or rounding it.

I’m also not sure how useful having a function specifically to tell if a number is an integer or not would be since in Lua 5.1 (and thus Roblox) all numbers are doubles regardless. If you really need to check if something is an integer you can use n%1 == 0.

BITWISE OPERATORS! yeet

No but seriously I probably will never need to use these, but good to see they’re here

1 Like

Has anyone made a HMAC SHA-256 module with this for the public yet? Please let me know, thanks in advance.

there was already lua hasher
hasher.lua (26.4 KB)

1 Like

is it necessary to encrypt/hash data on Roblox? you should really be handling data on the server

Some 3rd-party APIs may require the data to be hashed or whatever on arrival (e.g. GameAnalytics API, which requires an HMAC Authorization header).

1 Like

Woah, this is completely new to me, can’t wait to learn it!

Hashing is now far faster because comparison operations can be done at the C level, so it’s now a plausible thing to implement into your games (if you so choose)

1 Like

ah. never considered third party. that’s fair enough

Yes yes yes yes thank you! Now I’m just waiting for bigint

From what I recall, floats are split into a mantissa and an exponent (kinda like scientific notation, but in base 2). Integer numbers utilise all 32 (or 64) bits to represent an integer value. I could gather from this article that Rōblox are starting to implement integer-optimised functions.

I didn’t yet look into how the VM determines to store a number as an integer or as a float, but Rōblox’s sandboxing makes it hard to determine how much memory each value takes up.

That is indeed how floats and integers are represented. If you want to get into the nitty gritter, that’s why Lua didn’t have true bitwise operators until 5.3, when they added integers. Performing a bitwise operation on a double is an interesting thought experiment, one which the creators of Lua decided to not make people think about.

bit32 is just a solution to bitwise operations without an integer subtype, one which happened to have already been added to Lua so Roblox decided to go with it. There’s nothing particularly special about it nor does it signify the beginning of a plan to implement “integer-optimized” functions. It’s just a porting of a library that people have been asking for for a while.

Though on a totally unrelated note, I’ve run into my first problem with bit32! Namely, SHA-512 uses 64-bit numbers, meaning it’s not possible to implement (easily) with bit32. Alas, we shall be restricted to SHA-256/224.

Given that this library was implemented in Lua 5.2 (whereas integers were in 5.3), that would make sense. I’ve also found a downside to the xor method (in terms of comparing booleans): it’s an estimated 5×-7× slower to use that than to use and/or operators.

With luck, first-class support for bit32 functions will make that less of an issue. Worst case, you can always use nand to construct xor. :wink: