You have just been hired by the CIA as a programmer in the encryption department. Your job is
to write a class called Crypto. One method, encrypt, will accept a String that represents the sentence to be encrypted. It will return a String that is the sentence with all v’s (big or small)
replaced with “ag’,r”, all m’s (big or small) with “ssad”, all g’s (big or small) with “jeb..w”, and
all b’s (big or small) with “dug>?/”.
The class contains another method, decrypt, that accepts a String that represents the sentence to
be decrypted. In this method the reverse process described above is performed. It returns a String
that is the original sentence before encryption.
Use the following Tester class to insure that your methods work.
import java.io.*;
import java.util.*;
public class Tester
{
public static void main(String args[])
{
Scanner kbReader = new Scanner(System.in);
System.out.print(“Enter a sentence that is to be encrypted: ”);
String sntnc = kbReader.nextLine( );
System.out.println(“Original sentence = ” + sntnc);
Crypto myCryptObj = new Crypto( );
String encryptdSntnc = myCryptObj.encrypt(sntnc);
System.out.println(“Encrypted sentence = ” + encryptdSntnc);
String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc);
System.out.println(“Decrypted sentence = ” + decryptdSntnc);
}
}
Test with this sentence: “This is a very big morning.” After running your program, your screen
should appear as follows:
Enter a sentence that is to be encrypted: This is a very big morning.
Original sentence = This is a very big morning.
Encrypted sentence = This is a ag’,rery dug>?/ijeb..w ssadorninjeb..w.
Decrypted sentence = This is a very big morning.

Tagged with:

Filed under: crypto and decrypt

Like this post? Subscribe to my RSS feed and get loads more!