BITXOR


Finds the bitwise ‘XOR’ value of two numbers and returns it.

Syntax:

BITXOR(numberOne, numberTwo)


numberOne and numberTwo should be 0 or higher.


Example:

If numberOne contains 1 and numberTwo contains 2:

BITXOR(1, 2)

returns 3


numberOne:


numberTwo:


Result:

3

Application:

Simple Data Obfuscation


Imagine you have a small, sensitive piece of data, such as a user's ID, that you want to store in a way that isn't immediately readable to someone who might accidentally view the database. You can use a bitwise XOR operation with a fixed "key" to scramble the data. The beauty of the XOR operation is that applying it a second time with the same key will unscramble the data back to its original form.


The Key: Let's use the number 10 as our key. In binary, 10 is 1010.


The Data: Let's say we have a user ID of 5. In binary, 5 is 0101.



Step 1: Obfuscation (Scrambling the Data)


We apply the BITXOR function to the data and the key.


BITXOR(Data, Key) -> BITXOR(5, 10)


Let's do the math in binary:


  • Data (5): 0101
  • Key (10): 1010
  • Result: 1111


The bitwise XOR operation works like this:


  • 0 XOR 0 = 0
  • 0 XOR 1 = 1
  • 1 XOR 0 = 1
  • 1 XOR 1 = 0

Bit Position

Data (5)

Key (10)

Result (XOR)

A
B
C
D
1
1's place
1
0
1
2
2's place
0
1
1
3
4's place
1
0
1
4
8's place
0
1
1

The resulting binary 1111 is the decimal number 15. This is the scrambled value that would be stored in the database.



Step 2: De-obfuscation (Unscrambling the Data)


When the application needs to retrieve the original user ID, it performs the exact same operation with the same key.


BITXOR(Scrambled_Data, Key) -> BITXOR(15, 10)


Let's do the math in binary again:


  • Scrambled Data (15): 1111
  • Key (10): 1010
  • Result: 0101

Bit Position

Scrambled Data (15)

Key (10)

Result (XOR)

A
B
C
D
1
1's place
1
0
1
2
2's place
1
1
0
3
4's place
1
0
1
4
8's place
1
1
0

The resulting binary 0101 is the decimal number 5, which is our original user ID.


This simple example demonstrates how the BITXOR function can be used for a reversible, lightweight data transformation, making it a useful tool for basic data security and integrity tasks.





This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof