Advertisement
Mizuhara_Chizuru

Project progress v2.1.0

Oct 17th, 2021
60
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. //using namespace boost::multiprecision;
  17. void decrypt(string backup, lli len)
  18. {
  19.   lli temp,i=0,x;
  20.     while(i<len)
  21.       {
  22.         temp=backup[i];
  23.         temp-=i;
  24.         x=(char)temp;
  25.         backup[i]=x;
  26.         i++;
  27.       }
  28.     backup[len]='\0';
  29.     cout<<backup<<"\n";
  30.   }
  31. void save(string &backup)
  32.   {
  33.     ofstream file;
  34.     file.open("encryption_v1.00.txt");
  35.     file<<backup;
  36.     file.close();
  37.   }
  38. int main()
  39. {
  40.   //ios_base::sync_with_stdio(false);
  41.    //cin.tie(NULL);
  42.    //cout.tie(NULL);
  43.    lli a,i=0,temp,len;
  44.    string str,backup;
  45.    char x;
  46.  
  47.    cout<<"DATA ENCRYPTION SOFTWARE v1.00\n\n\n";
  48.    //gotoxy(24,30);
  49.    option
  50.    cout<<" 1. Encryption of a text \n";
  51.    cout<<" 2. Decryption of a text \n\n\n \t";
  52.    cin>>a;
  53.    system("cls");
  54.    if(a==1)
  55.    {
  56.    option
  57.    cout<<" 1.  Enter a text \n";
  58.    cout<<" 2. Choose a .txt or .dat (binary) file by giving its name and extension \n\n\n \t";
  59.  
  60.    cin>>a;
  61.  
  62.    /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  63.  
  64.    system("cls");
  65.    if(a==1)
  66.     {
  67.       cout<<"Enter your text below : \n";
  68.       unbuffer
  69.       getline(cin,str);
  70.       len=str.length();
  71.       str[len]='\0';
  72.       char enc[len],dec[len];
  73.       while(i<len)
  74.         {
  75.           /*switch(str[i])
  76.             {
  77.               case 's':
  78.                 enc[i]='m';
  79.                 break;
  80.               case 'u':
  81.                 enc[i]='n';
  82.                 break;
  83.               case 'r':
  84.                 enc[i]='g';
  85.                 break;
  86.               case 'y':
  87.                 enc[i]='l';
  88.                 break;
  89.               case 'a':
  90.                 enc[i]='p';
  91.                 break;
  92.             }
  93.           */
  94.           temp=str[i];
  95.           temp+=i;
  96.           x=(char)temp;
  97.           //cout<<x;
  98.           enc[i]=x; //*********************************
  99.           i++;
  100.         }
  101.         enc[len]='\0';
  102.       //cout<<str<<'\n';
  103.       cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  104.     i=0;
  105.     backup=enc;
  106.  
  107. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  108.  
  109. }
  110.  
  111. 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";
  112. cin>>a;
  113. if(a==1)
  114.   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";
  115. else if(a==2)
  116.   {
  117.     save(backup);
  118.     /*ofstream file;
  119.     file.open("encryption_v1.00.txt");
  120.     file<<backup;
  121.     file.close();*/
  122.   }
  123.     /*while(i<len)
  124.       {
  125.         temp=backup[i];
  126.         temp-=i;
  127.         x=(char)temp;
  128.         backup[i]=x;
  129.         i++;
  130.       }
  131.     backup[len]='\0';
  132.     cout<<backup;*/
  133.  
  134.  
  135.  
  136.     //  decrypt(backup,len); ######################################
  137.  }
  138. else if(a==2)
  139.   {
  140.     option
  141.     cout<<"1. Paste the text here and decrypt it.\n2. Decrypt the text saved to a file .\n\n\t";
  142.     cin>>a;
  143.     if(a==1)
  144.       {
  145.         cout<<"\nPaste your text below "<<(char)25<<"\n\n\t";
  146.         unbuffer
  147.         getline(cin,str);
  148.         cout<<"\nDecrypted text is below "<<(char)25<<"\n\n\t";
  149.         decrypt(str, str.length());
  150.       }
  151.   }
  152. }
  153.  
Advertisement
RAW Paste Data Copied
Advertisement