MD5 + SHA1 + SHA512

User projects written in or related to FreeBASIC.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

MD5 + SHA1 + SHA512

Postby MOD » Feb 23, 2010 20:21

I think this could be useful for some people:

To create MD5 hashvalues:

Code: Select all

#Include "MD5Checksum.bas"

createHash(text As String) As String
'and
createFileHash(file As String) As String


SHA1 hashes:

Code: Select all

#Include "SHA1Checksum.bas"

createSHA1(text As String) As String
'and
createFileSHA1(file As String) As String


SHA512 hashes:

Code: Select all

#Include "SHA512Checksum.bas"

createSHA512(text As String) As String
'and
createFileSHA512(file As String) As String


So, this should be really easy to use.

Download MD5Checksum

Download SHA1Checksum

Download SHA512Checksum

All In One Download with additional versions (marked with a "+") which are protected in namespaces

The zips includes files with examples and just ignore the german comments ;)


edit:
The downloads contain also a single .bi-version. Those who want to compile it to moduls could use the .bas+.bi-version. Both are pretty much the same code.

All shared variables are replaced.
Last edited by MOD on Jan 16, 2011 14:42, edited 5 times in total.
tinram
Posts: 88
Joined: Nov 30, 2006 13:35
Location: UK

Postby tinram » Feb 25, 2010 12:35

SHA512 is a strong hash.
I verified your implementation against PHP's hash('sha256', '...') - the few random strings I compared matched.

On a Duo 2GHz, your FB SHA512 hashed 10,000 80-char strings per second. With the same, interpreted PHP took ~0.1 seconds. For single hash checking, your code would be fine, but for much I/O processing, it would be worth optimizing.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Postby MOD » Feb 25, 2010 13:16

I could do some optimization but to speed it really up, you'll need ASM. Due to the lack of my knowledge about ASM and how to use it properly, i can't do it.

The code is open source, so if anyone could do some ASM-voodoo, it would be great ;)
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Re: MD5 + SHA512

Postby Fox » Mar 14, 2010 19:25

MOD wrote:I think this could be helpful for some people:

To create MD5 hashvalues:
(...)

SHA512 hashes:
(...)


Thank you a lot! This is exactly what I was searching for quite a long time - an easy to use module for handling checksums :)

I tested the MD5 module, and I confirm that it does the job perfectly (I tested both createHash and createFileHash functions on various contents).

A quick suggestion: it would be very nice if you could put all required code for each checksum into one file. For example, have all the MD5-related stuff in one "md5lib.bi" file, instead of having to use both md5checksum.bi and md5checksum.bas...
Also, I see that you are using some shared variables in your code. Could be nice to avoid using SHARED, as it will pollute all the rest of the program which uses your module (for example, it will be impossible for the user of your library to use a variable named "padding", as you are declaring it as shared).

Anyway, you did a great piece of work!
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Postby MOD » Mar 14, 2010 20:29

Just put the padding variable into the type and copy the text in MD5Checksum.bas into the .bi (except of the "include").

I'll do the changes during the next days.
VictorVE
Posts: 5
Joined: Mar 19, 2010 0:22

Postby VictorVE » Mar 19, 2010 1:32

Thanks MOD,

This is a truly great addition.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Postby MOD » Mar 20, 2010 12:25

As promised I changed the SHARED variables and included the code into one .bi

Download see first post.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Postby MOD » Mar 20, 2010 18:06

Download for SHA1Checksum see first post.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 6 guests