From cf183c1bdad99de2a65a260a22fcbd77e6c1e9c8 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Thu, 30 Dec 2021 16:07:16 -0500 Subject: [PATCH] Merge --- pom.xml | 186 ++++++------- .../mattrixwv/CipherStreamJava/Atbash.java | 40 +-- .../mattrixwv/CipherStreamJava/Caesar.java | 32 +-- .../mattrixwv/CipherStreamJava/Morse.java | 5 +- .../mattrixwv/CipherStreamJava/Vigenere.java | 1 + .../CipherStreamJava/TestAtbash.java | 10 +- .../CipherStreamJava/TestCaesar.java | 250 +----------------- .../mattrixwv/CipherStreamJava/TestMorse.java | 118 ++++----- .../CipherStreamJava/TestVigenere.java | 130 ++++----- 9 files changed, 248 insertions(+), 524 deletions(-) diff --git a/pom.xml b/pom.xml index 0d309af..65d1499 100644 --- a/pom.xml +++ b/pom.xml @@ -1,93 +1,93 @@ - - - - 4.0.0 - - mattrixwv - CipherStreamJava - 1.0-SNAPSHOT - - CipherStreamJava - http://www.mattrixwv.com - - - UTF-8 - 14 - 14 - - - - - junit - junit - 4.13.2 - test - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - enforce-maven - - enforce - - - - - 3.6.3 - - - - - - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.2.0 - - - maven-compiler-plugin - 3.8.1 - - - maven-surefile-plugin - 3.0.0-M5 - - - maven-jar-plugin - 3.2.0 - - - maven-install-plugin - 3.0.0-M1 - - - maven-deploy-plugin - 3.0.0-M1 - - - - maven-site-plugin - 3.9.1 - - - maven-project-info-reports-plugin - 3.1.1 - - - - + + + + 4.0.0 + + mattrixwv + CipherStreamJava + 1.0-SNAPSHOT + + CipherStreamJava + http://www.mattrixwv.com + + + UTF-8 + 14 + 14 + + + + + junit + junit + 4.13.2 + test + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + enforce-maven + + enforce + + + + + 3.6.3 + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.2.0 + + + maven-compiler-plugin + 3.8.1 + + + maven-surefile-plugin + 3.0.0-M5 + + + maven-jar-plugin + 3.2.0 + + + maven-install-plugin + 3.0.0-M1 + + + maven-deploy-plugin + 3.0.0-M1 + + + + maven-site-plugin + 3.9.1 + + + maven-project-info-reports-plugin + 3.1.1 + + + + diff --git a/src/main/java/mattrixwv/CipherStreamJava/Atbash.java b/src/main/java/mattrixwv/CipherStreamJava/Atbash.java index 461a1ab..97060c5 100644 --- a/src/main/java/mattrixwv/CipherStreamJava/Atbash.java +++ b/src/main/java/mattrixwv/CipherStreamJava/Atbash.java @@ -1,16 +1,15 @@ //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Atbash.java //Matthew Ellison // Created: 07-25-21 -//Modified: 12-25-21 +//Modified: 07-25-21 //This is the declaration of the Atbash class package mattrixwv.CipherStreamJava; public class Atbash{ + public static final String version = "1.0"; private String inputString; //Holds the string that needs encoded or decoded - private String outputString; //The encoded/decoded string - private boolean leaveCapitals; //Whether to respect capitals in the output string - private boolean leaveWhitespace; //Whether to respect whitespace in the output string + private String outputString; //Holds teh current version of the library //Decodes inputString and stores in outputString private String decode(){ StringBuilder output = new StringBuilder(); @@ -27,16 +26,7 @@ public class Atbash{ StringBuilder output = new StringBuilder(); //Step through every element in the inputString and shift it the correct amount for(int cnt = 0;cnt < inputString.length();++cnt){ - //Skip any whitespace - if(Character.isWhitespace(inputString.charAt(cnt))){ - continue; - } - //Use either uppercase or lowercase for the base - char letterBase = 'a'; - if(Character.isUpperCase(inputString.charAt(cnt))){ - letterBase = 'A'; - } - output.append((char)(inputString.charAt(cnt) + 25 - (2 * (inputString.charAt(cnt) - letterBase)))); + output.append((char)(inputString.charAt(cnt) + 25 - (2 * (inputString.charAt(cnt) - 'A')))); } outputString = output.toString(); @@ -44,29 +34,15 @@ public class Atbash{ } //Removes all invalid characters and sets inputString private void setInputString(String input){ - if(!leaveCapitals){ - //Convert all letters to uppercase - input = input.toUpperCase(); - } - if(!leaveWhitespace){ - //Remove all characters except capital letters - input = input.toLowerCase(); - } + //Convert all letters to uppercase + input = input.toUpperCase(); + //Remove all characters except capital letters + input = input.replaceAll("[^A-Z]", ""); //Save the string inputString = input; } - public Atbash(){ - reset(); - leaveCapitals = false; - leaveWhitespace = false; - } - public Atbash(boolean leaveCapitals, boolean leaveWhitespace){ - reset(); - this.leaveCapitals = leaveCapitals; - this.leaveWhitespace = leaveWhitespace; - } public String getInputString(){ return inputString; } diff --git a/src/main/java/mattrixwv/CipherStreamJava/Caesar.java b/src/main/java/mattrixwv/CipherStreamJava/Caesar.java index 2cfd777..45e991a 100644 --- a/src/main/java/mattrixwv/CipherStreamJava/Caesar.java +++ b/src/main/java/mattrixwv/CipherStreamJava/Caesar.java @@ -1,17 +1,16 @@ //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Caesar.java //Matthew Ellison // Created: 07-25-21 -//Modified: 12-25-21 +//Modified: 07-25-21 //This is the declaration of the Caesar class package mattrixwv.CipherStreamJava; public class Caesar{ + public static final String version = "1.0"; //The current version number for the library private String inputString; //The string that needs encoded/decoded private String outputString; //The encoded/decoded string private int shift; //The amount that you need to shift each letter - private boolean leaveCapitals; //Whether to respect capitals in the output string - private boolean leaveWhitespace; //Whether to respect whitespace in the output string //Sets shift and makes sure it is within the propper bounds private void setShift(int shiftAmount){ //If you shift more than 26 you will just be wrapping back around again @@ -19,12 +18,6 @@ public class Caesar{ } //Sets the input string private void setInputString(String inputString){ - if(!leaveCapitals){ - inputString = inputString.toLowerCase(); - } - if(!leaveWhitespace){ - inputString = inputString.replaceAll("\\s+", ""); - } this.inputString = inputString; } //Encodes the inputString and stores the result in outputString @@ -99,13 +92,6 @@ public class Caesar{ //Constructor public Caesar(){ reset(); - leaveCapitals = false; - leaveWhitespace = false; - } - public Caesar(boolean leaveCapitals, boolean leaveWhitespace){ - reset(); - this.leaveCapitals = leaveCapitals; - this.leaveWhitespace = leaveWhitespace; } //Returns the inputString public String getInputString(){ @@ -119,20 +105,6 @@ public class Caesar{ public String getOutputString(){ return outputString; } - //Returns if capitals should be respected in the output - public boolean getLeaveCapitals(){ - return leaveCapitals; - } - public void setLeaveCapitals(boolean leaveCapitals){ - this.leaveCapitals = leaveCapitals; - } - //Returns if whitespace should be respected in the output - public boolean getLeaveWhitespace(){ - return leaveWhitespace; - } - public void setLeaveWhitespace(boolean leaveWhitespace){ - this.leaveWhitespace = leaveWhitespace; - } //Sets the shift and inputString and encodes the message public String encode(int shiftAmount, String inputString){ reset(); diff --git a/src/main/java/mattrixwv/CipherStreamJava/Morse.java b/src/main/java/mattrixwv/CipherStreamJava/Morse.java index f5fdbe2..d74cd30 100644 --- a/src/main/java/mattrixwv/CipherStreamJava/Morse.java +++ b/src/main/java/mattrixwv/CipherStreamJava/Morse.java @@ -1,7 +1,7 @@ //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Morse.java //Matthew Ellison -// Created: 07-26-21 -//Modified: 07-26-21 +// Created: 07-28-21 +//Modified: 07-28-21 //This is the declaration of the Morse class package mattrixwv.CipherStreamJava; @@ -13,6 +13,7 @@ public class Morse{ "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", //M-Z "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." //0-9 }; + public static final String version = "1.0"; //The current library's version private String inputString; //The string that needs encoded/decoded private String outputString; //The encoded/decoded message diff --git a/src/main/java/mattrixwv/CipherStreamJava/Vigenere.java b/src/main/java/mattrixwv/CipherStreamJava/Vigenere.java index 9d73600..5b07e45 100644 --- a/src/main/java/mattrixwv/CipherStreamJava/Vigenere.java +++ b/src/main/java/mattrixwv/CipherStreamJava/Vigenere.java @@ -8,6 +8,7 @@ package mattrixwv.CipherStreamJava; import java.util.ArrayList; public class Vigenere{ + public static final String version = "1.0"; //The current library's version number protected String inputString; //This is the string that needs encoded/decoded protected String outputString; //This is the string that is output after encoding/decoding protected String keyword; //This is the keyword that is resposible for determining the offsets that you change each character by diff --git a/src/test/java/mattrixwv/CipherStreamJava/TestAtbash.java b/src/test/java/mattrixwv/CipherStreamJava/TestAtbash.java index daa09ee..60bd228 100644 --- a/src/test/java/mattrixwv/CipherStreamJava/TestAtbash.java +++ b/src/test/java/mattrixwv/CipherStreamJava/TestAtbash.java @@ -1,7 +1,7 @@ //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestAtbash.java //Matthew Ellison // Created: 07-25-21 -//Modified: 12-25-21 +//Modified: 07-25-21 //These are the tests for the Atbash class package mattrixwv.CipherStreamJava; @@ -18,13 +18,13 @@ public class TestAtbash{ //Test 1 String input = "zyx"; - String correctOutput = "abc"; + String correctOutput = "ABC"; String output = cipher.decode(input); assertEquals("Atbash Decoding failed the first test", correctOutput, output); //Test 2 input = "GSV JFRXP YILDM ULC QFNKH LEVI - GSV OZAB WLT"; - correctOutput = "thequickbrownfoxjumpsoverthelazydog"; + correctOutput = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG"; output = cipher.decode(input); assertEquals("Atbash Decoding failed the second test", correctOutput, output); } @@ -34,13 +34,13 @@ public class TestAtbash{ //Test 1 String input = "abc"; - String correctOutput = "zyx"; + String correctOutput = "ZYX"; String output = cipher.encode(input); assertEquals("Atbash Encoding failed the first test", correctOutput, output); //Test 2 input = "The quick brown fox jumps over - the lazy dog"; - correctOutput = "gsvjfrxpyildmulcqfnkhlevigsvozabwlt"; + correctOutput = "GSVJFRXPYILDMULCQFNKHLEVIGSVOZABWLT"; output = cipher.encode(input); assertEquals("Atbash Encoding failed the second test", correctOutput, output); } diff --git a/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java b/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java index 9631b78..f9bebb1 100644 --- a/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java +++ b/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java @@ -1,7 +1,7 @@ -//CipherStreamJava/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java +//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestCaesar.java //Matthew Ellison // Created: 07-25-21 -//Modified: 12-25-21 +//Modified: 07-25-21 //These are the tests for the Caesar class package mattrixwv.CipherStreamJava; @@ -14,7 +14,7 @@ import org.junit.Test; public class TestCaesar{ @Test public void testDecode(){ - Caesar cipher = new Caesar(true, true); + Caesar cipher = new Caesar(); //Test 1 String input = "def"; @@ -28,139 +28,24 @@ public class TestCaesar{ correctOutput = "abc"; output = cipher.decode(shift, input); assertEquals("Caesar Decoding failed the second test", correctOutput, output); - //Test 3 - input = "DEF"; - shift = 3; - correctOutput = "ABC"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the third test", correctOutput, output); - //Test 4 + //Test 3 input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; shift = -3; correctOutput = "The quick brown fox jumps over - the lazy dog"; output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fourth test", correctOutput, output); - //Test 5 + assertEquals("Caesar Decoding failed the third test", correctOutput, output); + //Test 4 input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; shift = 23; correctOutput = "The quick brown fox jumps over - the lazy dog"; output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fifth test", correctOutput, output); - } - @Test - public void testNoWhitespaceDecode(){ - Caesar cipher = new Caesar(true, false); - - //Test 1 - String input = "def"; - int shift = 3; - String correctOutput = "abc"; - String output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the first test", correctOutput, output); - //Test 2 - input = "def"; - shift = 29; - correctOutput = "abc"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the second test", correctOutput, output); - //Test 3 - input = "DEF"; - shift = 3; - correctOutput = "ABC"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the third test", correctOutput, output); - - //Test 4 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = -3; - correctOutput = "Thequickbrownfoxjumpsover-thelazydog"; - output = cipher.decode(shift, input); assertEquals("Caesar Decoding failed the fourth test", correctOutput, output); - //Test 5 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = 23; - correctOutput = "Thequickbrownfoxjumpsover-thelazydog"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fifth test", correctOutput, output); } - @Test - public void testNoCapitalDecode(){ - Caesar cipher = new Caesar(false, true); - - //Test 1 - String input = "def"; - int shift = 3; - String correctOutput = "abc"; - String output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the first test", correctOutput, output); - //Test 2 - input = "def"; - shift = 29; - correctOutput = "abc"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the second test", correctOutput, output); - //Test 3 - input = "DEF"; - shift = 3; - correctOutput = "abc"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the third test", correctOutput, output); - - //Test 4 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = -3; - correctOutput = "the quick brown fox jumps over - the lazy dog"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fourth test", correctOutput, output); - //Test 5 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = 23; - correctOutput = "the quick brown fox jumps over - the lazy dog"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fifth test", correctOutput, output); - } - @Test - public void testNoCapitalWhitespaceDecode(){ - Caesar cipher = new Caesar(false, false); - - //Test 1 - String input = "def"; - int shift = 3; - String correctOutput = "abc"; - String output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the first test", correctOutput, output); - //Test 2 - input = "def"; - shift = 29; - correctOutput = "abc"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the second test", correctOutput, output); - //Test 3 - input = "DEF"; - shift = 3; - correctOutput = "abc"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the third test", correctOutput, output); - - //Test 4 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = -3; - correctOutput = "thequickbrownfoxjumpsover-thelazydog"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fourth test", correctOutput, output); - //Test 5 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = 23; - correctOutput = "thequickbrownfoxjumpsover-thelazydog"; - output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the fifth test", correctOutput, output); - } - @Test public void testEncode(){ //Test 1 - Caesar cipher = new Caesar(true, true); + Caesar cipher = new Caesar(); String input = "abc"; int shift = 3; String correctOutput = "def"; @@ -171,130 +56,19 @@ public class TestCaesar{ shift = 29; correctOutput = "def"; output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the second test", correctOutput, output); - //Test 3 - input = "ABC"; - shift = 3; - correctOutput = "DEF"; - output = cipher.encode(shift, input); - assertEquals("Ceasar Encoding failed the third test", correctOutput, output); + assertEquals("Caesar Encoding failed the second test - Expected: " + correctOutput + "; actual" + output, correctOutput, output); - //Test 4 + //Test 3 input = "The quick brown fox jumps over - the lazy dog"; shift = -3; correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fourth test", correctOutput, output); - //Test 5 + assertEquals("Caesar Encoding failed the third test", correctOutput, output); + //Test 4 input = "The quick brown fox jumps over - the lazy dog"; shift = 23; correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fifth test", correctOutput, output); - } - @Test - public void testNoWhitespaceEncode(){ - //Test 1 - Caesar cipher = new Caesar(true, false); - String input = "abc"; - int shift = 3; - String correctOutput = "def"; - String output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the first test", correctOutput, output); - //Test 2 - input = "abc"; - shift = 29; - correctOutput = "def"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the second test", correctOutput, output); - //Test 3 - input = "ABC"; - shift = 3; - correctOutput = "DEF"; - output = cipher.encode(shift, input); - assertEquals("Ceasar Encoding failed the third test", correctOutput, output); - - //Test 4 - input = "The quick brown fox jumps over - the lazy dog"; - shift = -3; - correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fourth test", correctOutput, output); - //Test 5 - input = "The quick brown fox jumps over - the lazy dog"; - shift = 23; - correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fifth test", correctOutput, output); - } - @Test - public void testNoCapitalEncode(){ - //Test 1 - Caesar cipher = new Caesar(false, true); - String input = "abc"; - int shift = 3; - String correctOutput = "def"; - String output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the first test", correctOutput, output); - //Test 2 - input = "abc"; - shift = 29; - correctOutput = "def"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the second test", correctOutput, output); - //Test 3 - input = "ABC"; - shift = 3; - correctOutput = "def"; - output = cipher.encode(shift, input); - assertEquals("Ceasar Encoding failed the third test", correctOutput, output); - - //Test 4 - input = "The quick brown fox jumps over - the lazy dog"; - shift = -3; - correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fourth test", correctOutput, output); - //Test 5 - input = "The quick brown fox jumps over - the lazy dog"; - shift = 23; - correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fifth test", correctOutput, output); - } - @Test - public void testNoCapitalWhitespaceEncode(){ - //Test 1 - Caesar cipher = new Caesar(false, false); - String input = "abc"; - int shift = 3; - String correctOutput = "def"; - String output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the first test", correctOutput, output); - //Test 2 - input = "abc"; - shift = 29; - correctOutput = "def"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the second test", correctOutput, output); - //Test 3 - input = "ABC"; - shift = 3; - correctOutput = "def"; - output = cipher.encode(shift, input); - assertEquals("Ceasar Encoding failed the third test", correctOutput, output); - - //Test 4 - input = "The quick brown fox jumps over - the lazy dog"; - shift = -3; - correctOutput = "qebnrfzhyoltkclugrjmplsbo-qebixwvald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fourth test", correctOutput, output); - //Test 5 - input = "The quick brown fox jumps over - the lazy dog"; - shift = 23; - correctOutput = "qebnrfzhyoltkclugrjmplsbo-qebixwvald"; - output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the fifth test", correctOutput, output); + assertEquals("Caesar Encoding failed the third test", correctOutput, output); } } diff --git a/src/test/java/mattrixwv/CipherStreamJava/TestMorse.java b/src/test/java/mattrixwv/CipherStreamJava/TestMorse.java index bb5ecfd..ce855c5 100644 --- a/src/test/java/mattrixwv/CipherStreamJava/TestMorse.java +++ b/src/test/java/mattrixwv/CipherStreamJava/TestMorse.java @@ -1,59 +1,59 @@ -//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestVigenere.java -//Matthew Ellison -// Created: 07-25-21 -//Modified: 07-25-21 -//These are the tests for the Vigenere class -package mattrixwv.CipherStreamJava; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - - -public class TestMorse{ - @Test - public void testDecode(){ - Morse cipher = new Morse(); - - //Test 1 - String input = "... --- ..."; - String correctOutput = "SOS"; - String output = cipher.decode(input); - assertEquals("Morse Decoding failed the first test", correctOutput, output); - - //Test 2 - input = "-- --- .-. ... . -.-. --- -.. ."; - correctOutput = "MORSECODE"; - output = cipher.decode(input); - assertEquals("Morse Decoding failed the second test", correctOutput, output); - - //Test 3 - input = ".---- ..--- ...-- ----. ---.. --..."; - correctOutput = "123987"; - output = cipher.decode(input); - assertEquals("Morse Decoding failed the third test", correctOutput, output); - } - @Test - public void testEncode(){ - Morse cipher = new Morse(); - - //Test 1 - String input = "sos"; - String correctOutput = "... --- ..."; - String output = cipher.encode(input); - assertEquals("Morse Encoding failed the first test", correctOutput, output); - - //Test 2 - input = "MORSE, CODE"; - correctOutput = "-- --- .-. ... . -.-. --- -.. ."; - output = cipher.encode(input); - assertEquals("Morse Encoding failed the second test", correctOutput, output); - - //Test 3 - input = "1.23 987"; - correctOutput = ".---- ..--- ...-- ----. ---.. --..."; - output = cipher.encode(input); - assertEquals("Morse Encoding failed the third test", correctOutput, output); - } -} +//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestMorse.java +//Matthew Ellison +// Created: 07-28-21 +//Modified: 07-28-21 +//These are the tests for the Morse class +package mattrixwv.CipherStreamJava; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + + +public class TestMorse{ + @Test + public void testDecode(){ + Morse cipher = new Morse(); + + //Test 1 + String input = "... --- ..."; + String correctOutput = "SOS"; + String output = cipher.decode(input); + assertEquals("Morse Decoding failed the first test", correctOutput, output); + + //Test 2 + input = "-- --- .-. ... . -.-. --- -.. ."; + correctOutput = "MORSECODE"; + output = cipher.decode(input); + assertEquals("Morse Decoding failed the second test", correctOutput, output); + + //Test 3 + input = ".---- ..--- ...-- ----. ---.. --..."; + correctOutput = "123987"; + output = cipher.decode(input); + assertEquals("Morse Decoding failed the third test", correctOutput, output); + } + @Test + public void testEncode(){ + Morse cipher = new Morse(); + + //Test 1 + String input = "sos"; + String correctOutput = "... --- ..."; + String output = cipher.encode(input); + assertEquals("Morse Encoding failed the first test", correctOutput, output); + + //Test 2 + input = "MORSE, CODE"; + correctOutput = "-- --- .-. ... . -.-. --- -.. ."; + output = cipher.encode(input); + assertEquals("Morse Encoding failed the second test", correctOutput, output); + + //Test 3 + input = "1.23 987"; + correctOutput = ".---- ..--- ...-- ----. ---.. --..."; + output = cipher.encode(input); + assertEquals("Morse Encoding failed the third test", correctOutput, output); + } +} diff --git a/src/test/java/mattrixwv/CipherStreamJava/TestVigenere.java b/src/test/java/mattrixwv/CipherStreamJava/TestVigenere.java index 14ec239..490c5ef 100644 --- a/src/test/java/mattrixwv/CipherStreamJava/TestVigenere.java +++ b/src/test/java/mattrixwv/CipherStreamJava/TestVigenere.java @@ -1,65 +1,65 @@ -//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestVigenere.java -//Matthew Ellison -// Created: 07-25-21 -//Modified: 07-25-21 -//These are the tests for the Vigenere class -package mattrixwv.CipherStreamJava; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - - -public class TestVigenere{ - @Test - public void testDecode() throws Exception{ - Vigenere cipher = new Vigenere(); - - //Test 1 - String input = "xzb"; - String keyword = "xyz"; - String correctOutput = "ABC"; - String output = cipher.decode(keyword, input); - assertEquals("Vigenere Decoding failed the first test", correctOutput, output); - - //Test 2 - input = "LXFOPVEFRNHR"; - keyword = "LEMON"; - correctOutput = "ATTACKATDAWN"; - output = cipher.decode(keyword, input); - assertEquals("Vigenere Decoding failed the second test", correctOutput, output); - - //Test 3 - input = "CSASTPKVSIQUTGQUCSASTPIUAQJB"; - keyword = "ABCD"; - correctOutput = "CRYPTOISSHORTFORCRYPTOGRAPHY"; - output = cipher.decode(keyword, input); - assertEquals("Vigenere Decoding failed the third test", correctOutput, output); - } - @Test - public void testEncode() throws Exception{ - Vigenere cipher = new Vigenere(); - - //Test 1 - String input = "abc"; - String keyword = "xyz"; - String correctOutput = "XZB"; - String output = cipher.encode(keyword, input); - assertEquals("Vigenere Encoding failed the first test", correctOutput, output); - - //Test 2 - input = "Attack at dawn"; - keyword = "Lemon"; - correctOutput = "LXFOPVEFRNHR"; - output = cipher.encode(keyword, input); - assertEquals("Vigenere Encoding failed the second test", correctOutput, output); - - //Test 3 - input = "'Crypto' is short for 'Cryptography'"; - keyword = "abcd"; - correctOutput = "CSASTPKVSIQUTGQUCSASTPIUAQJB"; - output = cipher.encode(keyword, input); - assertEquals("Vigenere Encoding failed the third test", correctOutput, output); - } -} +//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestVigenere.java +//Matthew Ellison +// Created: 07-25-21 +//Modified: 07-25-21 +//These are the tests for the Vigenere class +package mattrixwv.CipherStreamJava; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + + +public class TestVigenere{ + @Test + public void testDecode() throws Exception{ + Vigenere cipher = new Vigenere(); + + //Test 1 + String input = "xzb"; + String keyword = "xyz"; + String correctOutput = "ABC"; + String output = cipher.decode(keyword, input); + assertEquals("Vigenere Decoding failed the first test", correctOutput, output); + + //Test 2 + input = "LXFOPVEFRNHR"; + keyword = "LEMON"; + correctOutput = "ATTACKATDAWN"; + output = cipher.decode(keyword, input); + assertEquals("Vigenere Decoding failed the second test", correctOutput, output); + + //Test 3 + input = "CSASTPKVSIQUTGQUCSASTPIUAQJB"; + keyword = "ABCD"; + correctOutput = "CRYPTOISSHORTFORCRYPTOGRAPHY"; + output = cipher.decode(keyword, input); + assertEquals("Vigenere Decoding failed the third test", correctOutput, output); + } + @Test + public void testEncode() throws Exception{ + Vigenere cipher = new Vigenere(); + + //Test 1 + String input = "abc"; + String keyword = "xyz"; + String correctOutput = "XZB"; + String output = cipher.encode(keyword, input); + assertEquals("Vigenere Encoding failed the first test", correctOutput, output); + + //Test 2 + input = "Attack at dawn"; + keyword = "Lemon"; + correctOutput = "LXFOPVEFRNHR"; + output = cipher.encode(keyword, input); + assertEquals("Vigenere Encoding failed the second test", correctOutput, output); + + //Test 3 + input = "'Crypto' is short for 'Cryptography'"; + keyword = "abcd"; + correctOutput = "CSASTPKVSIQUTGQUCSASTPIUAQJB"; + output = cipher.encode(keyword, input); + assertEquals("Vigenere Encoding failed the third test", correctOutput, output); + } +}