Code Monkey home page Code Monkey logo

pure_lua_sha's People

Contributors

egor-skriptunoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pure_lua_sha's Issues

"Ethereum" Keccak

Hi, I'm working on a side project for which I have to generate hashes for Ethereum, which uses the old padding of 1 instead of 6. Changing it on this line fixed it for me:

https://github.com/Egor-Skriptunoff/pure_lua_SHA/blob/master/sha2.lua#L4618

Is there any chance of making this configurable for a user of the module or would you accept a PR for this?

This is so one does not have to maintain one's own fork of this project.

(I use this project because of its speed, easy of use and also because I use LuaJit which a lot of other projects do not support (anymore).)

Reference: https://ethereum.stackexchange.com/questions/30369/difference-between-keccak256-and-sha3

Incorrect values returned from bin2base64

First - thank you for your excellent work!.

I attach a short script showing a problem with bin2base64. The script generates a random 10 character string and attempts to convert it via base64 using sha.bin2base64 and compares it with another base64 algorithm. Mismatches are outputted.

I hope this helps you discover the bug in bin2base64.

Regards,

Tom

local sha = require 'sha2'

-- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

-- encoding
function encode_b64(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end

local charset = {}
for i = 0, 255 do table.insert(charset, string.char(i)) end
math.randomseed(os.time())

function string.random(length)

if length > 0 then
return string.random(length - 1) .. charset[math.random(1, #charset)]
else
return ''
end
end

for i=1,100 do
local s = string.random(10)
if encode_b64(s) ~= sha.bin2base64(sha.hex2bin(s)) then
print('error',encode_b64(s),sha.bin2base64(sha.hex2bin(s)))
end
end

Add MIME and other popular formats

Possible add mime encoding-decoding + other popular formats for your choice? So add mime & base64 to tags project. Your script like me - very fast, good job.

Error when used with OpenWrt lua 5.1

Hi, I think that your code isn't accurately detecting Lua 5.1.5 on OpenWrt. Using a simple sha.sha256("test") generates the following error:

lua: ./sha2.lua:309: bad argument #2 to 'string_format' (integer expected, got number)
stack traceback:
        [C]: in function 'string_format'
        ./sha2.lua:309: in function 'HEX'
        ./sha2.lua:2467: in function <./sha2.lua:2433>
        (tail call): ?
        (tail call): ?
        shatest.lua:12: in function 'test'
        shatest.lua:16: in main chunk
        [C]: ?

Is there anything I can do to help debug?

bin2hex add, please.

something like this (for luajit 2.1):
local ffi=require 'ffi'
local C,ibuf,obuf = ffi.C,ffi.new("unsigned char[?]",buf_size),ffi.new("unsigned char[?]",buf_size*2)
while true do
local n = tonumber(C.fread(ibuf,1,ffi.sizeof(ibuf),f_in))
if n==0 then break end
for i=0,n-1 do
local low = ibuf[i]%16
local high = bit.rshift(ibuf[i],4)
obuf[i+i] = high<10 and high+48 or high+55
obuf[i+i+1] = low<10 and low+48 or low+55
end
C.fwrite(obuf,1,n+n,f_out)
end

Thanks for very good (fast!) checksum library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.