Added Baconian cipher
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestBaconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 01-12-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestBaconian{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException{
|
||||
Baconian cipher = new Baconian(true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "Messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecodeNoCapital() throws InvalidCharacterException{
|
||||
Baconian cipher = new Baconian(false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Baconian cipher = new Baconian(true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to-encode";
|
||||
correctOutput = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncodeNoCapital(){
|
||||
Baconian cipher = new Baconian(false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to-encode";
|
||||
correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user