Added ADFGX cipher

This commit is contained in:
2022-01-25 23:26:05 -05:00
parent 87c5eb093e
commit 57f5d350da
2 changed files with 623 additions and 0 deletions

View File

@@ -0,0 +1,450 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
//Mattrixwv
// Created: 01-25-22
//Modified: 01-25-22
package com.mattrixwv.CipherStreamJava.combination;
import static org.junit.Assert.assertEquals;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
import org.junit.Test;
public class TestADFGX{
@Test
public void testEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, 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("ADFGX failed lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed symbol encoding.", 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("ADFGX failed mixed case, whitesapce, and symbol encoding.", 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("ADFGX failed no capital lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital symbol encoding.", 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("ADFGX failed no capital mixed case, whitesapce, and symbol encoding.", 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("ADFGX failed no whitespace lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace symbol encoding.", 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("ADFGX failed no whitespace mixed case, whitesapce, and symbol encoding.", 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("ADFGX failed no symbol lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol symbol encoding.", 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("ADFGX failed no symbol mixed case, whitesapce, and symbol encoding.", 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("ADFGX failed lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed symbol encoding.", 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("ADFGX failed mixed case, whitesapce, and symbol encoding.", correctOutput, output);
}
@Test
public void testDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, true, true);
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "messagetoencode";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed lowercase decoding.", correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message to encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message*to+encode-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed symbol decoding.", 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("ADFGX failed mixed case, whitesapce, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, true, true);
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "MESSAGETOENCODE";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital lowercase decoding.", correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGE TO ENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGE*TO+ENCODE-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no capital symbol decoding.", 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("ADFGX failed no capital mixed case, whitesapce, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, false, true);
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "messagetoencode";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace lowercase decoding.", correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "messagetoencode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message*to+encode-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no whitespace symbol decoding.", correctOutput, output);
//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("ADFGX failed no whitespace mixed case, whitesapce, and symbol decoding.", correctOutput, output);
}
@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("ADFGX failed no symbol lowercase decoding.", correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message to encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "messagetoencode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed no symbol symbol decoding.", 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("ADFGX failed no symbol mixed case, whitesapce, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, false, false);
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "MESSAGETOENCODE";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed secure lowercase decoding.", correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed secure uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed secure whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed secure symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals("ADFGX failed secure mixed case, whitesapce, and symbol decoding.", correctOutput, output);
}
}