⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keshar5.cpp

📁 它加密txt文件和cpp文件
💻 CPP
字号:
/**************************************keshax for the win*************************/
// Name: ENCRYPTOR!! 
// Description:it  encrypts txt & cpp files(others maybe) and creates a KEY in //your floppy disk
// The same key opens or decrypts the file
// By:  keshax   (e-mail keshax@metallica.com) MAIL ME
// LEVEL : Begginer
// Oh Yeah: You better try em' one at a time coz if u loose the key...
//NOTE: They key has the first few letters of the original file name for EZ //identifying.
//Ps: This is also my school project!!



#include <string.h>
#include <bios.h>
#include <graphics.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
#include <stdio.h>

	  ifstream  fin;
	  ofstream fout;

class kryptonix{                                           //nice name what??!
		  public:
		  unsigned int *key;       //POINTER DECLARATIONS
		  unsigned char *ptr;
		  unsigned char *ptr2;
		  unsigned char *ptr3;
		  unsigned int *New_key;

		   void Encrypt();
		   void Decrypt();
		   void fillin2();
		   void Get_size();
		   void Fill_in();
		   void Get_size2();
		   void KEY();

		   friend void Disp_e();
		   friend void Disp_d();

		}; kryptonix cipher;

		    unsigned int count=0,i=0,cho, count2=0,h;
		    unsigned char ch=NULL,path[20],key_path[25];

int main()
  {

int gdriver = DETECT, gmode, errorcode;char ans,ans1;
initgraph(&gdriver, &gmode, "");
cleardevice();
  struct ffblk ffblk;
   int done;
   printf("\n\tDirectory listing of all tune (.tun) Files \t\n");
   done = findfirst("*.tun",&ffblk,0); //TO FIND ANY TUN FILES IN CURRENT DIR
   while (!done)
   {
      cout<<ffblk.ff_name<<"\n";
      done = findnext(&ffblk);
   }
settextstyle(2,0,8);
outtextxy(300,200,"Enter File name ");
cout<<"\n\n\n";
cin.getline(path,20);

   key_path[0]='a';
   key_path[1]=':';
   key_path[2]='/';
   key_path[3]=path[0];
   key_path[4]=path[1];
   key_path[5]=path[2];
   key_path[6]=path[3];
   key_path[7]=path[4];
   key_path[8]='.';
   key_path[9]='k';
   key_path[10]='e';
   key_path[11]='y';

do{
       cipher.Get_size();
       cipher.Get_size2();
 cipher.ptr=new unsigned char[count];        //PTR DECLARE
 cipher.key=new unsigned int[count];        //key DECLARE
 cipher.ptr2=new unsigned char[count];        //PTR2 DECLARE
 cipher.New_key=new unsigned int[count];
 cipher.ptr3= new unsigned char[count2];

setfillstyle(7,1);
bar(0,0,642,479);
settextstyle(2,0,12);
settextstyle(2,0,9);
outtextxy(200,140,"1. Display");
outtextxy(200,180,"2. Encrypt");
outtextxy(200,220,"3. Decrypt");
outtextxy(200,260,"4. About");
outtextxy(200,300,"5. Exit");
settextstyle(2,0,7);
outtextxy(150,348,"Enter your choice:_");
   gotoxy(46,23);
   cin>>cho;
    switch(cho)
    {
     case 1: cleardevice();
	    fin.open(path,ios::in);
	     while(fin)
	      {
		fin.get(ch);
		cout<<ch;
	       }
	      fin.close();
	     break;

     case 2:   cleardevice();
	      cipher.Fill_in();
	      cipher.Encrypt();
	       Disp_e();
	      outtextxy(150,48,"ENCRYPTION COMPLETE!");
	      break;

     case 3:  cleardevice();
		cipher.KEY();
		cipher.fillin2();
		cipher.Decrypt();
		Disp_d();
	      outtextxy(150,48,"DECRYPTION COMPLETE!");
	      getch();
	      break;

     case 5: exit(0);
	     break;
    }
    i=0;ch=NULL;
    count=0;
    count2=0;
    cout<<"\n******* Return to Menu?(Y/N): ";
    cin>>ans;
    }
    while(ans=='y' || ans=='Y');

      delete[]cipher.ptr;
      delete[]cipher.key;
      delete[]cipher.ptr2;
      delete[]cipher.New_key;
      delete[]cipher.ptr3;
      return 0;

      }
   void kryptonix::Get_size()
    {
       fin.open(path,ios::in | ios::binary);
	  while(fin)
	  {
		 fin.get(ch);
		 count++;
	    }
       fin.close();
   return ;
   }

   void kryptonix:: Fill_in()
	  {
	     fin.open(path,ios::in | ios::binary);
		 while(fin)
		  {
		    fin.get(ch);
		    if(ch==0x0d)
		    ch=' ';
		    cipher.ptr[i]=ch;
		    i++;
		  }
	fin.close();
      return ;
      }

   void kryptonix::Encrypt()  
       {
       int temp,dope,k=0;
       int result; char buffer[512];

   outtextxy(100,200,"Testing to see if drive a: is ready");
   result = biosdisk(4,0,0,0,0,1,buffer);
   result &= 0x02;
   if(result)
     { outtextxy(100,230,"Drive A: Ready!");
	cleardevice();
       fout.open(key_path,ios::out) ;
       for(int p=0;p<count;p++)
       {
	  temp=rand() % count;

       cipher.key[p]=temp;
	  for(int s=0;s<p;s++)//all this to get non-repeating random numbers!!
	    {
	      if(temp==cipher.key[s])
		 {  k=0;

		   while(k!=1)
		     {
		       dope=rand() % count;
			 if(dope!=temp)
			  {
			  cipher.key[p]=dope;
			   temp=dope;
			   s=-1;
			   k=1;
			  }
		     } //if inner

		 }

	     }     cipher.ptr2[temp]=cipher.ptr[p];
		    fout<<cipher.key[p]<<'\n';
	     }
     fout.close();
     }
      else{  cleardevice();
	     settextstyle(2,0,22);
	     outtextxy(100,300,"ERROR READING KEY!"); exit(0);}
	return ;
	  }

       void Disp_e()
	{
	   fout.open(path,ios::out);
	   for(int g=0;g<count;g++)
	     {
		 if(cipher.ptr2[g]==0x0d)
		   cipher.ptr2[g]=' ';
		fout<<cipher.ptr2[g];
		cout<<cipher.ptr2[g];
	     }
		fout.close();
	return ;
	 }



    void kryptonix::Decrypt()
    {
     if(key_path[3]==path[0]||key_path[4]==path[1]||key_path[5]==path[2]||key_path[6]==path[3]||key_path[7]==path[4])
     { fout.open(path,ios ::out);
      int tag=0;
      cout<<"\n\n";
	for(int u=0;u<count2;u++)
	 {
	   tag=cipher.New_key[u];
	    if(cipher.ptr3[tag]==0x0d)
	    cipher.ptr3[tag]=' ';
	   fout<<cipher.ptr3[tag];

	 }
      fout.close();
      } return ;
     }

       void Disp_d()
	{
     int tag=0;
      cout<<"\n\n";
	for(int u=0;u<count2;u++)
	 {
	   tag=cipher.New_key[u];
	   cout<<cipher.ptr3[tag];
	 }
	return ;
	 }
 void kryptonix::KEY()
  {
    if(key_path[3]==path[0]||key_path[4]==path[1]||key_path[5]==path[2]||key_path[6]==path[3]||key_path[7]==path[4])
     {
	 char *str; int k=0;
	int result; char buffer[512];

   outtextxy(100,200,"Testing to see if drive a: is ready");
   result = biosdisk(4,0,0,0,0,1,buffer);
   result &= 0x02;
   if(result)
     { outtextxy(100,230,"Drive A: Ready!");
	getch();
	cleardevice();
	fin.open(key_path,ios::in);//|ios::nocreate);
	while(fin)
	 {
		fin.getline(str,6);
		cipher.New_key[k]=atoi(str);
		k++;
	 }   fin.close();
	 }
	 else{  cleardevice();
	     settextstyle(2,0,22);
	     outtextxy(100,300,"ERROR READING KEY!"); exit(0);
	      }
	}
   return ;
}
 void kryptonix::Get_size2()
  {
  char ch3=NULL;
  fin.open(path,ios::in);
  while(fin)
   {
    fin.get(ch3);
    count2++;
    }
    count2--;
    fin.close();
    return ;
    }

void kryptonix::fillin2()
 {
  char ch2=NULL;
  int z=0;
   fin.open(path,ios::in);
    {
      while(fin)
       {
	 fin.get(ch2);
	  if(ch2==0x0d)
	   ch2=' ';
	   cipher.ptr3[z]=ch2;
	   z++;
       }
    fin.close();
    }
 return;
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -