Project… Encryption/Decryption?
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: cia • decrypt • encrypt • import java • jeb • job • main string • programmer • scanner system • string args
Filed under: crypto and decrypt
Like this post? Subscribe to my RSS feed and get loads more!
You need to make a class of course.
In that class, I would have constants, or final variables that contain the strings you need to change to and from.
You may want to use arrays to hold both the unencrypted string, eg ‘g’, and the encrypted string, eg ‘jeb..w’
Then in the encrypt method, you would use the replace method on String to replace the letters you find with the phrase you want. Be aware that you will have to search for both upper and lower case letters.
In the decrypt method, you would do the same, except in reverse. use the replace method to find the phrase and replace it with the letter.
Good luck with it.
So, what is your question?
False premise. Information security is the NSA’s responsibility; CIA gets their crypto from them.