diff --git a/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java b/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java new file mode 100644 index 0000000..c2bddcd --- /dev/null +++ b/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestHill.java @@ -0,0 +1,91 @@ +//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/polySubstitution/TestHill.java +//Mattrixwv +// Created: 01-31-22 +//Modified: 02-11-22 +package com.mattrixwv.CipherStreamJava.polySubstitution; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + + +public class TestHill{ + @Test + public void testEncode(){ + 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"; + 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"; + 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"; + 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"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed symbol 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"; + output = cipher.encode(key, inputString); + assertEquals("Hill failed mixed case, whitespace, and symbol encoding.", correctOutput, output); + } + + @Test + public void testDecode(){ + 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 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}}; + 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}}; + 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}}; + 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}}; + correctOutput = "Message to^encode"; + output = cipher.decode(key, inputString); + assertEquals("Hill failed mixed case, whitespace, and symbol decoding.", correctOutput, output); + } +}