
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
XOR Cipher in C++
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
#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
Advertisements