0% found this document useful (0 votes)
78 views2 pages

XOR Encryption Class Activity-1

XOR encryption is a common and simple encryption method that operates by applying the XOR logical operation between each character of a message and a shared key. It can encrypt data stored locally, like game saves, to deter tampering. While not very secure, it is commonly used as part of more complex encryption algorithms. XOR encryption works by applying the logical XOR between corresponding bits of the message and key, such that a bit is 0 if the message and key bits are the same and 1 if they are different.

Uploaded by

Nurdin Yussuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views2 pages

XOR Encryption Class Activity-1

XOR encryption is a common and simple encryption method that operates by applying the XOR logical operation between each character of a message and a shared key. It can encrypt data stored locally, like game saves, to deter tampering. While not very secure, it is commonly used as part of more complex encryption algorithms. XOR encryption works by applying the logical XOR between corresponding bits of the message and key, such that a bit is 0 if the message and key bits are the same and 1 if they are different.

Uploaded by

Nurdin Yussuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

XOR encryption

XOR encryption (or Exclusive-OR encryption) is a common method of encrypting text into a format that
cannot be trivially cracked by the average person. XOR encryption is great for storing things like game
save data, and other data types that are stored locally on a users computer, that while not a big deal if
they are tampered with, you would like to deter people from doing so. XOR encryption is also used often
as a part of more complex encryption algorithms

In cryptography, the simple XOR cipher is a type of additive cipher[1]an encryption algorithm
that operates according to the principles:

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

01101001 in 8-bit ASCII) can be encrypted with the repeating key 11110011 as follows:

01010111 01101001 01101011 01101001


11110011 11110011 11110011 11110011
= 10100100 10011010 10011000 10011010

And conversely, for decryption:

10100100 10011010 10011000 10011010


11110011 11110011 11110011 11110011
= 01010111 01101001 01101011 01101001

#include <iostream>

using namespace std;

string encryptDecrypt(string toEncrypt) {


char key = 'K'; //Any char will work
string output = toEncrypt;

for (int i = 0; i < toEncrypt.size(); i++)


output[i] = toEncrypt[i] ^ key;

return output;
}

int main(int argc, const char * argv[])


{
string encrypted = encryptDecrypt("kylewbanks.com");
cout << "Encrypted:" << encrypted << "\n";

string decrypted = encryptDecrypt(encrypted);


cout << "Decrypted:" << decrypted << "\n";

return 0;
}

Class Activity 1: Re-write above program to allow users to input string variable

You might also like