//this is with comments and an exit of the programm if no message is entered

// lab 2 session 5
// september 11th, 2001
// by katie williams and jochen balbach

//test: print out the ascii code for each symbol of the encrypted message

//exrtra credit: input a string whitch is used as the mask!!!!!!
//both is included in this programm

#include <iostream>
#include <string>

int main(){
	string pw = "";
	string code , read;


	char alpha, beta, xor;
	int inputLength, pwLength;
//input
	cout <<endl << "\n your password, please: " <<endl;
	getline(cin, pw);

	//default password
	if(pw=="")pw="swordfish";
	
	cout << "\n please enter a message" <<endl <<endl;
	getline(cin, read);
	
	//exit if no message is entered
	if(read==""){
		cout << "no message entered, leave programm!!" <<endl;
		exit (0);

		
	}
//end input

	inputLength=read.length();
	pwLength=pw.length();

	int asciiCode[inputLength];


	//concatenation of pw as long as it is shorter than the input string
	while(pwLength<inputLength){
		pw +=pw;
		pwLength=pw.length();
	}

	for(int i=0;i<inputLength;i++){
		alpha=pw[i];
		beta=read[i];
		
		xor=(alpha^beta);
	
		code[i]= (int)xor;
		asciiCode[i]=xor;
		
		// outpur was only for test reasons!!
		//cout <<alpha << " " << beta << " - " <<xor << "    ";
	
	}

	
	cout << endl <<"you entered: " <<endl << read <<endl <<endl
		<<"Ascii Code of the encrypted input:" <<endl;

	for(int z=0;z<inputLength;z++){
		cout << asciiCode[z] <<" ";
	}
	
	cout <<endl;

	//cout << "Code: " <<code <<"\t ende code "<<endl;
	// through the output above it happens sometimes that the console gets
characters
	// which it can not display

	//end
	return 1;
}


