MD5 Implementation

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

MD5 Implementation

Post by TheMeq »

Hi All, thought I would share this. It's not by me, it's by Enrique García Cota, Adam Baldwin, hanzao and Equi 4 Software, purely implemented in Lua.

Code: Select all

md5 = require("md5")

Code: Select all

response = md5.sumhexa("hello")
response = 5d41402abc4b2a76b9719d911017c592
md5.lua
(10.42 KiB) Downloaded 277 times
Enjoy :D
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: MD5 Implementation

Post by zorg »

Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

Re: MD5 Implementation

Post by TheMeq »

didn't realise it was there...

/thread

please delete

/forum.quit()
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: MD5 Implementation

Post by bobbyjones »

lol kikito is part of this forum so im sure most of his work is already known.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: MD5 Implementation

Post by undef »

twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: MD5 Implementation

Post by kikito »

The size problems only happen in lua 5.1, and are due to the lack of binary ops (they are simulated with strings and tables, and memory runs out). We use luajit in LÖVE, so it should work ok here.

I could do some rewiring to make lua 5.1 work better, but it isn't really a priority.
When I write def I mean function.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: MD5 Implementation

Post by undef »

kikito wrote:We use luajit in LÖVE, so it should work ok here.
Actually, I had the problem in LuaJIT.
I just didn't report it because somebody else already did it.
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: MD5 Implementation

Post by kikito »

Hi undef,

If you can, please comment on that issue then. The Lua 5.1 case was almost definitively an efficiency-related problem. If you have found a problem in LuaJIT, that might indicate a problem in the implementation. (Please make sure to include a sample failing file if you can).
When I write def I mean function.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: MD5 Implementation

Post by undef »

Hey Kikito,

sorry I didn't report this earlier, I found this bug in two days after it has been first reported, so once I was finally sure it was a bug with your libary (looked for my own mistake forever at first) I found that someone else already reported it so I thought it'll be fine.

So here's an example:

If I take the md5 sum of the libary itself I sometimes get "221f0d89221f0d89221f0d89221f0d89" and sometimes "e4559a35e5559a35e6559a35e6559a35".
Using md5sum on linux however I get "74b44e222b63de5f10917c2accdbce21".

I made a weird example that seems to reliably produce both outputs and makes sure the problem is not with love's read function:

Code: Select all

local md5 = require"md5"

local content = love.filesystem.read"md5.lua"
print( md5.sumhexa( content ) )
print( md5.sumhexa( content ) )
print( md5.sumhexa( content ) )
print( md5.sumhexa( content ) )

love.event.quit()
Produces:

Code: Select all

e4559a35e5559a35e6559a35e6559a35
e4559a35e5559a35e6559a35e6559a35
e4559a35e5559a35e6559a35e6559a35
e4559a35e5559a35e6559a35e6559a35
But if you comment out the last print statement:

Code: Select all

local md5 = require"md5"

local content = love.filesystem.read"md5.lua"
print( md5.sumhexa( content ) )
print( md5.sumhexa( content ) )
print( md5.sumhexa( content ) )
--print( md5.sumhexa( content ) )

love.event.quit()
You get this output:

Code: Select all

221f0d89221f0d89221f0d89221f0d89
221f0d89221f0d89221f0d89221f0d89
221f0d89221f0d89221f0d89221f0d89
This is all very weird to me and if you find out what caused this bug, please let me know!
I would really like to know how this can happen, considering that all the outputs are always uniform.
I think knowing how this happens might be something worth learning.
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: MD5 Implementation

Post by kikito »

This is indeed weird. Just to confirm: which version of Lua are you using to do this? Is it the one embedded with LÖVE, the standalone, linux, mac, windows?
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests