Can anyone help me in the table referencing? See the below example:
-------------------------------------------------------------------
-------------------------------------------------------------------Code:#include <iostream.h> #include <string.h> //#define TABLE_SIZE 10 struct tableType { char actual; char cipher; }; class secret { tableType table[10]; char text[256]; char temp[256]; int length; public: secret(); //~secret(){} void enter_message(); //char get_message(); void encrypt(); void display(); }; secret::secret() { table[0].actual='A'; table[0].cipher='z'; table[1].actual='B'; table[1].cipher='a'; table[2].actual='C'; table[2].cipher='q'; table[3].actual='D'; table[3].cipher='1'; table[4].actual='E'; table[4].cipher='2'; table[5].actual='F'; table[5].cipher='w'; table[6].actual='G'; table[6].cipher='s'; table[7].actual='H'; table[7].cipher='x'; table[8].actual='I'; table[8].cipher='c'; table[9].actual='J'; table[9].cipher='d'; } void secret::enter_message() { cout << "Enter Your Message: "; cin.getline(text,256); } void secret::encrypt() { length=strlen(text); for (int x=0; x { for (int y=x; y<10; y++) { if (text[x]==table[y].actual) temp[x]=table[y].cipher; } } } void secret::display() { cout << endl; cout << "Original Text: " << text << endl << endl; cout << "Encrypted Text: " << temp << endl << endl; cout << "ACTUAL" << " " << "CIPHER" << endl; cout << "======" << " " << "======" << endl; for (int i=0; i<10; i++) { cout << table[i].actual << " " << table[i].cipher << endl; } } void main() { secret sc; sc.enter_message(); sc.display(); cout << endl << endl; }
What I want is just create a table with 2 columns. One for actual value and the other is for cipher value. Then I'll enter a message and let the program to convert the character (of the message) to cipher one.
I think I'll doing in the stupid and incorrect way. I need you guys advise. Please help.