Use XOR to encode and ecode a message : XOR « Operators statements « C++ Tutorial






#include <iostream> 
using namespace std; 
 
int main() 
{ 
  char msg[] = "This is a test"; 
  char key = 123; 
 
  cout << "Original message: " << msg << "\n"; 
 
  for(int i = 0 ; i < strlen(msg); i++)  
    msg[i] = msg[i] ^ key; 
 
  cout << "Encoded message: " << msg << "\n"; 
 
  for(int i = 0 ; i < strlen(msg); i++)  
    msg[i] = msg[i] ^ key; 
 
  cout << "Decoded message: " << msg << "\n"; 
 
  return 0; 
}
Original message: This is a test
Encoded message: /[[?[¤¤
Decoded message: This is a test








3.12.XOR
3.12.1.Demonstrate bitwise exclusive OR
3.12.2.Use XOR to encode and ecode a message