philanc / plc

Pure Lua Crypto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of ~ operator bit working for my version of Lua (5.2)

mike-loopvoc opened this issue · comments

For whatever reason, my version of Lua does not like the ~ operator. I can't even find anything on the internet that describes what it does. Please let me know what it does and if there is a substitution I can make so my code will run. Thanks.

PLC only supports Lua 5.3 and above so that is normal.

The ~ operator is bitwise not, it flips all the bits of the operand. However fixing this won't let you use PLC with Lua 5.2. A reason for supporting only 5.3 and above is that 5.2 does not have 64 bit integers.

Hi mike-loopvoc,

As catwell said the lack of clean 64-bit integers in Lua versions before 5.3 is a big blocking factor. Beyond bit operators and 64-bit integers, another issue is the lack of functions string.pack() and string.unpack() (introduced with Lua 5.3) which are heavily used in plc to extract/insert integers from/to binary strings.

Hi mike-loopvoc,

If you use a standard Lua 5.2, it includes the bit32 library. Here is a pure Lua implementation of RC4 that uses bit32. It should work with Lua 5.2.

https://gist.github.com/philanc/c91a1744de392d75132ea461bdb86125

This is probably the simplest encryption algorithm with a reasonable strength :-) (of course this depends on your constraints and threat scenarios...)

This implements the rc4-drop variant (default drop=256) which is more robust than the default algo. If you want to test or compare with other implementations of standard rc4, just use drop=0 (see the comment in function rc4.encrypt())

Hope this helps!

Phil