
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- Polybius Square Cipher in C++
- Chalkboard XOR Game in C++
- Find XOR of two number without using XOR operator in C++
- C++ Program to Implement Affine Cipher
- Difference between Block Cipher and Stream Cipher
- Difference between Monoalphabetic Cipher and Polyalphabetic Cipher
- What is Bitwise XOR in C++?
- Minimum XOR Value Pair in C++
- XOR of a subarray in C++
- Equal Sum and XOR in C++
- Maximum XOR value in matrix in C++
- Atbash cipher in Python
- Caesar Cipher in Python
- Bifid Cipher in Cryptography
- Caesar Cipher in Cryptography

Advertisements