Updated Atbash to run faster

This commit is contained in:
2022-01-25 23:23:49 -05:00
parent 05024f931f
commit c65947a630
2 changed files with 255 additions and 239 deletions

View File

@@ -7,194 +7,14 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
import static org.junit.Assert.assertEquals;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
import org.junit.Test;
public class TestAtbash{
@Test
public void testDecode(){
Atbash cipher = new Atbash(true, true, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceDecode(){
Atbash cipher = new Atbash(true, false, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no whitespace lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalDecode(){
Atbash cipher = new Atbash(false, true, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no capital lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "abc";
output = cipher.decode(input);
assertEquals("Atbash failed no capital uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed no capital whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed no capital symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "the quick brown fox jumps over - the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoSymbolDecode(){
Atbash cipher = new Atbash(true, true, false);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no symbol lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "The quick brown fox jumps over the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalwhitesapceSymbolDecode(){
Atbash cipher = new Atbash(false, false, false);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed secure lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "abc";
output = cipher.decode(input);
assertEquals("Atbash failed secure uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed secure whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed secure symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
output = cipher.decode(input);
assertEquals("Atbash failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testEncode(){
public void testEncode() throws InvalidInputException{
Atbash cipher = new Atbash(true, true, true);
//Test lowercase encoding
@@ -230,43 +50,7 @@ public class TestAtbash{
assertEquals("Atbash failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceEncode(){
Atbash cipher = new Atbash(true, false, true);
//Test lowercase encoding
String input = "abc";
String correctOutput = "zyx";
String output = cipher.encode(input);
assertEquals("Atbash failed no whitespace lowercase encoding.", correctOutput, output);
//Test uppercase encoding
input = "ABC";
correctOutput = "ZYX";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace uppercase encoding.", correctOutput, output);
//Test whitespace encoding
input = "abc def";
correctOutput = "zyxwvu";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace whitespace encoding.", correctOutput, output);
//Test symbol decoding
input = "abc-def@";
correctOutput = "zyx-wvu@";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "The quick brown fox jumps over - the lazy dog";
correctOutput = "Gsvjfrxpyildmulcqfnkhlevi-gsvozabwlt";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoCapitalEncode(){
public void testNoCapitalEncode() throws InvalidInputException{
Atbash cipher = new Atbash(false, true, true);
//Test lowercase encoding
@@ -302,7 +86,43 @@ public class TestAtbash{
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoSymbolEncode(){
public void testNoWhitespaceEncode() throws InvalidInputException{
Atbash cipher = new Atbash(true, false, true);
//Test lowercase encoding
String input = "abc";
String correctOutput = "zyx";
String output = cipher.encode(input);
assertEquals("Atbash failed no whitespace lowercase encoding.", correctOutput, output);
//Test uppercase encoding
input = "ABC";
correctOutput = "ZYX";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace uppercase encoding.", correctOutput, output);
//Test whitespace encoding
input = "abc def";
correctOutput = "zyxwvu";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace whitespace encoding.", correctOutput, output);
//Test symbol decoding
input = "abc-def@";
correctOutput = "zyx-wvu@";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "The quick brown fox jumps over - the lazy dog";
correctOutput = "Gsvjfrxpyildmulcqfnkhlevi-gsvozabwlt";
output = cipher.encode(input);
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoSymbolEncode() throws InvalidInputException{
Atbash cipher = new Atbash(true, true, false);
//Test lowercase encoding
@@ -338,7 +158,7 @@ public class TestAtbash{
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolEncode(){
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidInputException{
Atbash cipher = new Atbash(false, false, false);
//Test lowercase encoding
@@ -373,4 +193,186 @@ public class TestAtbash{
output = cipher.encode(input);
assertEquals("Atbash failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testDecode() throws InvalidInputException{
Atbash cipher = new Atbash(true, true, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalDecode() throws InvalidInputException{
Atbash cipher = new Atbash(false, true, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no capital lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "abc";
output = cipher.decode(input);
assertEquals("Atbash failed no capital uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed no capital whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed no capital symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "the quick brown fox jumps over - the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceDecode() throws InvalidInputException{
Atbash cipher = new Atbash(true, false, true);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no whitespace lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abc-def@";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(input);
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoSymbolDecode() throws InvalidInputException{
Atbash cipher = new Atbash(true, true, false);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed no symbol lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "ABC";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abc def";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "The quick brown fox jumps over the lazy dog";
output = cipher.decode(input);
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalwhitesapceSymbolDecode() throws InvalidInputException{
Atbash cipher = new Atbash(false, false, false);
//Test lowercase decoding
String input = "zyx";
String correctOutput = "abc";
String output = cipher.decode(input);
assertEquals("Atbash failed secure lowercase decoding.", correctOutput, output);
//Test uppercase decoding
input = "ZYX";
correctOutput = "abc";
output = cipher.decode(input);
assertEquals("Atbash failed secure uppercase decoding.", correctOutput, output);
//Test whitespace decoding
input = "zyx wvu";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed secure whitespace decoding.", correctOutput, output);
//Test symbol decoding
input = "zyx-wvu@";
correctOutput = "abcdef";
output = cipher.decode(input);
assertEquals("Atbash failed secure symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
output = cipher.decode(input);
assertEquals("Atbash failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
}