
11.02.2008, 18:33
|
|
Постоянный
Регистрация: 05.01.2007
Сообщений: 508
С нами:
10182506
Репутация:
1393
|
|
Сообщение от KSoniX
ну хотябы блочный шифратор плз
Код:
#include <iostream>
#include <string>
#include <cstdio>
#include <strstream>
#include <conio.h>
using namespace std;
void main()
{
string fname;
strstream strstr;
char xor[20];
FILE* fl1, * fl2;
while(1)
{
cout << "Enter a file to encrypt or decrypt: ";
cin >> fname;
if(cin.good() )
{
cin.ignore(10, '\n');
break;
}
cin.clear();
}
fl1 = fopen(fname.c_str(),"r");
if(!fl1)
{ cout << "ERROR: Could not open file for reading!"; getch(); return; }
while(1)
{
cout << "Enter a file to write to: ";
cin >> fname;
if(cin.good() )
{
cin.ignore(10, '\n');
break;
}
cin.clear();
}
fl2 = fopen(fname.c_str(), "w");
if(!fl2)
{ cout << "ERROR: Could not open file for writing!"; getch(); return; }
while(1)
{
cout << "Enter a code to encrypt with: ";
cin >> xor;
if(cin.good() )
{
cin.ignore(10, '\n');
break;
}
cin.clear();
}
char chr1, chr2;
int xrCount=0;
int xrLen = strlen(xor);
while(1)
{
chr1=fgetc(fl1);
if(chr1==EOF)
{
break;
}
else
{
if( (++xrCount) >=xrLen) xrCount=0;
chr2 = chr1 ^ xor[xrCount];
fputc(chr2, fl2);
}
}
fclose(fl1);
fclose(fl2);
cout << "Encrypted successfully.\nPress any key to continue. ";
getch();
}
|
|
|