MD5Fingerprint() - am I doing something wrong?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Azul
Enthusiast
Enthusiast
Posts: 109
Joined: Fri Dec 29, 2006 9:50 pm
Location: Finland

MD5Fingerprint() - am I doing something wrong?

Post by Azul »

I'm not sure am I doing something wrong but with some testing I found out.
$ echo -n 123123123 | md5sum
f5bb0c8de146c67b44babbf4e6584cc0

Code: Select all

text.s="123123123"
Debug MD5Fingerprint(@text,StringByteLength(text,#PB_Ascii)) + ", StringByteLength(text,#PB_Ascii)"
Debug MD5Fingerprint(@text,StringByteLength(text,#PB_Unicode))+ ", StringByteLength(text,#PB_Unicode)"
Debug MD5Fingerprint(@text,StringByteLength(text,#PB_UTF8)) + ", StringByteLength(text,#PB_UTF8)"
Debug MD5Fingerprint(@text,Len(text)) + ", Len(text)"
Windows 8, 64 bit. PureBasic 5.22 LTS (Windows - x64)
e597cc6abb03dec3a089eaf7d47e944d, StringByteLength(text,#PB_Ascii)
5be3dde287e770d31cab1ab34085c9c7, StringByteLength(text,#PB_Unicode)
e597cc6abb03dec3a089eaf7d47e944d, StringByteLength(text,#PB_UTF8)
e597cc6abb03dec3a089eaf7d47e944d, Len(text)
Ubuntu 13.10, 32 bit. PureBasic 5.22 LTS (Linux - x86)
[Debugger] f5bb0c8de146c67b44babbf4e6584cc0, StringByteLength(text,#PB_Ascii)
[Debugger] 09e4f0f2091db8bb140f2ab7b27f7d09, StringByteLength(text,#PB_Unicode)
[Debugger] f5bb0c8de146c67b44babbf4e6584cc0, StringByteLength(text,#PB_UTF8)
[Debugger] f5bb0c8de146c67b44babbf4e6584cc0, Len(text)

Code: Select all

; Hello, World!
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: MD5Fingerprint() - am I doing something wrong?

Post by STARGÅTE »

what is the compiler setting? ascii or unicode.

if you want the md5 of a ascii string you have to use:

Code: Select all

text.s="123123123"

*Buffer = AllocateMemory(StringByteLength(text,#PB_Ascii)+1)
PokeS(*Buffer, text, #PB_Ascii)

Debug MD5Fingerprint(*Buffer, StringByteLength(text,#PB_Ascii))
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Azul
Enthusiast
Enthusiast
Posts: 109
Joined: Fri Dec 29, 2006 9:50 pm
Location: Finland

Re: MD5Fingerprint() - am I doing something wrong?

Post by Azul »

It seems it's unicode related. Thanks.
Compiling with -u at Linux and without unicode at windows will swap results.

MD5Fingerprint() (and other *Fingerprint) documentation does not make reference for this.

Code: Select all

; Hello, World!
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MD5Fingerprint() - am I doing something wrong?

Post by infratec »

That's not neccessary.

MD5FingerPrint() is not dedicated to strings.
It is made for binary data in a buffer.
So it depends on you to give the procedure the correct input.

Bernd
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: MD5Fingerprint() - am I doing something wrong?

Post by STARGÅTE »

For example, here is my procedure for MD5StringFingerprint:

Code: Select all

Procedure.s MD5StringFingerprint(String.s, Format.i=#PB_Ascii)
	
	Protected Length.i = StringByteLength(String, Flags)
	Protected *Buffer = AllocateMemory(Length+SizeOf(Unicode))
	Protected Result.s
	
	PokeS(*Buffer, String, #PB_Default, Format)
	Result = MD5Fingerprint(*Buffer, Length)
	FreeMemory(*Buffer)
	
	ProcedureReturn Result
	
EndProcedure

Debug "MD5 Fingerprint = " + MD5StringFingerprint("123123123")
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply