Это не ответ на Ваш вопрос, но вот реализация шифровки текста из латинских букв с помощью квадрата 5х5.
========================================
#include
using namespace std;
int main(){
char sqr[5][5] = {
{'a','b','c','d','e'},
{'f','g','h','i','k'},
{'l','m','n','o','p'},
{'q','r','s','t','u'},
{'v','w','x','y','z'},
};
char word[80];// = "sometext"; // шифруемый текст
gets(word);
char *pword = new char[strlen(word)+1]; // массив для шифровки.
int b;
for(int i(0); i < 5*5; i++){ // шифруем
for(int j(0); j < strlen(word); j++){
if(word[j] == sqr[0][i] || tolower(word[j]) == sqr[0][i]){
b=i;
if((b+5) < 25){ pword[j] = sqr[0][b+5];}
else{ pword[j] = sqr[0][b+5-25];}
}
else if(word[j] == ' ') pword[j] = ' ';
else if(word[j] == 'j' || word[j] == 'J') pword[j] = 'j';
if(isupper(word[j])) pword[j] = toupper(pword[j]);
if(!isalpha(word[j])) pword[j] = word[j];
}
}
pword[strlen(word)] = '\0';
cout << pword << endl; // смотрим, что получилось
char *ppword = new char[strlen(pword)]; // массив для дешифровки
for(int i(0); i < strlen(pword); i++){ // дешфруем
for(int j(0); j < 25; j++){
if(pword[i] == sqr[0][j] || tolower(pword[i]) == sqr[0][j]) {
b = j;
if((b-5) >= 0) ppword[i] = sqr[0][b-5];
else ppword[i] = sqr[0][b-5+25];
}
else if(pword[i] == ' ') ppword[i] = ' ';
else if(pword[i] == 'j' || pword[i] == 'J') ppword[i] = 'j';
if(isupper(pword[i])) ppword[i] = toupper(ppword[i]);
if(!isalpha(pword[i])) ppword[i] = pword[i];
}
}
ppword[strlen(pword)] = '\0';
cout << ppword << endl; // смотрим на дешифровку
system("pause >> void");
return 0;
}