Hi Guys,

Picking up asm again, so I hope some off you can tell me this is ok, tips etc welcome. Works nice if the pw is the same lenght as the input it is a OTP!

Use it as it fits (public domain)


Code:
#COMPILE EXE
#DIM ALL
declare Function AvXorKey(EnDeCod AS STRING, Pword AS STRING) as long

FUNCTION PBMAIN () AS LONG

  local EnDeCod$
  local Pword$

  EnDeCod$ = "Power To The PowerBasic Forums"
  Pword$ = "123456"

  AvXorKey(EnDeCod$, Pword$)
  msgbox EnDeCod$
  ' and again to get original back (we hope :-)
  AvXorKey(EnDeCod$, Pword$)
  msgbox EnDeCod$

END FUNCTION

Function AvXorKey(EnDeCod AS STRING, Pword AS STRING) as long
   #REGISTER NONE
   Local Elen, Plen, Ecod, Pwrd AS LONG

   Elen = LEN(EnDeCod)
   Plen = LEN(Pword)

   Ecod = STRPTR(EnDeCod$)                ' source
   Pwrd = STRPTR(Pword$)                 ' key

   ! mov esi, Ecod                     ; address of EnDeCod STRING
   ! mov eax, esi                      ; put [si] in ax
   ! add eax, Elen                     ; add ax string-len from EnDeCod
   ! mov ecx, eax                      ; set result in cx for exit condition
   ! xor eax, eax                      ; clear ax

   ! mov edi, Pwrd                     ; address of Pword  STRING
   ! mov eDx, Plen                     ; put string-len from Pword in dx

   coder:
   ! mov al, [esi]                     ; GET BYTE FROM Ecod  IN al
   ! mov bl, [edi]                     ; GET BYTE FROM Pword IN bl

   ! xor al, bl                       ; xor them (encode)
   ! mov BYTE PTR [esi], al              ; write encoded byte back to EnDeCod$

   ! inc esi                          ; point to  NEXT BYTE
   ! cmp esi, ecx                      ; test EXIT condition
   ! jZ  done

   ! dec edx
   ! jz  pwloop

   ! inc edi                          ; increase counters
   ! jmp coder

   pwloop:
   ! mov edi,Pwrd
   ! mov edx,Plen
   ! jmp coder
   done:


FunCTION = 1
END FUNCTION