Was bored, so I figured i would give this a shot.
Untested, so try at your own risk 
Code:
STRING_LENGTH CON 24 ; Must be divisable by 3
in_string VAR BYTE[STRING_LENGTH]
in_byte VAR BYTE
in_bit VAR BYTE
b64_string VAR BYTE[STRING_LENGTH*4/3]
b64_byte VAR BYTE
b64_bit VAR BYTE
temp VAR BYTE
in_byte=0 ; Start at byte 0
in_bit=7 ; Most significant bit first
FOR b64_byte=0 TO (STRING_LENGTH*4/3)-1 ; For each base64 byte:
b64_string[b64_byte]=0 ; Clear the byte
FOR b64_bit=5 TO 0 STEP -1 ; For each bit 5 thru 0:
temp=in_string[in_byte] ; Get the current input byte
temp=temp >> in_bit ; Shift to get the current bit as bit 0
temp=temp & 1 ; Clear the other bits
temp=temp << b64_bit ; Shift to the correct output bit position
b64_string[b64_byte]=temp|b64_string[b64_byte] ; Add the bit to the base64 byte
in_bit=in_bit-1 ; Next less significant bit
IF in_bit=255 THEN ; If we past bit 0:
in_bit=7 ; Set to bit 7 of the next byte
in_byte=in_byte+1
ENDIF
NEXT b64_bit
SELECT CASE b64_string[b64_byte] ; Convert to base64 coded ASCII
CASE IS<=25 ; 0-25
b64_string[b64_byte]=b64_string[b64_byte]+65; "A"-"Z"
CASE IS<=51 ; 26-51
b64_string[b64_byte]=b64_string[b64_byte]+71; "a"-"z"
CASE IS<=61 ; 52-61
b64_string[b64_byte]=b64_string[b64_byte]-4 ; "0"-"9"
CASE 62 ; 62
b64_string[b64_byte]=43 ; "+"
CASE 63 ; 63
b64_string[b64_byte]=47 ; "/"
END SELECT
NEXT b64_byte
Last edited by Kamikaze47; - 8th April 2008 at 21:58.
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
Bookmarks