News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Name encode with custom charset

Started by r0ger, January 31, 2022, 04:17:10 AM

Previous topic - Next topic

r0ger

hi guys,

does anyone know how do i rewrite this in masm32 ? i have a snippet where i need to encrypt a string with a custom charset.
1st charset : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
2nd charset : DEFACzIJGHy01KS34VYZabcPQRjklmTo8pqrWXstuvLwdeBfghiMNOx256Un79

e.g.: r0ger^PRF ----> wN8Tw^3Vz

function Encrypt(Name, Str1, Str2 : string):string;
var
  Str : string;
  i, StrPos, len : integer;
begin
  len :=  length(name);
      for I := 1 to len do
        begin
         StrPos := pos(Name[i], Str1);
         if (StrPos = 0) then
          begin
            Str := Str + Name[i];
          end else
          begin
            Str := Str + Str2[StrPos];
          end;
        end;
  Result := str;
end;
r0ger // PRF

avcaballero

Missed "^" char?

.386
.MODEL     flat, stdcall
OPTION     casemap :none
         
INCLUDE    windows.inc
INCLUDE    kernel32.inc
INCLUDE    masm32.inc
         
INCLUDELIB kernel32.lib
INCLUDELIB masm32.lib
         
.DATA
  charset01   db "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789^", 0
  charset02   db "DEFACzIJGHy01KS34VYZabcPQRjklmTo8pqrWXstuvLwdeBfghiMNOx256Un79^", 0
  txtorg      db "r0ger^PRF", 0
  crlf        db 13, 10, 0
  txttgt      db 20 dup(0)

.CODE
Encode proc ptxtOrg:dword, ptxttgt:dword, pchar1:dword, pchar2:dword
  mov      esi, [ptxtOrg]
  mov      edx, [pchar1]    ; charset01
  mov      ebx, [ptxttgt]    ; txttgt
  @Bucle:
    mov      al, byte ptr [esi]
    cmp      al, 0
    jz       @Fin
    mov      edi, edx
    repnz    scasb
    jne      @Fin      ; No encontrado
      push     ebx
      mov      eax, edi
      sub      eax, edx
      dec      eax
      mov      ebx, [pchar2]
      mov      al, byte ptr [ebx+eax]
      pop      ebx
      mov      byte ptr [ebx], al
      inc      ebx
      inc      esi
  jmp      @Bucle
  @Fin:
  ret
Encode endp

start:
  INVOKE     StdOut, offset txtorg
  INVOKE     StdOut, offset crlf
  invoke     Encode, offset txtorg, offset txttgt, offset charset01, offset charset02
  INVOKE     StdOut, offset txttgt
  INVOKE     ExitProcess, 0

END start

r0ger

thanks so much caballero, it works. ;)
r0ger // PRF