Base64Encoder PB 5.51

Just starting out? Need help? Post your questions and find answers here.
Trion
New User
New User
Posts: 7
Joined: Tue Dec 27, 2016 11:13 pm

Base64Encoder PB 5.51

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Base64Encoder PB 5.51

Post 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
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Base64Encoder PB 5.51

Post 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)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Base64Encoder PB 5.51

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Fred
Administrator
Administrator
Posts: 16681
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Base64Encoder PB 5.51

Post by Fred »

This has been changed to "Base64EncoderBuffer".
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Base64Encoder PB 5.51

Post by collectordave »

Working again thanks fred


cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply