hello all..
I have been working on a code to deal with cryptex .. please take a look at it and tell me what am doing wrong if you may..
here's the code:
//This program takes the number of rings, the unlocking word and the secret word in the form of _T___ that is with knowing
//only one charcter of the word.
//The program then takes the cryptx (rings==lines of the cryptx)
//each line has 26 different letters
//The program should align the unlocking word and thus the secret word appears
//The program only outputs the unlocking word and the secret word
# include <iostream>
# include <string>
using namespace std;
int main()
{
string un_lock;
string secret;
int sec_len;
int rings;
string string_in[3][26];//[rings][letters]
string second[3][26];
char sec_char;
int sec_pos;
int the_col;
string the_secret;
string first[3][26];
cout<<"Enter the Unlocking word"<<endl;
cin>>un_lock;
cout<<"Enter the secret word"<<endl;
cin>>secret;
//the length of the word is the number of the rows/rings
sec_len=secret.length();
rings=sec_len;
int f=0;
int k=0;
int p=0;
int y=0;
for(int j=0; j<rings; j++)
for(int i=0; i<26; i++)
{ //if the letters in the first/2nd/etc row != the letter
//in the unlocking word save that in the second string
if (string_in[j][i]!=un_lock[j])
second[f++][k++]=string_in [j][i];
//if the letters in the first/2nd/etc row = the letter
//in the unlocking word save that and what is after in the first string
else if (string_in[j][i]==un_lock[j])
for (int z=k; z<26; z++)
first[p++][y++]=string_in[j][i];
}
//to fill in the main string again
for(int j=0; j<rings; j++)
{
int i;
for( i=0; i<26; i++)
string_in[j][i]=first[j][i];
for(int z=i; i<26; i++)
string_in[j][i]=second[j][z];
}
//finding the position of the known secret letter
//which will be the number of the ring it is located in
for(int i=0; i<sec_len; i++)
if(secret[i]!=static_cast<char>(95))
{
sec_char=secret[i];
sec_pos=i;
}
//finding the column of the secret word
for(int i=0; i<26; i++)
if(string[sec_pos][i]==sec_char)
the_col=i;
//saving the secret word
for(int j=0; j<rings; j++)
the_secret[j]=string[j][the_col];
//the output
cout<<un_lock<<" "<<the_secret<<endl;
return 0;
}
if you didn't get the purpose of the code please check the attached file