#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//global varibals:
char entered_characters[9999];
int direction_of_rotor1;
int direction_of_rotor2;
char alphabet_of_rotor1[26];
char alphabet_of_rotor2[26];
char rotor1_backward(char Letter);
char rotor1_forward(char Letter);
char rotor2_backward(char Letter2);
char rotor2_forward(char Letter2);
char print(char print_char);
int main()
{
cout << "This is enigma machine:" << endl;
cout << "*NOTE:This programe accepts only lower case letters" << endl;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Enter letters for the first rotor:" << endl;
cin >> alphabet_of_rotor1;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Enter letters for the second rotor:" << endl;
cin >> alphabet_of_rotor2;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Chose direction of rotor 1:" << endl;
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;
cin >> direction_of_rotor1;
cout<<"--------------------------------------------------------------"<<endl;
int going_through_entered_characters_array=-1;
cout << "Enter letter to encode:" << endl;
cin >> entered_characters;
//***i need to return to here and not to the beginning of main function***
char Letter;
going_through_entered_characters_array++;
Letter = entered_characters[going_through_entered_characters_array];
if(entered_characters[going_through_entered_characters_array] != '\0')
{
switch(direction_of_rotor1)
{
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor1_backward(Letter);
break;
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor1_forward(Letter);
break;
default:
cout<<"--------------------------------------------------------------"<<endl;
cout << "Wrong choice" <<endl;
break;
}
}
else
{
cout << "\nend of program...";
system("PAUSE");
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor1_backward(char Letter)
{
for (int alphabet1=0;alphabet1<26;alphabet1++)
{
if(alphabet_of_rotor1[alphabet1] == Letter)
{
cout << "Chose direction of rotor 2:" << endl; //i intend to move these
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl; //lines to main so
cin >> direction_of_rotor2; //program wouldn't ask
switch(direction_of_rotor2) //direction of rotor 2
{ //on every letter
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_backward(alphabet_of_rotor1[alphabet1-1]);
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_forward(alphabet_of_rotor1[alphabet1-1]);
default:
cout<<"--------------------------------------------------------------"<<endl;
}
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor1_forward(char Letter)
{
for (int alphabet1=0;alphabet1<26;alphabet1++)
{
if(alphabet_of_rotor1[alphabet1] == Letter)
{
cout << "Chose direction of rotor 2:" << endl;
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;
cin >> direction_of_rotor2;
switch(direction_of_rotor2)
{
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_backward(alphabet_of_rotor1[alphabet1+1]);
break;
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_forward(alphabet_of_rotor1[alphabet1+1]);
break;
default:
cout<<"--------------------------------------------------------------"<<endl;
break;
}
break;
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor2_backward(char Letter2)
{
for (int alphabet2=0;alphabet2<26;alphabet2++)
{
if(alphabet_of_rotor2[alphabet2] == Letter2)
{
print(alphabet_of_rotor2[alphabet2-1]);
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor2_forward(char Letter2)
{
for (int alphabet2=0;alphabet2<26;alphabet2++)
{
if(alphabet_of_rotor2[alphabet2] == Letter2)
{
print(alphabet_of_rotor2[alphabet2+1]);
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char print(char print_char)
{
cout << print_char << endl;
//***i need to get from this line of this function here back to main***
return 0;
}
111100/11000
L7Sqr 227 Practically a Master Poster
111100/11000 commented: Thnx it worked +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.