|
|
|
|
@@ -1,450 +1,199 @@
|
|
|
|
|
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
|
|
|
|
|
//Mattrixwv
|
|
|
|
|
// Created: 01-25-22
|
|
|
|
|
//Modified: 07-09-22
|
|
|
|
|
//Modified: 04-14-23
|
|
|
|
|
package com.mattrixwv.cipherstream.combination;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.never;
|
|
|
|
|
import static org.mockito.Mockito.times;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
|
|
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
|
|
|
|
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
|
|
|
|
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
|
|
public class TestADFGX{
|
|
|
|
|
@Test
|
|
|
|
|
public void testEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, true, true);
|
|
|
|
|
private ADFGX cipher;
|
|
|
|
|
private Logger logger;
|
|
|
|
|
|
|
|
|
|
//Test lowercase encoding
|
|
|
|
|
String inputString = "messagetoencode";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase encoding
|
|
|
|
|
inputString = "MESSAGETOENCODE";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace encoding
|
|
|
|
|
inputString = "message to encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol encoding
|
|
|
|
|
inputString = "message*to+encode-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol encoding
|
|
|
|
|
inputString = "Message to^encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(false, true, true);
|
|
|
|
|
|
|
|
|
|
//Test lowercase encoding
|
|
|
|
|
String inputString = "messagetoencode";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
String output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase encoding
|
|
|
|
|
inputString = "MESSAGETOENCODE";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace encoding
|
|
|
|
|
inputString = "message to encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol encoding
|
|
|
|
|
inputString = "message*to+encode-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol encoding
|
|
|
|
|
inputString = "Message to^encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXD AXDX^ADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, false, true);
|
|
|
|
|
|
|
|
|
|
//Test lowercase encoding
|
|
|
|
|
String inputString = "messagetoencode";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase encoding
|
|
|
|
|
inputString = "MESSAGETOENCODE";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace encoding
|
|
|
|
|
inputString = "message to encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol encoding
|
|
|
|
|
inputString = "message*to+encode-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol encoding
|
|
|
|
|
inputString = "Message to^encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAgagadfagaxxdaxdx^adafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, true, false);
|
|
|
|
|
|
|
|
|
|
//Test lowercase encoding
|
|
|
|
|
String inputString = "messagetoencode";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase encoding
|
|
|
|
|
inputString = "MESSAGETOENCODE";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace encoding
|
|
|
|
|
inputString = "message to encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol encoding
|
|
|
|
|
inputString = "message*to+encode-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol encoding
|
|
|
|
|
inputString = "Message to^encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAgagadfagaxxd axdxadafafxddgdf";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(false, false, false);
|
|
|
|
|
|
|
|
|
|
//Test lowercase encoding
|
|
|
|
|
String inputString = "messagetoencode";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
String output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase encoding
|
|
|
|
|
inputString = "MESSAGETOENCODE";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace encoding
|
|
|
|
|
inputString = "message to encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol encoding
|
|
|
|
|
inputString = "message*to+encode-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol encoding
|
|
|
|
|
inputString = "Message to^encode";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
output = cipher.encode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void setup(){
|
|
|
|
|
cipher = new ADFGX();
|
|
|
|
|
logger = mock(Logger.class);
|
|
|
|
|
ADFGX.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, true, true);
|
|
|
|
|
public void testSetSquareKeyword(){
|
|
|
|
|
assertThrows(InvalidKeywordException.class, () -> {
|
|
|
|
|
cipher.setSquareKeyword(null);
|
|
|
|
|
});
|
|
|
|
|
assertEquals("", cipher.squareKeyword);
|
|
|
|
|
verify(logger, never()).debug(anyString(), anyString());
|
|
|
|
|
|
|
|
|
|
//Test lowercase decoding
|
|
|
|
|
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "messagetoencode";
|
|
|
|
|
String output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase decoding
|
|
|
|
|
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace decoding
|
|
|
|
|
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "message to encode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol decoding
|
|
|
|
|
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "message*to+encode-";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol decoding
|
|
|
|
|
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "Message to^encode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
String squareKeyword = "squareKeyword";
|
|
|
|
|
cipher.setSquareKeyword(squareKeyword);
|
|
|
|
|
assertEquals(squareKeyword, cipher.squareKeyword);
|
|
|
|
|
verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(false, true, true);
|
|
|
|
|
public void testSetKeyword(){
|
|
|
|
|
assertThrows(InvalidKeywordException.class, () -> {
|
|
|
|
|
cipher.setKeyword(null);
|
|
|
|
|
});
|
|
|
|
|
assertEquals("", cipher.keyword);
|
|
|
|
|
verify(logger, never()).debug(anyString(), anyString());
|
|
|
|
|
|
|
|
|
|
//Test lowercase decoding
|
|
|
|
|
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
String output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase decoding
|
|
|
|
|
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace decoding
|
|
|
|
|
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGE TO ENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol decoding
|
|
|
|
|
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGE*TO+ENCODE-";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol decoding
|
|
|
|
|
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGE TO^ENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
cipher.setKeyword(keyword);
|
|
|
|
|
assertEquals(keyword, cipher.keyword);
|
|
|
|
|
verify(logger, times(1)).debug("keyword = {}", keyword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, false, true);
|
|
|
|
|
public void testSetInputString(){
|
|
|
|
|
//Null input
|
|
|
|
|
assertThrows(InvalidInputException.class, () -> {
|
|
|
|
|
cipher.setInputString(null);
|
|
|
|
|
});
|
|
|
|
|
assertEquals("", cipher.inputString);
|
|
|
|
|
verify(logger, never()).debug(anyString(), anyString());
|
|
|
|
|
|
|
|
|
|
//Test lowercase decoding
|
|
|
|
|
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "messagetoencode";
|
|
|
|
|
String output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase decoding
|
|
|
|
|
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
String originalInputString = "original input string '{}'";
|
|
|
|
|
String cleanedInputString = "cleaned input string '{}'";
|
|
|
|
|
|
|
|
|
|
//Test whitespace decoding
|
|
|
|
|
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "messagetoencode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Blank input
|
|
|
|
|
cipher.preserveCapitals = true;
|
|
|
|
|
cipher.preserveSymbols = true;
|
|
|
|
|
cipher.preserveWhitespace = true;
|
|
|
|
|
assertThrows(InvalidInputException.class, () -> {
|
|
|
|
|
cipher.setInputString("");
|
|
|
|
|
});
|
|
|
|
|
assertEquals("", cipher.inputString);
|
|
|
|
|
verify(logger, times(1)).debug(originalInputString, "");
|
|
|
|
|
|
|
|
|
|
//Test symbol decoding
|
|
|
|
|
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "message*to+encode-";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//No options
|
|
|
|
|
String inputString = "input String*";
|
|
|
|
|
cipher.setInputString(inputString);
|
|
|
|
|
assertEquals(inputString, cipher.inputString);
|
|
|
|
|
verify(logger, times(1)).debug(originalInputString, inputString);
|
|
|
|
|
verify(logger, times(1)).debug(cleanedInputString, inputString);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol decoding
|
|
|
|
|
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "Messageto^encode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//capitals
|
|
|
|
|
cipher.preserveCapitals = false;
|
|
|
|
|
cipher.preserveWhitespace = true;
|
|
|
|
|
cipher.preserveSymbols = true;
|
|
|
|
|
inputString = "input String*";
|
|
|
|
|
cipher.setInputString(inputString);
|
|
|
|
|
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
|
|
|
|
verify(logger, times(2)).debug(originalInputString, inputString);
|
|
|
|
|
verify(logger, times(1)).debug("Removing capitals");
|
|
|
|
|
verify(logger, times(1)).debug(cleanedInputString, inputString.toUpperCase());
|
|
|
|
|
|
|
|
|
|
//whitespace
|
|
|
|
|
cipher.preserveCapitals = true;
|
|
|
|
|
cipher.preserveWhitespace = false;
|
|
|
|
|
cipher.preserveSymbols = true;
|
|
|
|
|
inputString = "input String*";
|
|
|
|
|
cipher.setInputString(inputString);
|
|
|
|
|
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
|
|
|
|
|
verify(logger, times(3)).debug(originalInputString, inputString);
|
|
|
|
|
verify(logger, times(1)).debug("Removing whitespace");
|
|
|
|
|
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("\\s", ""));
|
|
|
|
|
|
|
|
|
|
//symbols
|
|
|
|
|
cipher.preserveCapitals = true;
|
|
|
|
|
cipher.preserveWhitespace = true;
|
|
|
|
|
cipher.preserveSymbols = false;
|
|
|
|
|
inputString = "input String*";
|
|
|
|
|
cipher.setInputString(inputString);
|
|
|
|
|
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
|
|
|
|
verify(logger, times(4)).debug(originalInputString, inputString);
|
|
|
|
|
verify(logger, times(1)).debug("Removing symbols");
|
|
|
|
|
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("[^a-zA-Z\\s]", ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(true, true, false);
|
|
|
|
|
|
|
|
|
|
//Test lowercase decoding
|
|
|
|
|
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "messagetoencode";
|
|
|
|
|
String output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase decoding
|
|
|
|
|
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test whitespace decoding
|
|
|
|
|
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "message to encode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test symbol decoding
|
|
|
|
|
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "messagetoencode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol decoding
|
|
|
|
|
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "Message toencode";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
public void testFormatOutputStringEncode(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
|
|
|
|
ADFGX cipher = new ADFGX(false, false, false);
|
|
|
|
|
public void formatOutputStringDecode(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test lowercase decoding
|
|
|
|
|
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
|
|
|
|
|
String squareKeyword = "SquareKeyword";
|
|
|
|
|
String keyword = "keyword";
|
|
|
|
|
String correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
String output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
//Test uppercase decoding
|
|
|
|
|
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
@Test
|
|
|
|
|
public void testEncodePrivate(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test whitespace decoding
|
|
|
|
|
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
@Test
|
|
|
|
|
public void testDecodePrivate(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test symbol decoding
|
|
|
|
|
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
@Test
|
|
|
|
|
public void testConstructors(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Test mixed case, whitespace, and symbol decoding
|
|
|
|
|
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
|
|
|
|
squareKeyword = "SquareKeyword";
|
|
|
|
|
keyword = "keyword";
|
|
|
|
|
correctOutput = "MESSAGETOENCODE";
|
|
|
|
|
output = cipher.decode(squareKeyword, keyword, inputString);
|
|
|
|
|
assertEquals(correctOutput, output);
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetters(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testReset(){
|
|
|
|
|
//TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testPracticalEncoding(){
|
|
|
|
|
//Test as original
|
|
|
|
|
cipher.preserveCapitals = true;
|
|
|
|
|
cipher.preserveWhitespace = true;
|
|
|
|
|
cipher.preserveSymbols = true;
|
|
|
|
|
String output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
|
|
|
|
|
assertEquals("AAgagadfagaxxd axdx^adafafxddgdf", output);
|
|
|
|
|
|
|
|
|
|
//Test fully cleaned
|
|
|
|
|
cipher.preserveCapitals = false;
|
|
|
|
|
cipher.preserveWhitespace = false;
|
|
|
|
|
cipher.preserveSymbols = false;
|
|
|
|
|
output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
|
|
|
|
|
assertEquals("AAGAGADFAGAXXDAXDXADAFAFXDDGDF", output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testPracticalDecoding(){
|
|
|
|
|
//Test as original
|
|
|
|
|
cipher.preserveCapitals = true;
|
|
|
|
|
cipher.preserveWhitespace = true;
|
|
|
|
|
cipher.preserveSymbols = true;
|
|
|
|
|
String output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
|
|
|
|
|
assertEquals("Message to^encode", output);
|
|
|
|
|
|
|
|
|
|
//Test fully cleaned
|
|
|
|
|
cipher.preserveCapitals = false;
|
|
|
|
|
cipher.preserveWhitespace = false;
|
|
|
|
|
cipher.preserveSymbols = false;
|
|
|
|
|
output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
|
|
|
|
|
assertEquals("MESSAGETOENCODE", output);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|