Journal clone53421's Journal: Base64 decoder (80x86)
Decodes standard MIME-encoded base64 data. (Non-printable characters won't be visible, but they are echoed. E.g. the bell character, 07, should cause the terminal to beep.)
Every 4 characters typed will be decoded to the corresponding 3 characters. (Nothing will be echoed until 4 input characters have been typed.) Any input characters outside the base64 character table will be ignored and will not count toward the 4-character sequence.
The = character is a special character in base64 encoding: it is only used to pad the end of base64-encoded data when encoding the last 1 or 2 bytes (instead of the 3 bytes needed to have a full 24-bit chunk). Although the base64 encoding standard does not allow = symbols in the middle of base64-encoded output, the code does not attempt to verify this. The = symbol is treated as if it was an A (index 0) and it adjusts the number of output characters that are printed: If the 4-character sequence contains one = symbol, only the high 16 bits will be printed (2 characters). If it contains two = symbols, only the high 8 bits will be printed (1 character). Although sequences containing more than two = characters are not permitted according to the base64-encoding standard, the code will still treat them like A's (index 0) and print only the high 8 bits.
See also: Base64 encoder (80x86)
Paste in Notepad, save as base64de_asm.bat, run.
@echo off
goto batch
a
;Base64 decoder
;Accepts input from STDIN and prints to STDOUT
;Input bytes are buffered and decoded at intervals of 4 bytes
;Esc or Ctrl-Z exit, any buffered input will be discarded
;_input
mov si,01cc;_outbuffer
mov bx,0003;loop counter
mov dx,0002;counts output chars
;_inloop
mov di,018c;_charset
mov ah,08
int 21;get a key
cmp al,1b;check for esc
jnz 013a;_continue
;_quit
mov ah,03
xor bh,bh
int 10;get cursor position
mov ah,08
int 10;preserve character under cursor
mov ah,02
mov bl,al
mov cx,dx
mov dl,1a
int 21;send ^z
mov dx,cx
int 10;restore cursor position
mov ah,0a
mov al,bl
mov cx,1
int 10;restore character under cursor
mov ax,4c01
int 21;quit to dos
;_continue
cmp al,1a;check for ^z
jz 0114;_quit
cmp al,3d;check for = (padding)
jnz 0147;_process
dec dx;subtract an output character
xor al,al
jmp 0150;_skip
;_process
mov cx,0040;64 = number of valid chars
repnz
scasb;find al
jnz 0109;_inloop
mov al,cl
;_skip
shl al,1
shl al,1
mov ah,[si]
mov cl,06
rol ax,cl
mov [si],ah
shl al,1
shl al,1
mov ah,[si+1]
rol ax,cl
mov [si+1],ah
shl al,1
shl al,1
mov ah,[si+2]
shl ax,cl
mov [si+2],ah
dec bx
jns 0109;_inloop
;_output
mov bx,0002
sub bx,dx
add si,bx
mov bx,dx
mov ah,02
;_printloop
mov dl,[bx+si];get the next character to be printed
int 21
dec bx
jns 0182;_printloop
jmp 0100;_input
;_charset
db "/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA"
;_outbuffer
db 0,0,0
;ASCIIZ
db "base64de.com",0
;compile
MOV AX,CS
MOV DS,AX
MOV AH,3C
XOR CX,CX
MOV DX,01cf;ASCIIZ
INT 21
MOV BX,AX
MOV CX,01cf;ASCIIZ
MOV DX,0100;where the program starts
SUB CX,DX
MOV AH,40
INT 21
MOV AH,3E
INT 21
MOV AX,4C00
INT 21
r ip
1dc
g
q
:exists
echo You don't need to run this. Run BASE64DE.COM instead.
goto run
:batch
if exist base64de.com goto exists
if exist %0 goto extension
debug < %0.bat
goto run
:extension
debug < %0
:run
pause
cls
base64de.com
Base64 decoder (80x86) More Login
Base64 decoder (80x86)
Slashdot Top Deals