Advertisement
Mizuhara_Chizuru

Project progress v3.1.5

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