I was playing around a day or two ago with an xor encryption..... I had a small need to a faster way of doing it, so I went to an asm dll.

I didn't paste everything here, only whats needed. Can you make it better?


Code:
      SAFEARRAYBOUND struct
            cElements	      	DWORD	?	      	  ; Number of Elements
            lLbound		      DWORD	?		        ; Lower Boundary
      SAFEARRAYBOUND ends

      OLE_SAFEARRAY struct
	      cDims		            WORD	?		        ; Number of dimensions
	      fFeatures	      	WORD	?		        ; Bitfield indicating attributes
	      cbElements	      	DWORD	?		        ; size of an element of the array
   	      cLocks		      DWORD	?		        ; lock counter 0=Locked
	      pvData		      DWORD	?		        ; Pointer to data
	      rgsabound	            SAFEARRAYBOUND	<>	  ; Contains info for dimensions
      OLE_SAFEARRAY ends

Code:
xorbytes proc msg:DWORD, key:DWORD
    push ebx
    push esi
    push edi
    push ebp
    
    mov eax, msg
    mov ebx, key
    movd MM0, esp
    
    mov edx, [eax]
    mov ecx, [ebx]
    
    mov ebp, (OLE_SAFEARRAY ptr [edx]).rgsabound.cElements
    mov ebx, (OLE_SAFEARRAY ptr [ecx]).rgsabound.cElements
    mov edi, (OLE_SAFEARRAY ptr [edx]).pvData
    mov esi, (OLE_SAFEARRAY ptr [ecx]).pvData

    cmp ebp, 0
    je done

    cmp ebx, 0
    je done

    xor ecx, ecx

    mov esp, esi
    add esp, ebx

    jmp For_Loop

    SetKeyBack:
        sub esi, ebx
        jmp lblCon

    align 16
    For_Loop:
        cmp esi, esp
        je SetKeyBack

        lblCon:

        mov al, [esi]
        xor byte ptr [edi], al

        add edi, 1
        add esi, 1
        add ecx, 1
    cmp ecx, ebp
    jne For_Loop

done:
    movd esp, MM0
    pop ebp
    pop edi
    pop esi
    pop ebx
    ret
xorbytes endp