Created Beaufort cipher
This commit is contained in:
@@ -0,0 +1,407 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBeaufort.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestBeaufort{
|
||||
@Test
|
||||
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz rq ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz*rq+ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolz rq^ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "YAGEOLZRQUJMDAG";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ RQ UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ*RQ+UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ RQ^UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolzrqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz*rq+ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolzrq^ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz rq ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolzrqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolz rqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalwhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "YAGEOLZRQUJMDAG";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "yageolzrqujmdag";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "yageolzrqujmdag";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "yageolzrqujmdag";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "yageolzrqujmdag";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
Beaufort cipher = new Beaufort(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "yageolzrqujmdag";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user