1.data段
data db "hello,sam"
key db "key"
dataLen dword ?
endata byte 10 dup(0)
dedata byte 10 dup(0)
2.Encryption(加密)
Encryption procpush ebpmov ebp,esp;加密数据长度,循环次数mov ecx,sizeof data;寄存器不够用 sub esp,4mov dword ptr [ebp-4],sizeof key mov dataLen,0
la:mov eax,dataLenmov ebx,dword ptr [ebp-4]cdqidiv ebxmov bl,byte ptr key[edx]mov edx,dataLenmov al,byte ptr data[edx]not alxor al,blmov byte ptr endata[edx],alinc dataLenloop lamov esp,ebppop ebpret
Encryption endp
3.Decryption (解密)
Decryption procpush ebpmov ebp,espmov ecx,dataLenmov dataLen,0sub esp,4mov dword ptr [ebp-4],sizeof key
la:mov eax,dataLenmov ebx,dword ptr [ebp-4]cdqidiv ebxmov bl,byte ptr key[edx]mov edx,dataLenmov al,byte ptr endata[edx]xor al,blnot almov byte ptr dedata[edx],alinc dataLenloop lamov esp,ebppop ebpret
Decryption endp