Analysis: it is a question of number theory.
Ciphercode[I] = (Plaincode[KiMoDN]-I) Mod 28Plaincode[KiMoDN] Not greater than 28, so
Plaincode[KiMoDN] = (Ciphercode[I] + I) mod 28.
At that time, I couldn't understand this ki, And I was dizzy. It turned out to be key * I.
Code
# Include < Iostream >
# Include < Vector >
Using Namespace STD;
Void Transtocode ( Const Char * STR, Vector < Int > & V)
{
V. Clear ();
Int Len = Strlen (STR );
For ( Int I = 0 ; I < Len; ++ I)
Switch (STR [I])
{
Case ' _ ' : V. push_back ( 0 ); Break ;
Case ' . ' : V. push_back ( 27 ); Break ;
Default : V. push_back (STR [I] - ' A ' + 1 ); Break ;
}
}
Void Transtotext ( Const Vector < Int > V, Char * Str)
{
Int Len = V. Size ();
For ( Int I = 0 ; I < Len; ++ I)
Switch (V [I])
{
Case 0 : Str [I] = ' _ ' ; Break ;
Case 27 : Str [I] = ' . ' ; Break ;
Default : Str [I] = V [I] - 1 + ' A ' ; Break ;
}
STR [Len] = ' \ 0 ' ;
}
Void Decrypt (vector < Int > & V, Const Int Key)
{
Vector < Int > S (v );
Int Len = S. Size ();
For ( Int I = 0 ; I < Len; ++ I)
V [(Key * I) % Len] = (S [I] + I) % 28 ;
}
Int Main ()
{
Char Text [ 71 ]; Int Key;
While (CIN > Key, key)
{
CIN>Text;
Vector<Int>V;
Transtocode (text, V );
Decrypt (v, key );
Transtotext (v, text );
Cout<Text<Endl;
}
Return 0 ;
}