XOR Cipher | C ++ program to implement XOR - Encryption ; The same function is used to encrypt and decrypt ; Define XOR key Any character value will work ; calculate length of input string ; perform XOR operation of key with every character in string ; Driver program to test above function ; Encrypt the string ; Decrypt the string
#include <bits/stdc++.h> NEW_LINE void encryptDecrypt ( char inpString [ ] ) { char xorKey = ' P ' ; int len = strlen ( inpString ) ; for ( int i = 0 ; i < len ; i ++ ) { inpString [ i ] = inpString [ i ] ^ xorKey ; printf ( " % c " , inpString [ i ] ) ; } } int main ( ) { char sampleString [ ] = " GeeksforGeeks " ; printf ( " Encrypted ▁ String : ▁ " ) ; encryptDecrypt ( sampleString ) ; printf ( " STRNEWLINE " ) ; printf ( " Decrypted ▁ String : ▁ " ) ; encryptDecrypt ( sampleString ) ; return 0 ; }