Saturday, August 14, 2010

My Agent Security Scenario: The Code-Decrypt Class


/*
Receive the message from encrypt Aglet 
and do decryption operation 
*/
//examples is the name of the folder where the all ASDK(Agent
//software development kit) Java mobile agents resides
//Sec is the sub folder at the examples folder , contains the 
//java classes of my project
package examples.Sec;
//The package of com.ibm.aglet reused from the ASDK  
//to have * after package name means to be able to 
//reuse all the package classes in your project
import com.ibm.aglet.*;
//The Decrypt Aglet inherited from the subclass (remember 
//base class concept if you are C\C++ programmer) Aglet
public class Decrypt extends Aglet
{
 public String userName;
 public String Password;
 public boolean handleMessage(Message secretInfo)
 {
     if(secretInfo.sameKind("secretInformation"))
  {
    
    userName=new String((String)secretInfo.getArg("User Name"));
    Global.array_char=userName.toCharArray();
    Decrypt();
    userName="";
    userName=Global.array_in_string();
    System.out.println("User Name after Decryption : "+userName);
    /////////////////////////////////////////
    Password=new String((String)secretInfo.getArg("Password"));
    Global.array_char=Password.toCharArray();
    Decrypt();
    Password="";
    Password=Global.array_in_string();
    System.out.println("Password after Decryption : "+Password);
    System.out.println();
    dispose();
    return true;
  }
  return false;
 }
 public void Decrypt()
 {
  Global.array_int=new int[10];
     for(int h1=0;h1<Global.array_char.length;h1++)
  {
   
   Global.array_int[h1]=(int)Global.array_char[h1];
   if(Global.array_int[h1]>=65&&Global.array_int[h1]<=90)
   {
    if((Global.array_int[h1]-3)<65)
    {
     Global.array_int[h1]=Global.array_int[h1]-3;
     Global.array_int[h1]=65-Global.array_int[h1];
     Global.array_int[h1]=91-Global.array_int[h1];
     Global.array_char[h1]=(char)Global.array_int[h1];
    }
    else
    {
     Global.array_int[h1]=Global.array_int[h1]-3;
     Global.array_char[h1]=(char)Global.array_int[h1];
    }    
   }
   else if(Global.array_int[h1]>=97&&Global.array_int[h1]<=122)
   {
    if((Global.array_int[h1]-3)<97)
    {
     Global.array_int[h1]=Global.array_int[h1]-3;
     Global.array_int[h1]=97-Global.array_int[h1];
     Global.array_int[h1]=123-Global.array_int[h1];
     Global.array_char[h1]=(char)Global.array_int[h1];
    }else
    {
     Global.array_int[h1]=Global.array_int[h1]-3;
     Global.array_char[h1]=(char)Global.array_int[h1];
    }    
   }
   else Global.array_char[h1]=(char)Global.array_int[h1];
  }
 }
}

No comments:

Post a Comment