Архив задач

Дешифрование

Текстовый файл «encrypttext.txt» был получен, применяя 2015 раз функцию Encrypt (см. листинг 1) к исходному файлу. Расшифруйте файл «encrypttext.txt» по крайней мере в 1000 раз быстрее, чем он был зашифрован.

char * ReadMassFromFile(ifstream &inFile, int &outN)                       //1
{
       char tempMass[10];                                                  //2
       char buff;                                                          //3
       int i(0);                                                           //4
       while (!inFile.eof() && (i<10))                                     //5
       {
             inFile.get(buff);                                             //6
             if (inFile) tempMass[i++] = buff;                             //7
       }
       char * outMass = new char [i];                                      //8
       for (int j = 0; j
       outN = i;                                                           //10
       return outMass;                                                     //11
}
void EncryptMass(char * Mass, int n)                                       //12
{
       if (n!=10) return;                                                  //13
       char temp[10];                                                      //14
       for (int i = 0; i < 10; i++)      temp[i] = Mass[i];                //15
       for(int i=0;i
       return;                                                             //17
}
void WriteMassToFile(ofstream &outFile, char * mass, int n)                //18
{
       for (int i=0; i
       delete [] mass;                                                     //20
       return;                                                             //21
}
int Encrypt(char * inFile, char* outFile)                                  //22
{
       ifstream openText(inFile);                                          //23
       ofstream encryptText(outFile);                                      //24
       if (!openText || !encryptText) return -1;                           //25
       while (!openText.eof())                                             //27
       {
             int n;                                                        //28
             char *buffMass = ReadMassFromFile(openText, n);               //29
             EncryptMass(buffMass, n);                                     //30
             WriteMassToFile(encryptText,buffMass, n);                     //31
       }
       return 1;                                                           //32
}
Листинг 1. Исходный код программы шифрования файла