Created RailFence cipher
This commit is contained in:
@@ -0,0 +1,161 @@
|
|||||||
|
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestRailFence.java
|
||||||
|
//Mattrixwv
|
||||||
|
// Created: 03-21-22
|
||||||
|
//Modified: 03-21-22
|
||||||
|
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
public class TestRailFence{
|
||||||
|
@Test
|
||||||
|
public void testEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
RailFence cipher = new RailFence(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "maooesgtecdsene";
|
||||||
|
String output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "moetesenesgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed rail length encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "maooesg te cdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "maooesg*te+cdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Maooesg te^cdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Moetese ne^sgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNocapitalEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
RailFence cipher = new RailFence(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "maooesgtecdsene";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "MAOOESGTECDSENE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length decoding
|
||||||
|
inputString = "moetesenesgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed rail length decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "maooesg te cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "message to encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "maooesg*te+cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "message*to+encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Maooesg te^cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Message to^encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Moetese ne^sgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Message to^encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user