News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Assembly XOR and WRITE TXT

Started by DangerZone, May 07, 2015, 05:52:12 PM

Previous topic - Next topic

DangerZone

Hello everyone
I have a question

http://stackoverflow.com/questions/157273836/

jj2007

Hello. What you want to do looks trivial, but why do you want to treat quotes differently?

include \masm32\MasmBasic\MasmBasic.inc      ; download
  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

DangerZone

#2
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

jj2007

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"?

DangerZone

#4
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
  Init
  mov ecx, CL$()
  .if byte ptr [ecx]=="?"


Your program crashes.

jj2007

Quote from: DangerZone on May 07, 2015, 07:39:47 PM
Your program crashes.

How (exception, error message, ...)?
Did you provide a valid commandline?

DangerZone

#6
ok

jj2007

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.

DangerZone

#8
it was
thanks

dedndave

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)