Base64 Encoding Using ORCA/Pascal

I am currently working on a TCP/IP New Desk Accessory (what else do I ever work on?) that requires “basic authentication”. Basic authentication is a really simple, very unsecure way of encoding a username and password. In essence, the username and password are joined together in a single string with a colon between the two:

username:password

and then encoded into Base64. As I’ve never tried to figure out how to encode into Base64 before, I decided this would be a nice exercise for my Pascal skills.

Working backwards, I can easily figure out what the end result of the encoding is supposed to be; there are many online Base64 encoding Web pages, so the string above would be encoded as:

dXNlcm5hbWU6cGFzc3dvcmQ=

How do we get there from here?

Wikipedia to the rescue! Wikipedia provides about as close to a plain English step by step on encoding a string as Base64.

First off, each character that needs conversion must be converted to its ASCII numeric equivalent. Well, actually, first, once we have the username:password string built–which are two p-strings combined to make a c-string; p-strings because that’s an easier way for me to get input from a IIgs LineEdit dialog, and a c-string because its longer length could be an advantage depending on how long the username and password are–we need to look at it character by character. So in order to do that, we take the assembled username:password string and use a loop to parse out the characters one by one:

Procedure CharParser; {parses out each character}

Var
username, password: pstring;

parsedchar: char;
rawauthstring, binauthstring: cstring;

ploop: integer;

begin

rawauthstring := concat(username, ':', password); {combine the username}
{and password with a }
{colon between them }

ploop := 1; {parsing loop--1 for 1st character}
While ploop <= length(rawauthstring) do begin
parsedchar := rawauthstring[ploop]; {sets parsedchar to the current}
{character as ploop increases }
ploop := ploop + 1; {increment ploop by a character}
end; {parsing loop}
end; {CharParser}

This procedure, while it will run right now, isn’t useful without a bit more code that we won’t get into yet. Basically as the ploop starts with the first character in rawauthstring and moves character by character through the string until it reaches its end, it assigns the character at the current position in the loop to the character value parsedchar, then moves onto the next character. In order for this procedure to be more useful, more has to be done with parsedchar, starting with converting from a character to an ASCII value, then converting the numeric ASCII value into a binary value, padding the length of the binary value so it’s eight digits long, and adding it to a progressively growing string of 0s and 1s for further conversion. We’ll tackle some of this next episode!

23 Responses to “Base64 Encoding Using ORCA/Pascal”

  1. $1000 Welcome Bonus! Says:

    .

    $1000 Welcome Bonus!

  2. Best Online Casino Says:

    Black Jack,Video Poker,Online Slots,Craps

    $1000 Welcome Bonus!

  3. Kylie Batt Says:

    Да, действительно. Я согласен со всем выше сказанным.

    I am currently working on a TCP/IP New Desk Accessory (what else do I ever work on?) that requires “basic authentication”..

  4. Viagra Order Says:

    Viagra - 100mg 90 tablet $168.04

    Viagra order online

  5. BUY Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Online pharmacy viagra

  6. BUY Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Online pharmacy viagra

  7. Buy Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Buying viagra online legal

  8. Buy Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Buy viagra pills online

  9. Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Buy cheap viagra online

  10. Viagra Says:

    Viagra - 100mg 90 tablet $168.04

    Buy viagra soft online

  11. --- Says:

    222

    cialis

  12. Kylie Batt Says:

    В этом что-то есть. Буду знать, благодарю за информацию.

    I am currently working on a TCP/IP New Desk Accessory (what else do I ever work on?) that requires “basic authentication”..

  13. TIMOTHY Says:

    < blockquote >< a href=”http://medicamentspot.com/”>Medicamentspot.com. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. High quality pills. Order pills online< /a >

    Buy:Lasix.Nymphomax.Zocor.Cozaar.Advair.Buspar.Female Pink Viagra.Female Cialis.Zetia.Aricept.Lipothin.Acomplia.SleepWell.Ventolin.Amoxicillin.Lipitor.Benicar.Seroquel.Prozac.Wellbutrin SR.

  14. --- Says:

    ..

    .

  15. --- Says:

    ..

    .

  16. --- Says:

    ..

    .

  17. . Says:

    .

  18. QSC Says:

    QSC http://ACEHARDWAREE.INFO/tag/QSC MX 10 : MX

    MX

  19. 110 Sony cdx/ Says:

    110 Sony cdx/ http://BESTPARTSPLUS.INFO/tag/GT : GT

    110 Sony cdx/

  20. approved Says:

    approved http://fwhitemig41.03GMCPARTS.US/tag/approved dishwashers dishwasher Dishwashers/ : Dishwashers

    dishwashers

  21. Microsoft Says:

    Microsoft http://jspyuutyogl.01DODGEPARTS.US/tag/best+Microsoft+Natural/ : best

    Microsoft

  22. torrent Says:

    torrent http://stanningljxf.AWESOMEBABYCLOTHES.INFO/tag/torrent+money+tanning/ : tanning

    money

  23. Carafe Says:

    krups http://chunteryp4o.05KIAPARTS.US/tag/Carafe+krups+Krups/ : krups

    krups

Leave a Reply

  • Buy me a beer!

    If you like my software, please consider donating with PayPal.