base64 encoding routine

Talk about YBoxen, widgets, Propeller hacking, etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
imagitronics
 
Posts: 6
Joined: Sun Feb 01, 2009 10:34 am

base64 encoding routine

Post by imagitronics »

I have created a functional base64 encoding method for the ybox.

It's not ideal as it requires the programmer to declare an output array large enough to hold the result of the encoding procedure. I tried everything I could think of to avoid this by using the size of the input string (strsize(in_ptr)*(4/3)) to store the output, but I couldn't get it.

Download the updated base64.spin.

Sample usage:

Code: Select all

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ
  text : "TV_Text"
  b64  : "base64"

VAR
   byte outstring[25]

PUB start | i
  text.start(12)

  b64.encode(string("admin:admin"), @outstring)
  text.str(@outstring)
  text.out(13)

  b64.encode(string("admin:password"), @outstring)
  text.str(@outstring)
  text.out(13)

  b64.encode(string("Die SPIN Die!"), @outstring)
  text.str(@outstring)
  text.out(13)

  b64.encode(string("meh"), @outstring)
  text.str(@outstring)

  repeat
And a sample image from the above code:
Image

If anyone has any tips that can help get rid of the need to declare the output variable's size, please let me know.
Tim

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: base64 encoding routine

Post by adafruit »

with microcontrollers you tend to have to deal with fixed chunks of RAM...i dont think spin has malloc type things

Locked
Please be positive and constructive with your questions and comments.

Return to “YBox2 (discontinued)”