Advertisement
Mizuhara_Chizuru

Project progress v2

Oct 17th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 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. using namespace std;
  15. //using namespace boost::multiprecision;
  16. void decrypt(string &backup, lli &len)
  17. {
  18.   lli temp,i=0,x;
  19.     while(i<len)
  20.       {
  21.         temp=backup[i];
  22.         temp-=i;
  23.         x=(char)temp;
  24.         backup[i]=x;
  25.         i++;
  26.       }
  27.     backup[len]='\0';
  28.     cout<<backup;
  29.   }
  30. int main()
  31. {
  32.   //ios_base::sync_with_stdio(false);
  33.    //cin.tie(NULL);
  34.    //cout.tie(NULL);
  35.    lli a,i=0,temp,len;
  36.    string str,backup;
  37.    char x;
  38.  
  39.    cout<<"DATA ENCRYPTION SOFTWARE v1.00\n\n\n";
  40.    //gotoxy(24,30);
  41.    cout<<"Choose from one of the options below : \n\n\n";
  42.    cout<<" 1. Encryption of a text \n";
  43.    cout<<" 2. Decryption of a text \n\n\n \t";
  44.    cin>>a;
  45.    system("cls");
  46.    if(a==1)
  47.    {
  48.    cout<<" 1.  Enter a text \n";
  49.    cout<<" 2. Choose a .txt or .dat (binary) file by giving its name and extension \n\n\n \t";
  50.  
  51.    cin>>a;
  52.  
  53.    /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  54.  
  55.    system("cls");
  56.    if(a==1)
  57.     {
  58.       cout<<"Enter your text below : \n";
  59.       unbuffer
  60.       getline(cin,str);
  61.       len=str.length();
  62.       str[len]='\0';
  63.       char enc[len],dec[len];
  64.       while(i<len)
  65.         {
  66.           /*switch(str[i])
  67.             {
  68.               case 's':
  69.                 enc[i]='m';
  70.                 break;
  71.               case 'u':
  72.                 enc[i]='n';
  73.                 break;
  74.               case 'r':
  75.                 enc[i]='g';
  76.                 break;
  77.               case 'y':
  78.                 enc[i]='l';
  79.                 break;
  80.               case 'a':
  81.                 enc[i]='p';
  82.                 break;
  83.             }
  84.           */
  85.           temp=str[i];
  86.           temp+=i;
  87.           x=(char)temp;
  88.           //cout<<x;
  89.           enc[i]=x; //*********************************
  90.           i++;
  91.         }
  92.       //cout<<str<<'\n';
  93.       cout<<"\n_________________________________________________________________\n\n"<<enc<<"\n\n";
  94.     i=0;
  95.     backup=enc;
  96. 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";
  97.  
  98. /*---------X------------X-----------X-----------X----------X----------X--------X---------*/
  99.  
  100. }
  101.     /*while(i<len)
  102.       {
  103.         temp=backup[i];
  104.         temp-=i;
  105.         x=(char)temp;
  106.         backup[i]=x;
  107.         i++;
  108.       }
  109.     backup[len]='\0';
  110.     cout<<backup;*/
  111.    
  112.     decrypt(backup,len);
  113.  }
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement