Page 1 of 1

[BUG] Unicode&DES (Was: Cipher.pb to Unicode compatible)

Posted: Tue Nov 25, 2014 7:38 pm
by bbanelli
Greetings to all,

Code: Select all

*TestString = AllocateMemory(100)
*TestKey = AllocateMemory(100)

PokeS(*TestString, "abc", -1, #PB_Ascii)

; MessageRequester("CRC32 Test", "Should be 352441C2 : "+Hex(CRC32Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)), 0)))
Debug "CRC32 Test -> Should be 352441C2 : " + Hex(CRC32Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii))))

PokeS(*TestString, "PureBasic",-1,#PB_Ascii)

; MessageRequester("MD5 Test"  , "Should be ed50deb5bb795508b8a5c8e50dafa954 : "+MD5Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii))), 0)
Debug "MD5 Test -> Should be ed50deb5bb795508b8a5c8e50dafa954 : "+MD5Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)))

PokeS(*TestString, "1Fr",-1,#PB_Ascii)
PokeS(*TestKey, "Fr",-1,#PB_Ascii)

; MessageRequester("DES Test"  , "Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii)), 0)
Debug "DES Test -> Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii))

PokeS(*TestString, "PureBasic",-1,#PB_Ascii)

*OutputBuffer = AllocateMemory(100)
Base64Encoder(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)), *OutputBuffer, 100)
; MessageRequester("Base64 Test", "Should be UHVyZUJhc2lj : "+PeekS(*OutputBuffer,-1, #PB_Ascii), 0)
Debug "Base64 Test -> Should be UHVyZUJhc2lj : "+PeekS(*OutputBuffer,-1, #PB_Ascii)
Everything seems to be working fine except DES Test, which gives:

Code: Select all

CRC32 Test -> Should be 352441C2 : 352441C2
MD5 Test -> Should be ed50deb5bb795508b8a5c8e50dafa954 : ed50deb5bb795508b8a5c8e50dafa954
DES Test -> Should be FrfWXJ4yTjycc : FrfWXJ4yTjycc954 : ed50deb5bb795508b8a5c8e50dafa954
Base64 Test -> Should be UHVyZUJhc2lj : UHVyZUJhc2lj
However, if I move "DES part"

Code: Select all

PokeS(*TestString, "1Fr",-1,#PB_Ascii)
PokeS(*TestKey, "Fr",-1,#PB_Ascii)

; MessageRequester("DES Test"  , "Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii)), 0)
Debug "DES Test -> Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii))
anywhere else, before or after other functions, it works properly! For example:

Code: Select all

*TestString = AllocateMemory(100)
*TestKey = AllocateMemory(100)

PokeS(*TestString, "1Fr",-1,#PB_Ascii)
PokeS(*TestKey, "Fr",-1,#PB_Ascii)

; MessageRequester("DES Test"  , "Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii)), 0)
Debug "DES Test -> Should be FrfWXJ4yTjycc : "+DESFingerprint(PeekS(*TestString,-1,#PB_Ascii), PeekS(*TestKey,-1,#PB_Ascii))

PokeS(*TestString, "abc", -1, #PB_Ascii)

; MessageRequester("CRC32 Test", "Should be 352441C2 : "+Hex(CRC32Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)), 0)))
Debug "CRC32 Test -> Should be 352441C2 : " + Hex(CRC32Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii))))

PokeS(*TestString, "PureBasic",-1,#PB_Ascii)

; MessageRequester("MD5 Test"  , "Should be ed50deb5bb795508b8a5c8e50dafa954 : "+MD5Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii))), 0)
Debug "MD5 Test -> Should be ed50deb5bb795508b8a5c8e50dafa954 : "+MD5Fingerprint(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)))

PokeS(*TestString, "PureBasic",-1,#PB_Ascii)

*OutputBuffer = AllocateMemory(100)
Base64Encoder(*TestString, Len(PeekS(*TestString, -1, #PB_Ascii)), *OutputBuffer, 100)
; MessageRequester("Base64 Test", "Should be UHVyZUJhc2lj : "+PeekS(*OutputBuffer,-1, #PB_Ascii), 0)
Debug "Base64 Test -> Should be UHVyZUJhc2lj : "+PeekS(*OutputBuffer,-1, #PB_Ascii)
provides

Code: Select all

DES Test -> Should be FrfWXJ4yTjycc : FrfWXJ4yTjycc
CRC32 Test -> Should be 352441C2 : 352441C2
MD5 Test -> Should be ed50deb5bb795508b8a5c8e50dafa954 : ed50deb5bb795508b8a5c8e50dafa954
Base64 Test -> Should be UHVyZUJhc2lj : UHVyZUJhc2lj

Re: Cipher.pb to Unicode compatible

Posted: Tue Nov 25, 2014 8:42 pm
by infratec
Hi,

I think you found a bug :!:

It looks that DESFingerprint() adds always only one 0 at the end of the string.
In unicode mode that's wrong.
So additional bytes are printed because the string end is not found.

If you add

Code: Select all

+ ""
every thing works fine.

Bernd

Re: Cipher.pb to Unicode compatible

Posted: Tue Nov 25, 2014 8:48 pm
by infratec
Bug example (compile in unicode :!: ):

Code: Select all

Debug MD5Fingerprint(@"123456789", 9)
Debug DESFingerprint("1Fr", "Fr")
Bug fix:

Code: Select all

Debug MD5Fingerprint(@"123456789", 9)
Debug DESFingerprint("1Fr", "Fr") + ""
Btw.: PB 5.31 x86 on Win 7 x64

Re: Cipher.pb to Unicode compatible

Posted: Wed Nov 26, 2014 1:18 am
by bbanelli
Well, I'd guess DES and Unicode were not so commonly used in Purebasic's history... :D

So, should we leave this here or post on bug forum - since same effect is multiplatform, where should it be put?

Re: Cipher.pb to Unicode compatible

Posted: Wed Nov 26, 2014 7:45 am
by infratec
Hi,

I would put it in the window section.
But you can also change the topic of this thread to something like 'Bug: unicode and DESFingerPrint()'

Bernd