Encryption-Decryption using -XOR operator
This C program demonstrates basic example on encryption and decryption of data using "exclusive OR operator" -XOR . You can use it to secure your data and other security stuff. The C example has been explained with comments and input/output screenshots.
You can compile this program on bOtskOOl Free Online C/C++ Compiler
//Encryption-Decryption
#include <iostream.h>
using namespace std;
//declare funtion encrypt_decrypt that takes used data and the key
unsigned int encrypt_decrypt(unsigned int value,unsigned int key);
//main funtion
int main()
{ unsigned int user_data,user_key,user_en;
cout<<"Enter data for encryption or decryption : "<<endl;
cin>>user_data;
cout<<user_data;
cout<<"\nEnter a key value for encryption or decryption: "<<endl;
cin>>user_key;
cout<<user_key;
//funtion call: Pass user data and key into function for encryption or decryption
user_en=encrypt_decrypt(user_data,user_key);
cout<<"\n Your data has been encrypted or decrypted and its value is : "<<endl;
cout <<user_en<< endl;
}
//funtion details
unsigned int encrypt_decrypt(unsigned int value,unsigned int key) {
//perform bitwise XOR data and key, then return the value when function is called
return (value^key);
}
Output:
Data-encryption

Data-decryption using same key

The above OUTPUT was generated by bOtskOOl Online Compiler try>>
Terms of Agreement:
>>Kindly post your doubts and suggestions on our discussion forum.




Recent comments
11 weeks 10 hours ago
1 year 8 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 12 weeks ago
1 year 13 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago
1 year 18 weeks ago
1 year 18 weeks ago