Write a C++ program to perform 128-bit encryption and decryption using XOR operation.
Your program must ask for 128-bit key and plain text then perform encryption and decryption.
#include<bits/stdc++.h>
void encrypt_decrypt(int k, char str[])
{
int n = strlen(str);
for (int i = 0; i < n; i++)
{
str[i] = str[i] ^ k;
printf("%c",str[i]);
}
}
int main()
{
int k;
printf("\nEnter 128-bit key: ");
scanf("%d",&k);
char str[] = "Hello";
printf("Encrypted String: ");
encrypt_decrypt(k,str);
printf("\n");
printf("Decrypted String: ");
encrypt_decrypt(k,str);
return 0;
}
Comments
Leave a comment