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!
April 3rd, 2010 at 5:31 am
.
$1000 Welcome Bonus!
April 3rd, 2010 at 11:54 pm
Black Jack,Video Poker,Online Slots,Craps
$1000 Welcome Bonus!
April 20th, 2010 at 4:53 am
Да, действительно. Я согласен со всем выше сказанным.
I am currently working on a TCP/IP New Desk Accessory (what else do I ever work on?) that requires “basic authentication”..
April 26th, 2010 at 9:13 am
Viagra - 100mg 90 tablet $168.04
Viagra order online
April 26th, 2010 at 10:43 am
Viagra - 100mg 90 tablet $168.04
Online pharmacy viagra
April 26th, 2010 at 10:43 am
Viagra - 100mg 90 tablet $168.04
Online pharmacy viagra
April 26th, 2010 at 10:29 pm
Viagra - 100mg 90 tablet $168.04
Buying viagra online legal
April 27th, 2010 at 2:28 am
Viagra - 100mg 90 tablet $168.04
Buy viagra pills online
April 27th, 2010 at 5:11 am
Viagra - 100mg 90 tablet $168.04
Buy cheap viagra online
April 27th, 2010 at 6:50 am
Viagra - 100mg 90 tablet $168.04
Buy viagra soft online
May 2nd, 2010 at 4:36 am
222
cialis
May 3rd, 2010 at 9:07 pm
В этом что-то есть. Буду знать, благодарю за информацию.
I am currently working on a TCP/IP New Desk Accessory (what else do I ever work on?) that requires “basic authentication”..
July 20th, 2010 at 11:49 pm
< 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.
July 27th, 2010 at 4:25 am
..
.
July 28th, 2010 at 6:47 am
..
.
August 4th, 2010 at 6:02 am
..
.
August 10th, 2010 at 9:48 am
.
…
August 29th, 2010 at 12:32 am
QSC http://ACEHARDWAREE.INFO/tag/QSC MX 10 : MX
MX
August 29th, 2010 at 1:40 am
110 Sony cdx/ http://BESTPARTSPLUS.INFO/tag/GT : GT
110 Sony cdx/
August 29th, 2010 at 3:13 am
approved http://fwhitemig41.03GMCPARTS.US/tag/approved dishwashers dishwasher Dishwashers/ : Dishwashers
dishwashers
August 29th, 2010 at 3:33 am
Microsoft http://jspyuutyogl.01DODGEPARTS.US/tag/best+Microsoft+Natural/ : best
Microsoft
August 29th, 2010 at 2:47 pm
torrent http://stanningljxf.AWESOMEBABYCLOTHES.INFO/tag/torrent+money+tanning/ : tanning
money
August 29th, 2010 at 7:20 pm
krups http://chunteryp4o.05KIAPARTS.US/tag/Carafe+krups+Krups/ : krups
krups