#include <iostream> #include <string> #include <stdlib.h> using namespace std; int main() { string array[30][2]; string a,b; int t=0; while( cin >> a ) { if ( a == "0" ) { break; } else { cin >> b; } array[t][0] = a; array[t][1] = b; t++; } for ( int i = 0; i < t; i++ ) { const char *p = array[i][0].c_str(); int k = atoi(p); int len = array[i][1].size(); int *ciphercode = new int[len]; for ( int s = 0; s <len; s++ ) { if ( array[i][1][s] == '.') { ciphercode[s] = 27; } else if ( array[i][1][s] == '_') { ciphercode[s] = 0; } else { ciphercode[s] = array[i][1][s] - 96; } } int *plaincode = new int[len]; for ( int s = 0; s < len; s++ ) { int pt = ( k*s )%len; plaincode[pt] = (ciphercode[s] + s)%28; //cout <<pt <<" "<< plaincode[pt] << " "; } //cout << endl; char *plaintext = new char[len]; //cout << plaintext << endl; for ( int s = 0; s < len; s++ ) { if (plaincode[s] == 0 ) { plaintext[s] = '_'; } else if (plaincode[s] == 27 ) { plaintext[s] = '.'; } else { plaintext[s] = plaincode[s] + 96; } } //string resut(plaintext); for ( int m = 0; m < len; m++ ) { cout << plaintext[m]; } cout << endl; delete [] plaincode; delete [] plaintext; delete [] ciphercode; } return 0; }