#include <iostream>
#include <conio.h>
using namespace std;

class CaesarCipher
{
      private:
              static const int KEY = 3 ;       // the key for caesar cipher
              
      public:
             string encryption (string str) 
             {
                  string str2 = "" ;
                  
                  for (int i=0 ; i<str.length() ; i++)
                  {
                      int x = ( ( ((int)str[i] - 65) + KEY ) % 26 ) + 65 ;
                      str2 += (char) x ;
                  }
                   
                   return str2 ;
             }
			
             string decryption (string str) 
             {
                  string str2 = "" ;
                  
                  for (int i=0 ; i<str.length() ; i++)
                  {
                      int x =  ( ( ((int)str[i] - 65) - KEY ) % 26 )  ;
			          x = (x<0) ? (26- abs(x)) : x ;
			          str2 += (char)x+65 ;
                   }
                   
                   return str2 ;
             }

             
};

int menu () ;

int main()
{
    CaesarCipher caesar ;
    
    bool state = true ;
    
    while (state)
    {
          switch ( menu() )
          {
                 case 1:
                      {
                      cout << "\nEnter The Plain Text : \n";
                      string str ;
                      char ch ;
                      
                      while ( (ch=getche()) != '\r'  )
                      {
                            if ( ch == ' ')
                               continue ;
                               
                            str += ch ;
                      }
                      
                      cout << "\nThe Plain Text  : " << str << endl;
                      cout << "\nThe Cipher Text : " << caesar.encryption(str) << endl;
                      break;
                      }
                      
                 case 2:
                      {
                      cout << "\nEnter The Cipher Text : \n";
                      string str = ""; 
                      char ch ;
                      
                      while ( (ch=getche()) != '\r'  )
                      {
                            if ( ch == ' ')
                               continue ;
                               
                            str += ch ;
                      }
                      
                      cout << "\nThe Cipher Text  : " << str << endl;
                      cout << "\nThe Plain  Text  : " << caesar.decryption(str) << endl;
                      
                      break;
                      }
                      
                 case 3:
                      {
                        state = false;
                        cout << "Good Luck !\n";
                        break;
                      }
                      
                 default:
                        cout << "Error Choice , Try Again !";
                        break;
                        
          }
          getch();
          system("cls");
    }
    
    cout << "\n\n";
    return 0;
}

int menu ()
{
    cout << "\t\t Caesar Cipher \n";
    cout << "\t\t-----------------\n";
    
    cout << "Encryption ................ [1]\n";
    cout << "Decryption ................ [2]\n";
    cout << "Exit Now   ................ [3]\n";
    cout << "\n \t >> " ;
    int choice ;
    
    cin >> choice ;
    
    return choice ;
}

    
          
