The MASM Forum

General => The Campus => Topic started by: DangerZone on May 07, 2015, 05:52:12 PM

Title: Assembly XOR and WRITE TXT
Post by: DangerZone on May 07, 2015, 05:52:12 PM
Hello everyone
I have a question

http://stackoverflow.com/questions/157273836/ (http://stackoverflow.com/questions/57273836)
Title: Re: Assembly XOR and WRITE TXT
Post by: jj2007 on May 07, 2015, 06:49:13 PM
Hello. What you want to do looks trivial, but why do you want to treat quotes differently?

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  mov ecx, CL$()
  .if byte ptr [ecx]=="?"
      MsgBox 0, "You forgot the commandline", "Hi", MB_OK
  .else
      Let esi=FileRead$(ecx)
      push esi
      .While 1
            lodsb
            .Break .if !al
            xor al, 184
            mov [esi-1], al
      .Endw
      pop esi
      FileWrite "Xor184.txt", esi
      Print "bye"
  .endif
  Exit
end start
Title: Re: Assembly XOR and WRITE TXT
Post by: DangerZone on May 07, 2015, 06:58:44 PM
I want to make symmetric encryption.

Key value: 180
a.txt = Hello

1)Read a.txt
2)H ASCII => 72
3)72 XOR 184 => ASCII
4)Write cryptic.txt
5)e ASCII => 101
6)101 XOR 184 => ASCII
7)Write cryptic.txt
Title: Re: Assembly XOR and WRITE TXT
Post by: jj2007 on May 07, 2015, 07:10:45 PM
Quote from: DangerZone on May 07, 2015, 06:58:44 PM
I want to make symmetric encryption.

Yes I know, that's what the proggie attached above does. But why special treatment for "quotes"?
Title: Re: Assembly XOR and WRITE TXT
Post by: DangerZone on May 07, 2015, 07:39:47 PM
Quote from: jj2007 on May 07, 2015, 06:49:13 PM
Hello. What you want to do looks trivial, but why do you want to treat quotes differently?

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  mov ecx, CL$()
  .if byte ptr [ecx]=="?"


Your program crashes.
Title: Re: Assembly XOR and WRITE TXT
Post by: jj2007 on May 07, 2015, 08:00:28 PM
Quote from: DangerZone on May 07, 2015, 07:39:47 PM
Your program crashes.

How (exception, error message, ...)?
Did you provide a valid commandline?
Title: Re: Assembly XOR and WRITE TXT
Post by: DangerZone on May 07, 2015, 08:09:51 PM
ok
Title: Re: Assembly XOR and WRITE TXT
Post by: jj2007 on May 07, 2015, 09:22:41 PM
OK, I see. Use Let instead of mov:

  Init
  Let ecx=CL$()


And remember the proggie needs to know which input file. Drag your input_whatever.txt over the xor.exe, and even the old version will work.
Title: Re: Assembly XOR and WRITE TXT
Post by: DangerZone on May 07, 2015, 09:29:02 PM
it was
thanks
Title: Re: Assembly XOR and WRITE TXT
Post by: dedndave on May 07, 2015, 10:59:51 PM
get the file size (GetFileAttributesEx)
allocate a buffer (GetProcessHeap, HeapAlloc)
read the input file into the buffer (CreateFile, ReadFile, CloseHandle)
XOR the buffer - you can speed it up by XOR'ing 4 bytes at a time, except perhaps the last few bytes
write the buffer to the output file (CreateFile, WriteFile, CloseHandle)
free the buffer (HeapFree)
exit (ExitProcess)