Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Implementation of XOR cipher algorithm. More...
#include <iostream>
#include <string>
#include <cassert>
Namespaces | |
namespace | ciphers |
Algorithms for encryption and decryption. | |
namespace | XOR |
Functions for XOR cipher algorithm. | |
Functions | |
std::string | ciphers::XOR::encrypt (const std::string &text, const int &key) |
std::string | ciphers::XOR::decrypt (const std::string &text, const int &key) |
void | test () |
int | main () |
Implementation of XOR cipher algorithm.
In cryptography, the simple XOR cipher is a type of additive cipher, an encryption algorithm that operates according to the principles:
where \(\oplus\) symbol denotes the exclusive disjunction (XOR) operation. This operation is sometimes called modulus 2 addition (or subtraction, which is identical). With this logic, a string of text can be encrypted by applying the bitwise XOR operator to every character using a given key. To decrypt the output, merely reapplying the XOR function with the key will remove the cipher.
Choose the key for encryption and apply XOR operation to each character of a string. Reapplying XOR operation to each character of encrypted string will give original string back.
std::string ciphers::XOR::decrypt | ( | const std::string & | text, |
const int & | key ) |
Decrypt given text using XOR cipher.
text | text to be encrypted |
key | to be used for decryption |
std::string ciphers::XOR::encrypt | ( | const std::string & | text, |
const int & | key ) |
Encrypt given text using XOR cipher.
text | text to be encrypted |
key | to be used for encyption |
int main | ( | void | ) |
void test | ( | ) |
Function to test above algorithm