title: Time Complexity of Multi level Encryption and Decryption Algorithm
body: <p>In my project I have provided "Encryption and Decryption" through Multi Level algorithms. </p>
  
  <p>I used RSA and 3DES for this. Now I want to calculate its time complexity for performance analysis. I am a little bit confused here. How to exactly calculate it or what's the time complexity for it. </p>
  
  <p>Following is the Algo.</p>
  
  <p><strong>Helper Class</strong></p>
  
  <pre><code>class Helper{  
   public Cipher dcipher,ecipher;  
   public Helper(String passPhrase){  
      byte[] salt = 
        {  (byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,  
           (byte)0x56, (byte)0x34, (byte)0xE3, (byte)0x03  
        };  
      int iterationCount = 19;  
      try {    
            KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,                  
                      iterationCount);  
            SecretKey key =                                
                SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);  
            ecipher = Cipher.getInstance(key.getAlgorithm());  
            dcipher = Cipher.getInstance(key.getAlgorithm());  
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,
                                         iterationCount);  
            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);  
            dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);  
      } 
      catch(Exception e){ } 
  }  
  @SuppressWarnings("unused")  
  protected String encrypt(String str){  
          try{  
            byte[] utf8 = str.getBytes("UTF8");  
            byte[] enc = ecipher.doFinal(utf8);  
            return new sun.misc.BASE64Encoder().encode(enc);  
          } 
          catch (Exception e) {   } 
          return null;  
  }      
  // Decrpt password     
  //To decrypt the encryted password  
  protected String decrypt(String str) {  
    Cipher dcipher = null;  
    try{  
          byte[] salt = {(byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,(byte)0x56, 
                         (byte)0x34, (byte)0xE3, (byte)0x03};  
          int iterationCount = 19;  
        try{   
          String passPhrase="";  
          KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,
                          iterationCount);  
          SecretKey key = 
                SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);            
          dcipher = Cipher.getInstance(key.getAlgorithm());  
          // Prepare the parameters to the cipthers   
              AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, 
                                 iterationCount);  
          dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);  
        }   
    catch (Exception e) { 
              System.out.println("EXCEPTION: InvalidAlgorithmParameterException");  
        }  
        byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);  
        // Decrypt  
        byte[] utf8 = dcipher.doFinal(dec);  
        // Decode using utf-8  
        return new String(utf8, "UTF8");  
     }  
     catch (BadPaddingException e) {  
     } catch (IllegalBlockSizeException e) {  
     } catch (UnsupportedEncodingException e) {  
     } catch (IOException e){  
  }  
  return null;  
  }  
  </code></pre>
  
  <p><strong>MultilevelEnc Class</strong></p>
  
  <pre><code>public String Encrypt()
  {
  
      try
      {
          KeyPairGenerator kpg=KeyPairGenerator.getInstance("RSA");
          kpg.initialize(512);//initialize key pairs to 512 bits ,you can also take 1024 or 2048 bits
          kp=kpg.genKeyPair();
          PublicKey publi=kp.getPublic();
          Cipher cipher = Cipher.getInstance("RSA");
          cipher.init(Cipher.ENCRYPT_MODE, publi);
          byte[]src=srci.getBytes();//converting source data into byte array
          cipherData = cipher.doFinal(src);//use this method to finally encrypt data
          srco=new String(cipherData);//converting byte array into string
      }
      catch(Exception e)
      {
  
      }
          return srco;
  }
  public String Decrypt(String cipherdata)
      {
          try
          {
  
          PrivateKey privatei=kp.getPrivate();//Generating private key
          Cipher cipheri=Cipher.getInstance("RSA");//Intializing 2nd instance of Cipher class
          cipheri.init(Cipher.DECRYPT_MODE, privatei);//Setting to decrypt_mode
          byte[] cipherDat = cipheri.doFinal(cipherData);//Finally decrypting data
          decryptdata=new String(cipherDat);
          }
          catch(Exception e)
          {
              System.out.println(e.getMessage());
          }
          return decryptdata;
  }
  </code></pre>
  
  <p><strong>Main Class</strong></p>
  
  <pre><code>public static void main(String args[])
  {
      String odata = "abcd";
      String encdata2;
      String decrypt2;
      String decrypt1;
      MultilevelEnc r = new MultilevelEnc(odata);
      String encdata = r.Encrypt(); // RSA Algo Encryption        
      Helper h = new Helper("");
      encdata2 = h.encrypt(encdata);  // 3Des Algo Encryption
  
      decrypt2 = h.decrypt(encdata2); // 3Des Decryption
      decrypt1 = r.Decrypt(decrypt2);  // RSA Decryption
  }
  </code></pre>