Advertisement
Mizuhara_Chizuru

Project progress v4.2.5 (beta final)

Oct 27th, 2021
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.    while(1)
  117. {
  118.   system("cls");
  119.    cout<<"DATA ENCRYPTION SOFTWARE v1.00\n\n\n";
  120.    //gotoxy(24,30);
  121.    option
  122.    cout<<" 1. Encryption of a text \n";
  123.    cout<<" 2. Decryption of a text \n";
  124.    cout<<" 3. Exit \n\n\n \t";
  125.    cin>>a;
  126.    system("cls");
  127.    if(a==1)
  128.    {
  129.    option
  130.    cout<<" 1.  Enter a text \n";
  131.    cout<<" 2. Choose a .txt or .dat (binary) file by giving its name and extension \n\n\n \t";
  132.  
  133.    cin>>a;
  134.  
  135.    /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  136.  
  137.    system("cls");
  138.    /*if(a==1)
  139.     {
  140.       cout<<"Enter your text below : \n";
  141.       unbuffer
  142.       getline(cin,str);
  143.       len=str.length();
  144.       str[len]='\0';
  145.       char enc[len],dec[len];
  146.       while(i<len)
  147.         {
  148.           /*switch(str[i])
  149.             {
  150.               case 's':
  151.                 enc[i]='m';
  152.                 break;
  153.               case 'u':
  154.                 enc[i]='n';
  155.                 break;
  156.               case 'r':
  157.                 enc[i]='g';
  158.                 break;
  159.               case 'y':
  160.                 enc[i]='l';
  161.                 break;
  162.               case 'a':
  163.                 enc[i]='p';
  164.                 break;
  165.             }
  166.           if(pass>50)
  167.             pass=0;
  168.           temp=str[i];
  169.           temp+=pass;
  170.           x=(char)temp;
  171.           //cout<<x;
  172.           enc[i]=x; //*********************************
  173.           i++;
  174.           pass++;
  175.         }
  176.         enc[len]='\0';
  177.       //cout<<str<<'\n';
  178.       cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  179.     i=0;
  180.     pass=0;
  181.     backup=enc; */
  182.  
  183. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  184.  
  185. if(a==1)
  186. {
  187.   cout<<"Enter your text below : \n";
  188.   unbuffer
  189.   getline(cin,str);
  190.   ans=encrypt(str);
  191.  }
  192.  
  193. else if(a==2)
  194. {
  195.   ifstream file;
  196.   file.open("decrypted_v.1.00.txt");
  197.       getline(file,backup);
  198.     ans=encrypt(backup);
  199. }
  200. cout<<"\n_________________________________________________________________\n\n"<<ans<<"\n\n";
  201. 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";
  202. cin>>a;
  203. if(a==1)
  204.   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";
  205. else if(a==2)
  206.   {
  207.     save(ans);
  208.     cout<<"The text is succesfully saved in a file named \"encrypted_v1.txt\" "<<char(24)<<"\n\n\t";
  209.     /*ofstream file;
  210.     file.open("encryption_v1.00.txt");
  211.     file<<backup;
  212.     file.close();*/
  213.   }
  214.     /*while(i<len)
  215.       {
  216.         temp=backup[i];
  217.         temp-=i;
  218.         x=(char)temp;
  219.         backup[i]=x;
  220.         i++;
  221.       }
  222.     backup[len]='\0';
  223.     cout<<backup;*/
  224.  
  225.  
  226.  
  227.     //  decrypt(backup,len); ######################################
  228.  }
  229.  
  230.  /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  231.  
  232.  
  233. else if(a==2)
  234.   {
  235.     option
  236.     cout<<"1. Paste the text here and decrypt it.\n2. Decrypt the text saved to a file .\n\n\t";
  237.     cin>>a;
  238.     if(a==1)
  239.       {
  240.         cout<<"\nPaste your text below "<<(char)25<<"\n\n\t";
  241.         unbuffer
  242.         getline(cin,str);
  243.         cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<decrypt(str);
  244.         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";
  245.         cin>>a;
  246.         if(a==1)
  247.             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";
  248.         else if(a==2)
  249.           {
  250.             save2(str);
  251.             cout<<"The text is succesfully saved in a file named \"decrypted_v.1.00.txt\" "<<char(24)<<"\n\n\t";
  252.           }
  253.       }
  254.       else if(a==2)
  255.       {
  256.         ans=decryptv2();
  257.         cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<ans;
  258.         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";
  259.         cin>>a;
  260.         if(a==1)
  261.         {
  262.           backup=ans;
  263.           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";
  264.         }
  265.         else if(a==2)
  266.         {
  267.           save2(ans);
  268.           cout<<"The text is succesfully saved in a file named \"decrypted_v.1.00.txt\" "<<char(24)<<"\n\n\t";
  269.         }
  270.       }
  271.   }
  272.   else if(a==3)
  273.     break;
  274. }
  275. }
  276.  
Advertisement
RAW Paste Data Copied
Advertisement