AuthorMessage
Lord_Zero
Ametuar
Posts: 122

The following procedure calculates Lock2Key, srcbuf has a $Lock string, destbuf will contain calculated $Key string (masm32).
Code:
Lock2key PROC uses edi esi ebx srcbuf:DWORD,destbuf:DWORD
   mov   esi,srcbuf
   mov   edi,destbuf
   mov   eax,'yeK$'
   stosd
   mov   al,32
   stosb
   lea   esi,[esi+6]
   xor   ecx,ecx
   .while (byte ptr[esi+ecx]!='|')
      .if (dword ptr[esi+ecx]=='=kP ')
         .break
      .endif
      inc   ecx
   .endw
   .if ecx<3
      ret
   .endif
   mov   al,[esi]
   xor   al,5
   mov   ah,al
   shr   ax,4
   and   ax,0ff0h
   or   al,ah
   mov   [edi],al
   xor   edx,edx
   inc   edx
   .while edx<ecx
      mov   al,[esi+edx]
      xor   al,[esi+edx-1]
      mov   ah,al
      shr   ax,4
      and   ax,0ff0h
      or   al,ah
      mov   [edi+edx],al
      inc   edx
   .endw
   mov   al,[edi]
   xor   al,[edi+ecx-1]
   mov   [edi],al
   xor   edx,edx
   .while edx<ecx
      mov   al,[edi+edx]
      mov   [esi+edx],al
      inc   edx
   .endw
   xor   edx,edx
   .while edx<ecx
      lodsb
      .if al==0
         mov   eax,'CD%/'
         stosd
         mov   eax,'000N'
         stosd
         mov   ax,'/%'
         stosw
      .elseif al==5
         mov   eax,'CD%/'
         stosd
         mov   eax,'500N'
         stosd
         mov   ax,'/%'
         stosw
      .elseif al==36
         mov   eax,'CD%/'
         stosd
         mov   eax,'630N'
         stosd
         mov   ax,'/%'
         stosw
      .elseif al==96
         mov   eax,'CD%/'
         stosd
         mov   eax,'690N'
         stosd
         mov   ax,'/%'
         stosw
      .elseif al==124
         mov   eax,'CD%/'
         stosd
         mov   eax,'421N'
         stosd
         mov   ax,'/%'
         stosw
      .elseif al==126
         mov   eax,'CD%/'
         stosd
         mov   eax,'621N'
         stosd
         mov   ax,'/%'
         stosw
      .else
         stosb
      .endif
      inc   edx
   .endw
   ret
Lock2Key ENDP