Advertisement
Mizuhara_Chizuru

Project progress v4.1.5 (beta final)

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