davidm / lua-bit-numberlua Goto Github PK
View Code? Open in Web Editor NEWBitwise operators in pure Lua using Lua numbers
Home Page: http://lua-users.org/wiki/ModuleCompressDeflateLua
License: Other
Bitwise operators in pure Lua using Lua numbers
Home Page: http://lua-users.org/wiki/ModuleCompressDeflateLua
License: Other
Bitwise operations implemented entirely in Lua. Includes Lua 5.2 'bit32' and (LuaJIT) LuaBitOp 'bit' compatibility interfaces. See comments in lmod/bit/numberlua.lua for details.
Hi,
Iโm looking to convert some Lua code that I found online, which uses some jit/ proprietary modules - into pure Lua so I can control my tv using Lua alone.
The code is here, which uses bit.band, bit.bnot, bit.bxor - how best would you convert it ?
local iv = "mUQdS7/RyJTMsiojPz9i1Q=="
local iv_vals = { iv:byte(1, -1) }
local key_vals = {}
for i = 1, 16, 4 do
key_vals[ i ] = bit.band(bit.bnot(iv_vals[ i + 3 ]), 0xFF)
key_vals[ i + 1 ] = bit.band(bit.bnot(iv_vals[ i + 2 ]), 0xFF)
key_vals[ i + 2 ] = bit.band(bit.bnot(iv_vals[ i + 1 ]), 0xFF)
key_vals[ i + 3 ] = bit.band(bit.bnot(iv_vals[ i ]), 0xFF)
end
local key = string.char(unpack(key_vals))
-- local hmac_key_mask = lmcore.hextostr('15C95AC2B08AA7EB4E228F811E34D04FA54BA7DCAC9879FA8ACDA3FC244F3854', true)
local hmac_key_mask = hextostr('15C95AC2B08AA7EB4E228F811E34D04FA54BA7DCAC9879FA8ACDA3FC244F3854')
local hmac_key_mask_vals = { hmac_key_mask:byte(1, -1) }
local hmac_vals = {}
for i = 1, 32, 4 do
hmac_vals[ i ] = bit.bxor(hmac_key_mask_vals[ i ], iv_vals[ bit.band(i + 1, 0xF) + 1 ])
hmac_vals[ i + 1 ] = bit.bxor(hmac_key_mask_vals[ i + 1 ], iv_vals[ bit.band(i + 2, 0xF) + 1 ])
hmac_vals[ i + 2 ] = bit.bxor(hmac_key_mask_vals[ i + 2 ], iv_vals[ bit.band(i - 1, 0xF) + 1 ])
hmac_vals[ i + 3 ] = bit.bxor(hmac_key_mask_vals[ i + 3 ], iv_vals[ bit.band(i, 0xF) + 1 ])
end
I would appreciate any help / advice you could give,
I tried to extract 5 of your bitwise operators into my lua file (do not want to load whole library) but unsuccessfully-
If you have time, look at this question on StackOverflow: (https://stackoverflow.com/questions/68706031/lua-setmetatable-error-attempt-to-call-global-setmetatable-a-nil-value)
I'm new to LUA so I do not understand gema aroung memoise() function - sort of caching for functions!?
I followed the instruction to load the module with Lua 5.1.5
local bit = require "bit.numberlua"
print(bit) -- nil
print(require "bit.numberlua").lshift(1,0) -- 1
``
I dont know why the methods are not exported as local variable bit
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.