Loading
notes intro/old submit AP Problems the dump links
 

Interface Activity - Encryption

 

Create a class that implements the encryption interface below. The encryption can be anything but it needs to be easy enough that you could offline decrypt a message in less than 10 seconds without any resources (no cheat sheet). Ideas are:

  1. The encryption will write the phrase backwards (super weak)
  2. The encryption will replace all the I-1 and O-0 and B-8, S-5 and E-3
  3. The encryption will replace every letter will how far from a it is. Ie b would be 2 and so on. Put commas between letters. Use char(65) to convert the ascii int to a number
  4. For every group of three letters it reorders the first and third. IE scoreboard would be ocsberraod

Messages will be one word, all letters, all lower case (

public interface Encryption {
	/**
	 * Encrpyt will take in a message and return the message encrypted 
	 */
	public String encrypt (String word);
	
	/**
	 * Decrypt will take in an encrypted message and return the message decoded
	 */
	public String decrypt (String encryptedWord);

	/**
	 * This will return some info of the encryption method - it should include your names and if you want a hint or teaser
	 */
	public String encryptionInfo();
}
           
           

You can not save original word - that wont work.

 

Test it with code below (change Borland to whatever your is called):

 
	public static void main(String[] args) { 
	    // TODO Auto-generated method stub 
	    Encryption theEncryption=new BorlandsEncrypt();
   	    System.out.println(theEncryption.encryptionInfo());    
	    String originalWord="apples";
	    String encrypt=theEncryption.encrypt(originalWord);
     theEncryption.encrypt("garbage"); //thrown in so you cant save original word
	    System.out.println("Encrypting "+originalWord + " is " + encrypt);
	    String decrypt=theEncryption.decrypt(encrypt);
	    System.out.println("Decrypted is" + decrypt);
	    if (!originalWord.equals(decrypt))
	    	System.out.println("THIS ENCRYPTION DOESNT WORK");
	    else
	    	System.out.println("WORKS");
	}

Rubric: ( 8 points) - if it is not done in time, you lose 2 points.

  • encrypt works to encrypt a message ( 2.5 points)
  • not instantly obvious how you encrypted (2 points)
  • decrypt works to decrypt that message (2.5 points)
  • description of encryption does its job (1 point)

Bonus points:

  • +2 if no one can decrypt your message

For more testing: add to main

 

	String randomPhrases[]={"sand","confuse","brown","preserves","cathey","bombs","submarines"};
for (int i=0;i<randomPhrases.length;i++)	
	{			
		String text=randomPhrases[i];
		String en=theEncryption.encrypt(text);
		String dc=theEncryption.decrypt(en);
		if (!dc.equals(text))
			dc="ERROR:"+dc;
		System.out.println(dc +"    :   "+ en);
	}