//--------------------------------------------------------------------------- #include <iostream.h> #include <fstream.h> #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender) { if (OpenDialog1->Execute() ) RichEdit1->Lines->LoadFromFile (OpenDialog1->FileName) ; } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn2Click(TObject *Sender) { int q=0; char ch; char mas1[8]; char mas2[8]; char mas3[8]; char gam[8] = {'П', 'k', 'O', 'Q', 'б', 'я', 'Y', 'v'}; ifstream infile(OpenDialog1->FileName.c_str()); ofstream outfile("Ofile.txt"); while(!infile.eof()) { ++q; int i; for(i=0; i<8; ++i) { infile.get(ch); if(!infile.eof()) { mas2[i]=ch; } else break; } if(q==1) { for(int j=0; j<i; ++j) { mas3[j] = mas2[j] ^ gam[j]; outfile.put(mas3[j]); } } else { for(int c=0; c<i; ++c) { mas3[c]=mas2[c] ^ mas1[c] ^ gam[c]; outfile.put(mas3[c]); } } for(int w=0; w<i; ++w) { mas1[w] = mas3[w]; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn3Click(TObject *Sender) { int q=0; char ch; char mas1[8]; char mas2[8]; char mas3[8]; char gam[8] = {'П', 'k', 'O', 'Q', 'б', 'я', 'Y', 'v'}; ifstream infile(OpenDialog1->FileName.c_str()); ofstream outfile("File.txt"); while(!infile.eof()) { ++q; int i; for(i=0; i<8; ++i) { infile.get(ch); if(!infile.eof()) { mas2[i]=ch; } else break; } if(q==1) { for(int j=0; j<i; ++j) { mas3[j] = mas2[j] ^ gam[j]; outfile.put(mas3[j]); } } else { for(int c=0; c<i; ++c) { mas3[c]=mas2[c] ^ mas1[c] ^ gam[c]; outfile.put(mas3[c]); } } for(int w=0; w<i; ++w) { mas1[w] = mas2[w]; } } } 

It works well with .тхт files. But when I open the .rtf file, encryption occurs without errors (they are the same size), but when I decrypt the file, when I try to open it via MSWord, I get a message that the file is damaged. Tell me what to do?

0