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

Just starting out? Need help? Post your questions and find answers here.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 541
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

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

Post 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
Last edited by bbanelli on Wed Nov 26, 2014 8:53 am, edited 1 time in total.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
infratec
Always Here
Always Here
Posts: 5568
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cipher.pb to Unicode compatible

Post 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
infratec
Always Here
Always Here
Posts: 5568
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cipher.pb to Unicode compatible

Post 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
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 541
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Cipher.pb to Unicode compatible

Post 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?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
infratec
Always Here
Always Here
Posts: 5568
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cipher.pb to Unicode compatible

Post 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
Post Reply