; BASE64编码是邮件加密协议的必用算法,实际上就是一个简单的字节置换
; 首先是将原字符串按6 bits 分组,高2位加0作为一个字节然后查找如下的
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/); 码表获得加密字符.原文字符若不为3的倍数,用0补足参与运算,最后要把全
; 0字节置换为"=",具体算法如下代码所示:
; 可以采用查表法处理,但同样的问题是,那不适我喜欢的方式,让我聪明的程序
; 来干这玩意吧.
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)
; 码表如下:; Value Encoding Value Encoding Value Encoding Value Encoding; 0 A 17 R 34 i 51 z; 1 B 18 S 35 j 52 0; 2 C 19 T 36 k 53 1; 3 D 20 U 37 l 54 2; 4 E 21 V 38 m 55 3; 5 F 22 W 39 n 56 4; 6 G 23 X 40 o 57 5; 7 H 24 Y 41 p 58 6; 8 I 25 Z 42 q 59 7; 9 J 26 a 43 r 60 8; 10 K 27 b 44 s 61 9; 11 L 28 c 45 t 62 +; 12 M 29 d 46 u 63 /; 13 N 30 e 47 v; 14 O 31 f 48 w (pad) =; 15 P 32 g 49 x; 16 Q 33 h 50 yinclude '%fasinc%/win32as.inc'.dataen_1 db "Sun Bird!!!"en1.size=$-en_1fmt db "ENC length=%d DECode length=%d",0buf2 rb 256buf3 rb 256buf rb 256zTit db "By Hume 2K2",0.codeStArT:mov esi,en_1mov edi,bufmov ecx,en1.sizecall base64_encinvokeMessageBox,0,buf,zTit,0mov edi,bufcall my_strlenmov esi,bufmov edi,buf3call base64_decinvokeMessageBox,0,buf3,zTit,0invokewsprintf,buf2,fmt,enc.size,b64.dcode.sizeinvokeMessageBox,0,buf2,zTit,0invokeExitProcess,0my_strlen: ;edi-stringz ecx and eax and edi altered...xor eax,eaxor ecx,-1repnz scasbneg ecxdec ecxdec ecxret;IN : esi=src_begin ecx=len0;OUT: edi=buf contains encoded strings;pure code lines=55 size=112 bytesbase64_enc:xor eax,eaxgen_base64:xor ebx,ebxlodsbshl eax,8loop @@2shl eax,8inc ebxinc ebxjmp @@_@@2:lodsbshl eax,8loop @@3inc ebxjmp @@_@@3:lodsbdec ecx@@_:push ecxpush 4pop ecxpush ecx@@:rol edx,8mov dl,aland dl,00111111Bshr eax,6loop @Bpop ecxcall edx2_b64xchg eax,edxstosdxchg eax,edxpop ecxor ecx,ecxjnz gen_base64mov ecx,ebxsub edi,ecxmov al,"="rep stosbretedx2_b64:cmp dl,62jae dl_62_63cmp dl,51ja digit_0_9add dl,'A'cmp dl,'Z'jbe @Fadd dl,'a'-'Z'-1@@:jmp rotate_edxdigit_0_9:add dl,30h-52jmp rotate_edxdl_62_63:sub dl,62shl dl,2add dl,43rotate_edx:rol edx,8loop edx2_b64retenc.size=$-base64_enc;IN :ecx=length esi=string edi=outBUF;OUT:buf=decompress data edx=actual len;pure code 49 lines and 101 bytes long;many regs are altered.(you can count it!)base64_dec:push edishr ecx,2mov edx,ecximul edx,edx,3next_dword:push ecxlodsdpush 4pop ecxpush ecxcall eax_b64_2_orgpop ecx ;ecx=4!xor ebx,ebxbswap eax@@:shl eax,2shld ebx,eax,6shl eax,6loop @Bmov eax,ebxbswap eaxshr eax,8stosbshr eax,8stoswpop ecxloop next_dwordpop edimov byte [edi+edx],0reteax_b64_2_org:cmp al,'='jne @Fxor al,aldec edx@@:cmp al,'/'ja is_digit_0_9sub al,'+'shr al,2add al,62jmp rotate_eaxis_digit_0_9:cmp al,'9'ja is_alphabetadd al,52-'0'jmp rotate_eaxis_alphabet:sub al,'A'cmp al,25jbe rotate_eaxsub al,6rotate_eax:rol eax,8loop eax_b64_2_orgretb64.dcode.size=$-base64_dec.end StArT