Base-64 Decoding: Vbscript


By: nbrane
August 11, 2012

Here's the "other half", the decoder.
Experimenting with base-64 (6-bit) encoding, according to Wikipedia etc.

Every 8 bits is made .75 of an output-byte, so every 4 input-bytes (32 bits)
constitutes an even number (3) of output-bytes. ROUGH DRAFT

FOR I = 65 TO 90
X = X & CHR(I)
NEXT
X = X & LCASE(X) & "0123456789+\"
set fso=wscript.createobject("scripting.filesystemobject")
set infile=fso.opentextfile ("B64.out",1)
S=infile.readall
OUT = ""
LS = LEN(S)
ZEROS = STRING(8, CHR(0))
P = INSTR(S, "=")
IF P > 0 THEN
P = LEN(S) - P + 1
S = S & STRING(P, ZEROS)
END IF
FOR I = 1 TO LS STEP 4
PREV = 0: ZZ = 64
FOR J = 1 TO 4
M = I + J - 1: N = MID(S, M, 1)
'find the index location in letter-number string
T = INSTR(X, N) - 1
'split the number into top and bottom parts
TOP = T \ ZZ
BOTT = T - TOP * ZZ
'add the top part to the previous bottom-part
PREV = PREV + TOP
IF PREV > -1 THEN
IF J > 1 THEN OUT = OUT & CHR(PREV)
END IF
'mult. the bottom, shifting it left, leaving zeros on right for next top locn
PREV = BOTT * 4 ^ J
ZZ = ZZ / 4
NEXT
IF M > LS THEN EXIT FOR
NEXT
set outfile=fso.createtextfile("b64dec.out",true)
outfile.write OUT


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question