This variation of the Base64 encodeing sytem is slightly cheaper to code than the standard due to the rearranging of the values used.
6 bit input value | ASCII character range produced | gap |
0...9 | "0"..."9" | 30h, 48d, '0' |
10...35 | "A"..."Z" | 7, 'A'-':' |
36...61 | "a"..."z" | 6, 'a'-'[' |
62 | "+" | -80d, -50h, '+'-'{' |
63 | "?" | 20d, 14h, '?'-',' |
Encode 3 bytes into 4 bytes consisting of only the characters 0...9, A...Z, a...z, and +
Entry:
lodsd dec esi mov edx,eax mov ecx,4 .Repeat and al, 00111111y add al, ('0') .If al > '9' add al, ('A' - ':') .If al > 'Z' add al, ('a' - '[') .If al > 'z' .if al > 'z'+1 mov al, '?' .else mov al, '+' .EndIf .EndIf .EndIf .EndIf stosb shr edx, 6 mov al,dl .Untilcxz
Decode
get value .if al < 'a' .if al < 'A' .if al < '0' .if al == '+' mov al, 62 .else stc breakpoint .endif .elseif al > '9' .if al == '?' mov al, 63 .else stc breakpoint .endif .else ;0...9 sub al, '0' .endif .elseif al > 'Z' stc breakpoint .else ;A...Z sub al, 'A' - 10 .endif .elseif al > 'z' stc breakpoint .else ;a...z sub al, 'a' - 36 .EndIf
Better?
sub al, '0' .if Carry? .if al == '+' - '0' mov al, 62 .else breakpoint ;invalid character in Mime input stream .endif .else .if al > 9 sub al, 'A' - ':' ; if it was A, now its 10 .if Carry? .if al == '?' - ('A' - '0') mov al, 63 .else breakpoint ;invalid character in Mime input stream .endif .else .if al > 9 + 26 sub al, 'a' - '[' ; if it was a, now its 36 .if al > 9 + 26 + 26 breakpoint ;invalid character in Mime input stream .endif .endif .endif .endif .endif