Skip to content
← Back to Community
Binary Encryption and Decryption
Profile icon
KyraFulford

Binary Encryption and Decryption

Data on a computer is stored in binary form, in the form of bytes (8 bits of 1's or 0's). As an example, binary data can easily be "encrypted" with a "key" based on a little Boolean operation called an xor, or exclusive or.

When we xor a single bit (a 1 or 0) with another bit:

if 1 bit is true and 1 bit is false, it returns true, otherwise it returns false; so:

1 xor 1 = 0
1 xor 0 = 1
0 xor 1 = 1
0 xor 0 = 0

And now, one reason this is useful is because if we take the new bit and xor it with the same key (the second bit) the result will always be the first bit. So:

0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0
0 xor 0 = 0

Now using the above, demonstrate encryption and decryption by writing a program in C++ (or language of your choice).

1- Use the keyboard to input Key and Plaintexts binary values, encrypt them and output Key, Plaintext and the Ciphertext.

2- Decrypt the Ciphertext to Plaintext and out values.

Voters
Profile icon
DominicCastro
Profile icon
Kai_Justice
Profile icon
KyraFulford