The ciphertext is almost identical to the message:
Code:
#include <iostream>
#include <string>
using namespace std;
#define DEBUG
char* shift(char* k) {
// return an (odd) permutation of `k'
int sz = sizeof(k)/sizeof(char);
for(int i = 0; i < sz; i++) {
char t = k[i];
k[i] = k[i+1];
k[i+1] = t;
}
return k;
}
char* forward(char* m, char* k) {
// forward cipher (encryption)
int sz_m = sizeof(m)/sizeof(char);
while(*m++ ^= *k) {
k = shift(k); // algorithm (symmetric difference)
#ifdef DEBUG
cout << k << '\n';
#endif
}
return m;
}
int main(int argc, char* argv[]) {
char** args = argv;
char* mess;
char* key;
switch(argc) {
case 3:
mess = args[1];
key = args[2];
break;
default:
cout <<"usage: encrypt message key\n";
return 1;
}
cout << "Encrypted message is: \n"
<<"\n\t" << forward(mess, key) << '\n';
return 0;
}
The `shift' function is supposed to rotate through each character in the key, so that a (somewhat) different comparison is done for as many characters as the unencrypted message contains. But the output points to a problem:
Code:
oops% encrypt bell-labs message
Encrypted message is:
ll-labs
Any ideas? Great help on past issues--thanks.