Created Bifid cipher
This commit is contained in:
@@ -0,0 +1,408 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestBifid.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 03-03-22
|
||||
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||
|
||||
|
||||
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 TestBifid{
|
||||
@Test
|
||||
public void testEncode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne kc vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne*kc+vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaokne kc^vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MQAOKNEKCVDODZD";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE KC VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE*KC+VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE KC^VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaoknekcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne*kc+vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaoknekc^vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne kc vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaoknekcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaokne kcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MQAOKNEKCVDODZD";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "mqaoknekcvdodzd";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "mqaoknekcvdodzd";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "mqaoknekcvdodzd";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "mqaoknekcvdodzd";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
Bifid cipher = new Bifid(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "mqaoknekcvdodzd";
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user