Question
Please use C++ #include #include using namespace std; //xor operator ^: Hash code applied twice regenerates the original value: m is message character and h
Please use C++
#include
using namespace std;
//xor operator ^: Hash code applied twice regenerates the original value: m is message character and h is hash // x=m^h and y=x^h then y (decoded message) is the same as m
void coder(char *x, char key,int length); char *getMessage(char *request);
int main() { char *m = getMessage("Enter message to encode: "); int length = strlen(m); cout << length << endl; //char *k = getMessage("Enter key ");//read in a key of arbitrary length coder(m, 'A', length);//A is the key. Encode message with key string cout << m << endl; coder(m, 'A', length);//Decode message. Decode message with key string cout << m << endl; delete(m); //no leaks // delete(k); return 0; }
void coder(char *message, char key, int length)//make key an array { for (int i = 0; i < length; i++) message[i] = message[i]^key;//cycle through the key }
char *getMessage(char *request) { char temp[100], *p; cout << request << " "; cin >> temp; p = new char(strlen(temp)+1);//+1 for terminating null strcpy(p, temp); return p; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started