.386
.model flat,stdcall
option casemap:none

.CODE
; =========================================================
; void b64_encode(LPSTR str_in,LPSTR str_out)
; =========================================================
b64_encode PROC uses esi edi str_in:DWORD,str_out:DWORD
     mov esi,str_in
     mov edi,str_out
@1:  mov eax,'===='
     mov al,[esi]
     test al,al
     jz @3
     inc esi
     mov ah,[esi]
     mov edx,eax
     shr al,2
     call @X ; Байт №1
     ror eax,8
     shr al,4
     shl dl,4
     or al,dl
     call @X ; Байт №2
     mov dl,0FFh
     and dl,dh
     ror eax,16
     jz @2
     rol eax,8
     inc esi
     mov al,[esi]
     mov dl,al
     shr al,6
     shl dh,2
     or al,dh
     call @X ; Байт №3
     test dl,dl
     ror eax,8
     jz @2
     mov al,dl
     call @X ; Байт №4
     inc esi
@2:  ror eax,8
     mov [edi],eax
     add edi,4
     test dl,dl
     jnz @1
@3:  mov BYTE PTR [edi],0
     ret
     ; Переводим в 6-битный ASCII
@X:  and al,3Fh
     add al,'A'
     cmp al,'Z' + 1
     jb @F
     add al,6
     cmp al,'z' + 1
     jb @F
     sub al,75
     cmp al,58
     jb @F
     mov al,'+'
     je @F
     mov al,'/'
@@:  retn
b64_encode ENDP

END