Advertisement
Mizuhara_Chizuru

Project progress v5.0.2 (beta final)

Nov 4th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.42 KB | None | 0 0
  1. /*Code by Surya a.k.a Sunny*/
  2. /* by https://www.codechef.com/users/spsc */
  3. #include <bits/stdc++.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. //#include <boost/multiprecision/cpp_int.hpp>
  7. #define lli long long
  8. #define pi 3.14159265358979323846
  9. #define MOD 1000000007
  10. #define foi(n)  for(lli i=0;i<n;i++)
  11. #define foj(n)  for(lli j=0;j<n;j++)
  12. #define test(T) lli T;cin>>T;while(T--)
  13. #define loop(i, a, b) for(int i = (a); i<= (b); i++)
  14. #define unbuffer cin.clear(); cin.sync();
  15. #define option cout<<"Choose from one of the options below : \n\n\n";
  16. using namespace std;
  17. lli pass=0;
  18. string ans,backup;
  19. //using namespace boost::multiprecision;
  20. string decrypt(string backup)
  21.   {
  22.     lli temp,len=backup.length(),i=0;
  23.     char ans2[len],x;
  24.     while(i<len)
  25.       {
  26.         if(pass>50)
  27.           pass=0;
  28.         temp=backup[i];
  29.         temp-=pass;
  30.         x=(char)temp;
  31.         ans2[i]=x;
  32.         i++;
  33.         pass++;
  34.       }
  35.     ans2[len]='\0';
  36.     //ans;
  37.     //cout<<backup<<"\n";
  38.     return ans2;
  39.   }
  40. string decryptv2()
  41.   {
  42.     string f;
  43.     cout<<"Enter the name(with extension) of file you want to open.\n\n\t";
  44.     cin>>f;
  45.     ifstream file;
  46.     file.open(f, ios_base::app);
  47.     unbuffer
  48.     getline(file,backup);
  49.     file.close();
  50.     return decrypt(backup);
  51.     //cout<<"yayayayayayayayayayayayayaya";
  52.     //decrypt()
  53.   }
  54. void save(string &backup)
  55.   {
  56.     string f;
  57.     cout<<"Enter the name of the file(with extension)\n\n\t";
  58.     cin>>f;
  59.     ofstream file;
  60.     file.open(f);
  61.     file<<backup;
  62.     cout<<"The text is succesfully saved in a file named \""<<f<<"\""<<char(24)<<"\n\n\t";
  63.     file.close();
  64.   }
  65. void save2(string &backup)
  66.   {
  67.     string f;
  68.     cout<<"Enter the name of the file(with extension)\n\n\t";
  69.     cin>>f;
  70.     ofstream file;
  71.     file.open(f);
  72.     file<<backup;
  73.     cout<<"The text is succesfully saved in a file named \""<<f<<"\""<<char(24)<<"\n\n\t";
  74.     file.close();
  75.   }
  76. string encrypt(string str)
  77.   {
  78.     lli len,i=0,temp;
  79.     //file.open("decrypted_v.1.00.txt");
  80.     //getline(file,str);
  81.     len=str.length();
  82.     str[len]='\0';
  83.     char enc[len],x;
  84.     while(i<len)
  85.       {
  86.         if(pass>50)
  87.           pass=0;
  88.         temp=str[i];
  89.         temp+=pass;
  90.         x=(char)temp;
  91.         enc[i]=x; //*********************************
  92.         i++;
  93.         pass++;
  94.       }
  95.       enc[len]='\0';
  96.     //cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  97.   i=0;
  98.   pass=0;
  99.   backup=enc;
  100.   return enc;
  101.   }
  102. void encryptv2()
  103.   {
  104.     cout<<"Enter the Filename(with extension)./n/n/t";
  105.     string str;
  106.     cin>>str;
  107.     ifstream file;
  108.     file.open(str);
  109.     getline(file,str);
  110.     encrypt(str);
  111.     file.close();
  112.   }
  113. int main()
  114. {
  115.   //ios_base::sync_with_stdio(false);
  116.    //cin.tie(NULL);
  117.    //cout.tie(NULL);
  118.    lli a,i=0,temp,len;
  119.    string str;
  120.    char x;
  121.    //createfiles();
  122.    while(1)
  123.      {
  124.        i=0,pass=0;
  125.        system("cls");
  126.        //textcolor(11);
  127.        //setcolor(5);
  128.        cout<<setw(80)<<"DATA ENCRYPTION/DECRYPTION SOFTWARE v1.00\n\n\n";
  129.        //gotoxy(24,30);
  130.        option
  131.        cout<<" 1. Encryption of a text \n";
  132.        cout<<" 2. Decryption of a text \n";
  133.        cout<<" 3. Exit \n\n\n \t";
  134.        cin>>a;
  135.        system("cls");
  136.        if(a==1)
  137.         {
  138.           option
  139.           cout<<" 1. Enter a text \n";
  140.           cout<<" 2. Choose a .txt or .dat (binary) file by giving its name and extension \n\n\n \t";
  141.  
  142.           cin>>a;
  143.  
  144. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  145.  
  146.           system("cls");
  147.    /*if(a==1)
  148.     {
  149.       cout<<"Enter your text below : \n";
  150.       unbuffer
  151.       getline(cin,str);
  152.       len=str.length();
  153.       str[len]='\0';
  154.       char enc[len],dec[len];
  155.       while(i<len)
  156.         {
  157.           /*switch(str[i])
  158.             {
  159.               case 's':
  160.                 enc[i]='m';
  161.                 break;
  162.               case 'u':
  163.                 enc[i]='n';
  164.                 break;
  165.               case 'r':
  166.                 enc[i]='g';
  167.                 break;
  168.               case 'y':
  169.                 enc[i]='l';
  170.                 break;
  171.               case 'a':
  172.                 enc[i]='p';
  173.                 break;
  174.             }
  175.           if(pass>50)
  176.             pass=0;
  177.           temp=str[i];
  178.           temp+=pass;
  179.           x=(char)temp;
  180.           //cout<<x;
  181.           enc[i]=x; //*********************************
  182.           i++;
  183.           pass++;
  184.         }
  185.         enc[len]='\0';
  186.       //cout<<str<<'\n';
  187.       cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  188.     i=0;
  189.     pass=0;
  190.     backup=enc; */
  191.  
  192. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  193.  
  194.           if(a==1)
  195.             {
  196.               cout<<"Enter your text below : \n";
  197.               unbuffer
  198.               getline(cin,str);
  199.               ans=encrypt(str);
  200.             }
  201.           else if(a==2)
  202.             {
  203.               string f;
  204.               cout<<"Enter the Filename(with extension).\n\n\t";
  205.               cin>>f;
  206.               ifstream file;
  207.               file.open(f);
  208.               if(file)
  209.                 {
  210.                   getline(file,backup);
  211.                   ans=encrypt(backup);
  212.                 }
  213.               else
  214.                 {
  215.                   cout<<"\n\nEnter a valid Filename...";
  216.                   break;
  217.                 }
  218.             }
  219.           cout<<"\n_________________________________________________________________\n\n"<<ans<<"\n\n";
  220.           cout<<"THIS IS YOUR ENCRYPTED TEXT \n Choose an option from below : \n \t1. Manually copy this text. \n \t2. Save this text to a file. \n\n";
  221.           cin>>a;
  222.           if(a==1)
  223.           cout<<"The text is succesfully saved in a variable named \"backup\" which is printed above, you can note it down "<<char(24)<<"\n\n\t";
  224.           else if(a==2)
  225.             {
  226.               save(ans);
  227.               //cout<<"The text is succesfully saved in a file named \""<<f<<"\""<<char(24)<<"\n\n\t";
  228.               /*ofstream file;
  229.               file.open("encryption_v1.00.txt");
  230.               file<<backup;
  231.               file.close();*/
  232.             }
  233.     /*while(i<len)
  234.       {
  235.         temp=backup[i];
  236.         temp-=i;
  237.         x=(char)temp;
  238.         backup[i]=x;
  239.         i++;
  240.       }
  241.     backup[len]='\0';
  242.     cout<<backup;*/
  243.  
  244.  
  245.  
  246.     //  decrypt(backup,len); ######################################
  247.         }
  248.  
  249.  /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  250.  
  251.  
  252.         else if(a==2)
  253.          {
  254.            option
  255.            cout<<"1. Paste the text here and decrypt it.\n2. Decrypt the text saved to a file .\n\n\t";
  256.            cin>>a;
  257.            if(a==1)
  258.            {
  259.              cout<<"\nPaste your text below "<<(char)25<<"\n\n\t";
  260.              unbuffer
  261.              getline(cin,str);
  262.              cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<decrypt(str);
  263.              cout<<"\n\nTHIS IS YOUR DECRYPTED TEXT \n Choose an option from below : \n \t1. Manually copy this text. \n \t2. Save this text to a file. \n\n";
  264.              cin>>a;
  265.              if(a==1)
  266.                cout<<"The text is succesfully saved in a variable named \"backup\" which is printed above, you can note it down "<<char(24)<<"\n\n\t";
  267.              else if(a==2)
  268.              {
  269.                save2(str);
  270.             //   cout<<"The text is succesfully saved in a file named \"decrypted_v.1.00.txt\" "<<char(24)<<"\n\n\t";
  271.              }
  272.            }
  273.            else if(a==2)
  274.            {
  275.              ans=decryptv2();
  276.              cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<ans;
  277.              cout<<"\n\nTHIS IS YOUR DECRYPTED TEXT \n Choose an option from below : \n \t1. Manually copy this text. \n \t2. Save this text to a file. \n\n";
  278.              cin>>a;
  279.              if(a==1)
  280.              {
  281.                backup=ans;
  282.                cout<<ans<<"/nThe text is succesfully saved in a variable named \"backup\" which is printed above, you can note it down "<<char(24)<<"\n\n\t";
  283.              }
  284.              else if(a==2)
  285.              {
  286.                save2(ans);
  287.                cout<<"The text is succesfully saved in a file named \"decrypted_v.1.00.txt\" "<<char(24)<<"\n\n\t";
  288.              }
  289.            }
  290.          }
  291.       else if(a==3)
  292.         break;
  293.       else
  294.         cout<<"Enter a Valid Option. /n /n";
  295.      }
  296. }
  297.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement