Page 1 of 1

Base64Encoder PB 5.51

Posted: Mon Jan 16, 2017 1:20 am
by Trion
Window 10 64 Bit

Code: Select all

  Example$ = "This is a test string!" 
  Decoded$ = Space(1024) 
  Encoded$ = Space(1024) 
    
  Debug Base64Encoder(@Example$, StringByteLength(Example$), @Encoded$, 1024)
  Debug Encoded$ 
    
  Debug Base64Decoder(@Encoded$, StringByteLength(Encoded$), @Decoded$, 1024)
  Debug Decoded$
Make this
60
䅖潂䝁䅫督杁䝁䅫督杁䝁䅅䅉あ䝁䅕督あ䍁䅁督あ䡁䅉兡畂䝁䅣光㵁
44
This is a test string!

Richard

Re: Base64Encoder PB 5.51

Posted: Mon Jan 16, 2017 2:35 am
by Demivec
The example should be updated. Perhaps this is a better version:

Code: Select all

Example$ = "This is a test string!" 
Decoded$ = Space(1024) 
*EncodeBuffer = AllocateMemory(1024)

EncodedDataLength = Base64Encoder(@Example$, StringByteLength(Example$), *EncodeBuffer, 1024)
Debug EncodedDataLength

;Display encoded data in rows of 16 bytes
For i = 0 To EncodedDataLength - 1 Step 16
  
  If i + 16 < EncodedDataLength
    byteCount = 16 - 1
  Else
    byteCount = (EncodedDataLength % 16) - 1
  EndIf

  output$ = ""
  For j = 0 To byteCount
    output$ + Hex(PeekA(*EncodeBuffer + i + j)) + " "
  Next
  Debug output$
Next


Debug Base64Decoder(*EncodeBuffer, EncodedDataLength, @Decoded$, 1024)
Debug Decoded$

;FreeMemory(*EncodeBuffer)
;*EncodeBuffer = 0

Re: Base64Encoder PB 5.51

Posted: Mon Jan 16, 2017 4:42 pm
by kenmo
The encoder is writing ASCII byte characters into a Unicode string buffer.
The quick fix:

Code: Select all

;Debug Encoded$
Debug PeekS(@Encoded$, -1, #PB_Ascii)

Re: Base64Encoder PB 5.51

Posted: Sat Feb 25, 2017 8:45 am
by collectordave
Running the above with PB5.6B3
I get an error on this line

EncodedDataLength = Base64Encoder(@Example$, StringByteLength(Example$), *EncodeBuffer, 1024)

That Base64Encoder has the wrong number of parameters. The help file also shows 2 parameters not four.

Am I missing something or is this broken?

Regards

cd

Re: Base64Encoder PB 5.51

Posted: Sat Feb 25, 2017 9:13 am
by Fred
This has been changed to "Base64EncoderBuffer".

Re: Base64Encoder PB 5.51

Posted: Sat Feb 25, 2017 9:19 am
by collectordave
Working again thanks fred


cd