flat assembler
Message board for the users of flat assembler.

 Index > Examples and Tutorials > ultimate xor use
Author
Ali.Z

Joined: 08 Jan 2018
Posts: 233
Ali.Z
Code:
; standard and basic xor encryption
BASE = 2525h

_xor:
mov edx,BASE
xor edx,25h ; just any number to encrypt
; result is 2500h
; now to retrieve the encrypted number back
; xor base by result
xor edx,BASE ; remember edx have 2500h from last xor operation
; now edx have the original number which is 25h

Code:
; another use of xor i dont know what to call it but it can be useful to store qword values and write them later to memory location
LOW_QWORD = 0ABCDEF10h
HIGH_QWORD = 23456789h
; FULL_QWORD = 23456789ABCDEF10h

_label:
mov edx,LOW_QWORD ; store the low 32bit value
xor edx,HIGH_QWORD ; we need the result
; result is 88888899h ; the KEY
mov eax,88888899h ; store it in eax for later use

; now to get the HIGH_QWORD, xor KEY by LOW_QWORD
xor edx,LOW_QWORD ; remember edx have 88888899h and being xored by ABCDEF10 which is low qword
; the result is 23456789h = high qword

; to get the LOW_QWORD xor KEY by the HIGH_QWORD
xor edx,eax ; = eax is our key 88888899h, edx = high qword
; result is 0ABCDEF10 = low qword

_________________
Asm For Wise Humans
26 Jul 2018, 16:45
MacroZ

Joined: 12 Oct 2018
Posts: 30
MacroZ
It can be used to flip bits
Code:
xor al,1 ; Flips the first bit

Can we get another unique xor usage/trick by the next person? We want this thread to grow larger with unique answers. Forum users are encouraged to participate!

_________________
The king auto-generates two things to degrade dangerous artists and intellectuals. The King reserves the right to be king and has made the culprits in advance. Half of the time or more, they are auto-generated.
20 Oct 2018, 18:49
HaHaAnonymous

Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
MacroZ wrote:
It can be used to flip bits...

This is true. Nice find!
Code:
mov eax,1011b
; eax now is 1011b
xor eax,1000b
; eax now is 0011b
xor eax,1000b
; eax now is 1011b
xor eax,0001b
; eax now is 1010b
ret

Thank you!
20 Dec 2018, 12:03
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum