Advertisement
Mizuhara_Chizuru

Project progress v4.1.5

Oct 25th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.75 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. string encrypt(string str)
  67.   {
  68.     lli len,i=0,temp;
  69.     //file.open("decrypted_v.1.00.txt");
  70.     //getline(file,str);
  71.     len=str.length();
  72.     str[len]='\0';
  73.     char enc[len],x;
  74.     while(i<len)
  75.       {
  76.         if(pass>50)
  77.           pass=0;
  78.         temp=str[i];
  79.         temp+=pass;
  80.         x=(char)temp;
  81.         enc[i]=x; //*********************************
  82.         i++;
  83.         pass++;
  84.       }
  85.       enc[len]='\0';
  86.     //cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  87.   i=0;
  88.   pass=0;
  89.   backup=enc;
  90.   return enc;
  91.   }
  92.   void encryptv2()
  93.   {
  94.     string str;
  95.     ifstream file;
  96.     file.open("decrypted_v.1.00.txt");
  97.     getline(file,str);
  98.     encrypt(str);
  99.   }
  100. int main()
  101. {
  102.   //ios_base::sync_with_stdio(false);
  103.    //cin.tie(NULL);
  104.    //cout.tie(NULL);
  105.    lli a,i=0,temp,len;
  106.    string str;
  107.    char x;
  108.    createfiles();
  109.    cout<<"DATA ENCRYPTION SOFTWARE v1.00\n\n\n";
  110.    //gotoxy(24,30);
  111.    option
  112.    cout<<" 1. Encryption of a text \n";
  113.    cout<<" 2. Decryption of a text \n\n\n \t";
  114.    cin>>a;
  115.    system("cls");
  116.    if(a==1)
  117.    {
  118.    option
  119.    cout<<" 1.  Enter a text \n";
  120.    cout<<" 2. Choose a .txt or .dat (binary) file by giving its name and extension \n\n\n \t";
  121.  
  122.    cin>>a;
  123.  
  124.    /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  125.  
  126.    system("cls");
  127.    /*if(a==1)
  128.     {
  129.       cout<<"Enter your text below : \n";
  130.       unbuffer
  131.       getline(cin,str);
  132.       len=str.length();
  133.       str[len]='\0';
  134.       char enc[len],dec[len];
  135.       while(i<len)
  136.         {
  137.           /*switch(str[i])
  138.             {
  139.               case 's':
  140.                 enc[i]='m';
  141.                 break;
  142.               case 'u':
  143.                 enc[i]='n';
  144.                 break;
  145.               case 'r':
  146.                 enc[i]='g';
  147.                 break;
  148.               case 'y':
  149.                 enc[i]='l';
  150.                 break;
  151.               case 'a':
  152.                 enc[i]='p';
  153.                 break;
  154.             }
  155.           if(pass>50)
  156.             pass=0;
  157.           temp=str[i];
  158.           temp+=pass;
  159.           x=(char)temp;
  160.           //cout<<x;
  161.           enc[i]=x; //*********************************
  162.           i++;
  163.           pass++;
  164.         }
  165.         enc[len]='\0';
  166.       //cout<<str<<'\n';
  167.       cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  168.     i=0;
  169.     pass=0;
  170.     backup=enc; */
  171.  
  172. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  173.  
  174. if(a==1)
  175. {
  176.   cout<<"Enter your text below : \n";
  177.   unbuffer
  178.   getline(cin,str);
  179.   ans=encrypt(str);
  180.  }
  181.  
  182. else if(a==2)
  183. {
  184.   ifstream file;
  185.   file.open("decrypted_v.1.00.txt");
  186.       getline(file,backup);
  187.     ans=encrypt(backup);
  188. }
  189. cout<<"\n_________________________________________________________________\n\n"<<ans<<"\n\n";
  190. 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";
  191. cin>>a;
  192. if(a==1)
  193.   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";
  194. else if(a==2)
  195.   {
  196.     save(ans);
  197.     cout<<"The text is succesfully saved in a file named \"encrypted_v1.txt\" "<<char(24)<<"\n\n\t";
  198.     /*ofstream file;
  199.     file.open("encryption_v1.00.txt");
  200.     file<<backup;
  201.     file.close();*/
  202.   }
  203.     /*while(i<len)
  204.       {
  205.         temp=backup[i];
  206.         temp-=i;
  207.         x=(char)temp;
  208.         backup[i]=x;
  209.         i++;
  210.       }
  211.     backup[len]='\0';
  212.     cout<<backup;*/
  213.  
  214.  
  215.  
  216.     //  decrypt(backup,len); ######################################
  217.  }
  218.  
  219.  /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  220.  
  221.  
  222. else if(a==2)
  223.   {
  224.     option
  225.     cout<<"1. Paste the text here and decrypt it.\n2. Decrypt the text saved to a file .\n\n\t";
  226.     cin>>a;
  227.     if(a==1)
  228.       {
  229.         cout<<"\nPaste your text below "<<(char)25<<"\n\n\t";
  230.         unbuffer
  231.         getline(cin,str);
  232.         cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<decrypt(str);
  233.       }
  234.       else if(a==2)
  235.       {
  236.         cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t"<<decryptv2();
  237.       }
  238.   }
  239. }
  240.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement