bug in example sha1fingerprint()

Everything else that doesn't fall into one of the other PB categories.
User avatar
niijel
User
User
Posts: 24
Joined: Sun Oct 30, 2005 7:55 pm

bug in example sha1fingerprint()

Post by niijel »

ver 4.60 RC1
windows 64bit (but others also?)

on help page for sha1fingerprint()

[string variable as buffer example works fine!]


Example: with memory buffer

*Buffer = AllocateMemory(500)
If *Buffer
PokeS(*Buffer, "The quick brown fox jumps over the lazy dog.")
SHA1$ = SHA1Fingerprint(*Buffer, MemorySize(*Buffer))
Debug "SHA1 Fingerprint = " + SHA1$
FreeMemory(*Buffer) ; would also be done automatically at the end of the program
EndIf

will return a incorrect sha1 digest unless input string is exactly 500 bytes in length.
this is due to it using the buffer length not the data length.

code returns sha: ab57c34511256b11e101d3b1d17abfb80de95828SHA1
correct is: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

see http://en.wikipedia.org/wiki/SHA-1 for the above example.
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: bug in example sha1fingerprint()

Post by STARGÅTE »

As the code is there, it works properly.

In the example is the fingerprint of the entire buffer can be calculated, not only of the string!

so, no bug!
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