Page 1 of 1
Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 9:57 pm
by Karbon
So I have some legacy code where some checksums were created using this code ( I think in PB 4.4).
(New Code)
Code: Select all
Str(Val("$"+Fingerprint(@temp_kb7,StringByteLength(temp_kb7,#PB_Ascii),#PB_Cipher_CRC32)))
(Old Code)
Code: Select all
Str(CRC32Fingerprint(@temp_kb7,StringByteLength(temp_kb7)))
Given the same data, the two checksums are different. I need to figure out how to make the first example generate the exact same checksum as the second (given the same data of course).
I don't have access to the manual from PB 4.40 right now to look and see if it is documented differently. Can anyone help me out?
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 10:05 pm
by JHPJHP
Hi Karbon,
Try the following:
Code: Select all
nLength = StringByteLength(temp_kb7, #PB_Ascii)
*temp_kb7 = AllocateMemory(nLength)
PokeS(*temp_kb7, temp_kb7, nLength, #PB_Ascii)
Fingerprint(*temp_kb7, nLength, #PB_Cipher_CRC32)
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 10:14 pm
by Karbon
Unfortunately that wasn't it (It's an all-ASCII program and I'm using the LTS version for exactly that reason).
Since the original function returned an integer and that's what was stored, and the new version returns a hex string, I'm actually comparing like this :
Code: Select all
Str(Val("$"+Fingerprint(@temp_kb7,StringByteLength(temp_kb7,#PB_Ascii),#PB_Cipher_CRC32)))
But still a no-go. I must be missing something since if it's a true CRC32 implementation the checksums shouldn't ever be different. I'm going to grab the old version and install it when I get back to the house, I just can't download it here over this crappy 4G connection.
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 10:22 pm
by Karbon
You're right, I only saw the original post. Same thing, though, you just unrolled it a bit in your last as far as I can tell..
Other than the #PB_ASCII I don't see any difference in your example and mine.. Am I missing something there?
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 10:43 pm
by JHPJHP
Hi Karbon,
Are you able to post the original string and the expected checksum?
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 10:51 pm
by nco2k
pb doesnt have unsigned longs and Str() expects a quad / Val() returns a quad.
old:
Code: Select all
MyLong.l = CRC32Fingerprint(?MyString, ?MyStringEnd - ?MyString)
Debug Str(MyLong)
Debug Str(CRC32Fingerprint(?MyString, ?MyStringEnd - ?MyString) & $FFFFFFFF)
Debug StrU(CRC32Fingerprint(?MyString, ?MyStringEnd - ?MyString), #PB_Long)
Debug UCase(RSet(Hex(CRC32Fingerprint(?MyString, ?MyStringEnd - ?MyString), #PB_Long), 8, "0"))
DataSection
MyString:
Data.a $48, $65, $6C, $6C, $6F
MyStringEnd:
EndDataSection
new:
Code: Select all
UseCRC32Fingerprint()
MyLong.l = Val("$"+Fingerprint(?MyString, ?MyStringEnd - ?MyString, #PB_Cipher_CRC32))
Debug Str(MyLong)
Debug Str(Val("$"+Fingerprint(?MyString, ?MyStringEnd - ?MyString, #PB_Cipher_CRC32)))
Debug UCase(RSet(Fingerprint(?MyString, ?MyStringEnd - ?MyString, #PB_Cipher_CRC32), 8, "0"))
DataSection
MyString:
Data.a $48, $65, $6C, $6C, $6F
MyStringEnd:
EndDataSection
i still hope that regular Str() gets an optional type like StrU() -
http://www.purebasic.fr/english/viewtop ... =3&t=64823
c ya,
nco2k
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 11:16 pm
by Karbon
So shouldn't these be producing the same string?
New
Code: Select all
Str(Val("$"+Fingerprint(@temp_kb7,StringByteLength(temp_kb7,#PB_Ascii),#PB_Cipher_CRC32)))
Old
Code: Select all
Str(CRC32Fingerprint(@temp_kb7,StringByteLength(temp_kb7)))
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 11:19 pm
by nco2k
no, because Val("$"+X) will return the unsigned value of the hex string.
Code: Select all
MyQuad.q = Val("$"+Fingerprint(@temp_kb7,StringByteLength(temp_kb7,#PB_Ascii),#PB_Cipher_CRC32))
Debug Str(MyQuad)
MyLong.l = Val("$"+Fingerprint(@temp_kb7,StringByteLength(temp_kb7,#PB_Ascii),#PB_Cipher_CRC32))
Debug Str(MyLong)
c ya,
nco2k
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 11:42 pm
by Karbon
Well, damn... I thought you were saying your old/new examples above were equivalents.
Do you have any idea what the old CRC32Fingerprint() returned?
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Wed Jan 24, 2018 11:50 pm
by nco2k
Karbon wrote:Well, damn... I thought you were saying your old/new examples above were equivalents.
they are. just run them when u get home.
Karbon wrote:Do you have any idea what the old CRC32Fingerprint() returned?
yes, a signed long.
c ya,
nco2k
Re: Old CRC32Fingerprint() Versus Fingerprint()
Posted: Thu Jan 25, 2018 1:33 am
by Karbon
Awesome -- thank you!