Answer to Question #265128 in C++ for acky_1

Question #265128

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.


1
Expert's answer
2021-11-12T17:32:51-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS