## MD5 Implementation

TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

### MD5 Implementation

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
Enjoy
zorg
Party member
Posts: 3090
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: MD5 Implementation

Me and my stuff True 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.
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

### Re: MD5 Implementation

didn't realise it was there...

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

### Re: MD5 Implementation

lol kikito is part of this forum so im sure most of his work is already known.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

### Re: MD5 Implementation

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: MD5 Implementation

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.
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

### Re: MD5 Implementation

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.

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: MD5 Implementation

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.
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

### Re: MD5 Implementation

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"

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"

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.

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm