GVA SUPPORT

³äïîâ³äü íà çàïèòàííÿ ¹ 1300653514
Text:
	ԲΠ= Ãîðáà÷åíêî Â.À.

 Çàïèòàííÿ:/* ØÈÔÐ ÖÅÇÀÐß
 * Öþ ïðîãðàìó íàïèñàâ ÃÎÐÁÀ×ÅÍÊÎ ÂÀÑÈËÜ
 * 20.03.2011 22:31
 * Äðóãà ãðóïà. Ëàáà 3. Øèôðóâàííÿ.
 * Ðîáèòü ìàéæå íà â³äì³ííî. 
 * Ïðîáëåìè: Äîïèñóº ëèøí³é ñèìâîë â ê³íåöü. Íå âèñòà÷ຠ÷àñó äëÿ òîãî ùîá ðîç³áðàòèñü
 * Íå ïåðåâ³ðÿºòüñÿ óìîâà ïåðåïîâíåííÿ ìåæ³. Áàéò ìຠìåæ³[-128;127].
 * Íå â³äîìî ùî áóäå êîëè çàéäå çà ìåæ³... ïåðåâ³ðÿéòå ñàì³... à òàê 
 * âçàãàë³ ïðàöþº íà êëþ÷àõ â³ä -30 äî +30
*/

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <strings.h>
#include <conio.h>

#include <iostream>
using namespace std;
void encoding(char *in, char *key, char *out)
{
    ifstream f_in(in, ios::in | ios::binary);
    ofstream f_out(out, ios::out | ios::binary);
    if ( !f_in || !f_out )  {
       cout << "ERROR of opening of a file.\\n"; system("PAUSE");  return ;
    }
    char  buf;
    while (!f_in.eof())  {
          f_in.read(&buf,1);
          buf=buf+atoi(key);
          f_out.write(&buf,1);
//          cout<<buf;
    }     
    f_in.close();
    f_out.close();
    
    cout<<"\\n\\n -> Encoding complate!\\n\\n";
}
void dencoding(char *in, char *key, char *out)
{
    ifstream f_in(in, ios::in | ios::binary);
    ofstream f_out(out, ios::out | ios::binary);
    if ( !f_in || !f_out )  {
       cout << "ERROR of opening of a file.\\n"; system("PAUSE");  return ;
    }
    char  buf;
    while (!f_in.eof())  {
          f_in.read(&buf,1);
          buf=buf-atoi(key);
          f_out.write(&buf,1);
//          cout<<buf;
    }     
    f_in.close();
    f_out.close();
    
    cout<<"\\n\\n -> Encoding complate!\\n\\n";
}
void k_read(char a[],char *b){
     cout<<a<<" : ";
     cin>>b;     
}
int main(int argc, char *argv[])
{
    char *in_filename=new char[80];
    char *out_filename=new char[80];
    char *key=new char[10];
    char userkey;
    do
    {
         system("cls"); 
         cout<<"Group 2. Laba#3. Variant #9. by Gorbachenko V.A\\
         \\nPress 1 to ecode\\
         \\nPress 2 to decode\\
         \\nYour choise : ";
         do{         
            userkey=getch();                  
         }while (userkey!=\'1\' && userkey!=\'2\');
         cout<<userkey<<endl;
         
         k_read("Enter IN filename",in_filename);
         k_read("Enter KEY [INT ONLY]",key);    
         k_read("Enter OUT filename",out_filename);    
         if (userkey==\'1\'){
            encoding(in_filename,key,out_filename);
         }
         else
         {
            dencoding(in_filename,key,out_filename);
         }
            
         cout<<"Press ESC to EXIT or other key to CONTINUE..."<<endl;
    } while (getch()!=27);

    
    system("PAUSE"); 
	return 0;
}


====================================	
Âàøà â³äïîâ³äü