XOR Cipher in C++

C++Server Side ProgrammingProgramming

XOR cipher or XOR encryption is a data encryption method that cannot be cracked by brute-force method.

Brute-force method is a method of random encryption key generation and matching them with the correct one.

To implement this encryption method, we will define an encryption key(random character) and perform XOR of all characters of the string with the encryption key. This will encrypt all characters of the string.

Program to show the implementation of encryption −

Example

 Live Demo

#include<iostream>
#include<string.h>
using namespace std;
void XORChiper(char orignalString[]) {
   char xorKey = 'T';
   int len = strlen(orignalString);
   for (int i = 0; i < len; i++){
      orignalString[i] = orignalString[i] ^ xorKey;
      cout<<orignalString[i];
   }
}
int main(){
   char sampleString[] = "Hello!";
   cout<<"The string is: "<<sampleString<<endl;
   cout<<"Encrypted String: ";
   XORChiper(sampleString);
   return 0;
}

Output

The string is: Hello!
Encrypted String: 188;u
raja
Published on 17-Apr-2020 12:25:54
Advertisements