• [src]RC4

 #86797  por YST
 26 Jun 2009, 10:44
Código: [ Debe registrarse para ver este enlace ]
include 'win32ax.inc'
.data
cBuffer db 'Hola',0
cClave db 'Hola',0
s db 257 dup(0)
 
.code
start:
stdcall Len,cClave
mov ebx,eax
stdcall Len,cBuffer
stdcall RC4,cBuffer,cClave,eax,ebx
invoke MessageBox,0,cBuffer,0,0
invoke ExitProcess,0
proc RC4,pBuffer,pPassword,pTamñoBuffer,pTamPass
pushad
dec [pTamñoBuffer]
;   For i = 0 To 255
 ; DoEvents
 ; s(i) = i
 ;   Next i
 mov eax,s
mov byte[eax],0
inc eax
mov ecx,256
.bucle1_:
mov bl,byte[eax-1]
inc bl
mov  byte[eax] ,bl
inc eax
loop .bucle1_
 
;    For i = 0 To 255
;        DoEvents
;        j = (j + s(i) + Key(i Mod Len(sKey))) Mod 256
;        tmp = s(i)
;        s(i) = s(j)
;        s(j) = tmp
;    Next i
;j = ebx
;ja = esi
;I = edi
xor ebx,ebx
mov edi,-1
.bucle2_:
inc edi
xor esi,esi
mov esi,ebx
movzx eax,byte[s+edi]
add esi,eax
stdcall lMod,edi,[pTamPass]
mov ecx,[pPassword]
movzx eax,byte[ecx+eax]
add esi,eax
stdcall lMod,esi,256
mov ebx, eax
mov eax,s
mov cl,byte[eax+ebx] ; s(j)
mov ch,byte[eax+edi] ; s(i)
mov byte[eax+edi],cl
mov byte[eax+ebx],ch
cmp edi,255
jne .bucle2_
inc edi
 
 
 ;   For l = 0 To UBound(Buffer)
 ;       DoEvents
 ;       i = (i + 1) Mod 256
 ;       j = (j + s(i)) Mod 256
 ;       tmp = s(i)
 ;       s(i) = s(j)
 ;       s(j) = tmp
 ;       Buffer(l) = Buffer(l) Xor (s((s(i) + s(j)) Mod 256))
 ;   Next l
xor esi,esi  ;esi = l
dec esi ; esi = -1
.bucle3_:
inc esi
mov eax,edi
inc eax
stdcall lMod,eax,256
mov edi,eax
mov eax,ebx
xor ecx,ecx
movzx ecx,byte[s+edi]
add eax,ecx
stdcall lMod,eax,256
mov ebx,eax
mov eax,s
mov cl,byte[eax+ebx] ; s(j)
mov ch,byte[eax+edi] ; s(i)
mov byte[eax+edi],cl
mov byte[eax+ebx],ch
mov eax,[pBuffer]
add cl,ch
movzx eax,cl
add eax,s
movzx eax,byte[eax]
stdcall lMod,eax,256
 
mov edx,[pBuffer]
xor byte[edx+esi],al
 
cmp esi,[pTamñoBuffer]
jne .bucle3_
popad
ret
endp
invoke ExitProcess,0
proc lMod,c1,c2
push edx
xor edx,edx
mov eax,[c1]
idiv [c2]
push edx
pop eax
pop edx
ret
endp
 
proc Len,cCadena   ;Funcion que mide la cadena
push ecx edi
mov ecx,-1
mov edi,[cCadena]
mov al,0
repnz scasb
mov eax,ecx
not eax
dec eax
pop edi ecx
ret
endp
.end start
 #95330  por tercer_ojo
 23 Jul 2009, 06:00
Muy útil. Gracias
 #98162  por bloodday
 04 Ago 2009, 03:29
te lo compro... sera bien utilizado

saludos