From eca3c130ed513f2e69d5cb3c4a41252d5c6d0a57 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 17 Feb 2022 21:39:48 +0000 Subject: [PATCH] Finished implementing Hill cipher --- .../polySubstitution/TestHill.java | 484 +++++++++++++++++- 1 file changed, 461 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java b/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java index c2bddcd..b82ac2e 100644 --- a/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java +++ b/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java @@ -1,91 +1,529 @@ //CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/polySubstitution/TestHill.java //Mattrixwv // Created: 01-31-22 -//Modified: 02-11-22 +//Modified: 02-17-22 package com.mattrixwv.CipherStreamJava.polySubstitution; import static org.junit.Assert.assertEquals; +import java.security.InvalidKeyException; + +import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException; +import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException; + import org.junit.Test; public class TestHill{ @Test - public void testEncode(){ + public void testEncode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ Hill cipher = new Hill(true, true, true, true); //Test lowercase encoding String inputString = "messagetoencode"; - int[][] key = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; - String correctOutput = "yikkamimciaecgi"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "mgkeqgeulikhisp"; String output = cipher.encode(key, inputString); assertEquals("Hill failed lowercase encoding.", correctOutput, output); //Test uppercase encoding inputString = "MESSAGETOENCODE"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; - correctOutput = "YIKKAMIMCIAECGI"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; output = cipher.encode(key, inputString); assertEquals("Hill failed uppercase encoding.", correctOutput, output); //Test whitespace encoding inputString = "message to encode"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; - correctOutput = "yikkami mc iaecgi"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge ul ikhisp"; output = cipher.encode(key, inputString); assertEquals("Hill failed whitespace encoding.", correctOutput, output); //Test symbol encoding inputString = "message*to+encode"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; - correctOutput = "yikkami*mc+iaecgi"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge*ul+ikhisp"; output = cipher.encode(key, inputString); assertEquals("Hill failed symbol encoding.", correctOutput, output); + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhul"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed padding encoding.", correctOutput, output); + //Test mixed case, whitespace, and symbol encoding inputString = "Message to^encode"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; - correctOutput = "Yikkami mc^iaecgi"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Mgkeqge ul^ikhisp"; output = cipher.encode(key, inputString); assertEquals("Hill failed mixed case, whitespace, and symbol encoding.", correctOutput, output); } @Test - public void testDecode(){ + public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(false, true, true, true); + + //Test lowercase encoding + String inputString = "messagetoencode"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "MGKEQGEULIKHISP"; + String output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital lowercase encoding.", correctOutput, output); + //Test uppercase encoding + inputString = "MESSAGETOENCODE"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital uppercase encoding.", correctOutput, output); + + //Test whitespace encoding + inputString = "message to encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGE UL IKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital whitespace encoding.", correctOutput, output); + + //Test symbol encoding + inputString = "message*to+encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGE*UL+IKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital symbol encoding.", correctOutput, output); + + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHUL"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital padding encoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol encoding + inputString = "Message to^encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGE UL^IKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + @Test + public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, false, true, true); + + //Test lowercase encoding + String inputString = "messagetoencode"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "mgkeqgeulikhisp"; + String output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace lowercase encoding.", correctOutput, output); + //Test uppercase encoding + inputString = "MESSAGETOENCODE"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace uppercase encoding.", correctOutput, output); + + //Test whitespace encoding + inputString = "message to encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace whitespace encoding.", correctOutput, output); + + //Test symbol encoding + inputString = "message*to+encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge*ul+ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace symbol encoding.", correctOutput, output); + + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhul"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace padding encoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol encoding + inputString = "Message to^encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Mgkeqgeul^ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + @Test + public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, true, false, true); + + //Test lowercase encoding + String inputString = "messagetoencode"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "mgkeqgeulikhisp"; + String output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol lowercase encoding.", correctOutput, output); + //Test uppercase encoding + inputString = "MESSAGETOENCODE"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol uppercase encoding.", correctOutput, output); + + //Test whitespace encoding + inputString = "message to encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge ul ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol whitespace encoding.", correctOutput, output); + + //Test symbol encoding + inputString = "message*to+encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol symbol encoding.", correctOutput, output); + + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhul"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol padding encoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol encoding + inputString = "Message to^encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Mgkeqge ulikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + @Test + public void testNoPaddingEncoding() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, true, true, false); + + //Test lowercase encoding + String inputString = "messagetoencode"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "mgkeqgeulikhisp"; + String output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding lowercase encoding.", correctOutput, output); + //Test uppercase encoding + inputString = "MESSAGETOENCODE"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding uppercase encoding.", correctOutput, output); + + //Test whitespace encoding + inputString = "message to encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge ul ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding whitespace encoding.", correctOutput, output); + + //Test symbol encoding + inputString = "message*to+encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqge*ul+ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding symbol encoding.", correctOutput, output); + + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "mgkeqgeulikhulb"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding padding encoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol encoding + inputString = "Message to^encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Mgkeqge ul^ikhisp"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed no padding mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + @Test + public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(false, false, false, false); + + //Test lowercase encoding + String inputString = "messagetoencode"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "MGKEQGEULIKHISP"; + String output = cipher.encode(key, inputString); + assertEquals("Hill failed secure lowercase encoding.", correctOutput, output); + //Test uppercase encoding + inputString = "MESSAGETOENCODE"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed secure uppercase encoding.", correctOutput, output); + + //Test whitespace encoding + inputString = "message to encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed secure whitespace encoding.", correctOutput, output); + + //Test symbol encoding + inputString = "message*to+encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed secure symbol encoding.", correctOutput, output); + + //Test padding encoding + inputString = "messagetoencod"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHULB"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed secure padding encoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol encoding + inputString = "Message to^encode"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MGKEQGEULIKHISP"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + + @Test + public void testDecode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ Hill cipher = new Hill(true, true, true, true); //Test lowercase decoding - String inputString = "yikkamimciaecgi"; - int[][] key = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; String correctOutput = "messagetoencode"; String output = cipher.decode(key, inputString); assertEquals("Hill failed lowercase decoding.", correctOutput, output); //Test uppercase decoding - inputString = "YIKKAMIMCIAECGI"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; correctOutput = "MESSAGETOENCODE"; output = cipher.decode(key, inputString); assertEquals("Hill failed uppercase decoding.", correctOutput, output); //Test whitespace decoding - inputString = "yikkami mc iaecgi"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; correctOutput = "message to encode"; output = cipher.decode(key, inputString); assertEquals("Hill failed whitespace decoding.", correctOutput, output); //Test symbol decoding - inputString = "yikkami*mc+iaecgi"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; correctOutput = "message*to+encode"; output = cipher.decode(key, inputString); assertEquals("Hill failed symbol decoding.", correctOutput, output); //Test mixed case, whitespace, and symbol decoding - inputString = "Yikkami mc^iaecgi"; - key = new int[][]{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; correctOutput = "Message to^encode"; output = cipher.decode(key, inputString); assertEquals("Hill failed mixed case, whitespace, and symbol decoding.", correctOutput, output); } + + @Test + public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(false, true, true, true); + + //Test lowercase decoding + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "MESSAGETOENCODE"; + String output = cipher.decode(key, inputString); + assertEquals("Hill failed no capital lowercase decoding.", correctOutput, output); + //Test uppercase decoding + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no capital uppercase decoding.", correctOutput, output); + + //Test whitespace decoding + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGE TO ENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no capital whitespace decoding.", correctOutput, output); + + //Test symbol decoding + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGE*TO+ENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no capital symbol decoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol decoding + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGE TO^ENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output); + } + + @Test + public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, false, true, true); + + //Test lowercase decoding + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "messagetoencode"; + String output = cipher.decode(key, inputString); + assertEquals("Hill failed no whitespace lowercase decoding.", correctOutput, output); + //Test uppercase decoding + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no whitespace uppercase decoding.", correctOutput, output); + + //Test whitespace decoding + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "messagetoencode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no whitespace whitespace decoding.", correctOutput, output); + + //Test symbol decoding + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "message*to+encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no whitespace symbol decoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol decoding + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Messageto^encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output); + } + + @Test + public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, true, false, true); + + //Test lowercase decoding + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "messagetoencode"; + String output = cipher.decode(key, inputString); + assertEquals("Hill failed no symbol lowercase decoding.", correctOutput, output); + //Test uppercase decoding + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no symbol uppercase decoding.", correctOutput, output); + + //Test whitespace decoding + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "message to encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no symbol whitespace decoding.", correctOutput, output); + + //Test symbol decoding + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "messagetoencode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no symbol symbol decoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol decoding + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Message toencode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output); + } + + @Test + public void testNoPaddingDecoding() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(true, true, true, false); + + //Test lowercase decoding + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "messagetoencode"; + String output = cipher.decode(key, inputString); + assertEquals("Hill failed no padding lowercase decoding.", correctOutput, output); + //Test uppercase decoding + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no padding uppercase decoding.", correctOutput, output); + + //Test whitespace decoding + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "message to encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no padding whitespace decoding.", correctOutput, output); + + //Test symbol decoding + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "message*to+encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no padding symbol decoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol decoding + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "Message to^encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed no padding mixed case, whitespace, and symbol decoding.", correctOutput, output); + } + + @Test + public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeyException, InvalidInputException{ + Hill cipher = new Hill(false, false, false, false); + + //Test lowercase decoding + String inputString = "mgkeqgeulikhisp"; + int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + String correctOutput = "MESSAGETOENCODE"; + String output = cipher.decode(key, inputString); + assertEquals("Hill failed secure lowercase decoding.", correctOutput, output); + //Test uppercase decoding + inputString = "MGKEQGEULIKHISP"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed secure uppercase decoding.", correctOutput, output); + + //Test whitespace decoding + inputString = "mgkeqge ul ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed secure whitespace decoding.", correctOutput, output); + + //Test symbol decoding + inputString = "mgkeqge*ul+ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed secure symbol decoding.", correctOutput, output); + + //Test mixed case, whitespace, and symbol decoding + inputString = "Mgkeqge ul^ikhisp"; + key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}}; + correctOutput = "MESSAGETOENCODE"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output); + } }