About Me

Age:25 --- B.E.(Computer Science), Android/Java Developer, CCNA, CCNA SECURITY (IINS), CCNP (R&S), 4011 Recognized(NSA & CNSS)U.S.A. , MCSA, MCTS, REDHAT CERTIFIED NETWORK SECURITY ADMINISTRATOR(RH253), AFCEH.

Friday, July 12, 2013

Simple encryption and decryption of String using Java

       

	   public class EncryDB {

	// Method to encrypt the String

	private String encry(String str) {

		String result = "";

		int l = str.length();

		char ch;

		for (int i = 0; i < l; i++) {

			ch = str.charAt(i);

			// Adding of '$' to every character in the String

			ch += '$';

			result += ch;

		}

		return result;

	}

	// Method to decrypt the String

	private String decry(String str) {

		String result = "";

		int l = str.length();

		char ch;

		for (int i = 0; i < l; i++) {

			ch = str.charAt(i);

			// Subtracting of '$' from every character in the String

			ch -= '$';

			result += ch;

		}

		return result;

	}

	public static void main(String[] args) {

		EncryDB e = new EncryDB();

		String en = e.encry("Vivek");

		String de = e.decry(en);

		System.out.println("String Encrypted : " + en);

		System.out.println("String Decrypted : " + de);

	}

}

            
       
 

1 comment: