Completed RailFence cipher
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestRailFence.java
|
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestRailFence.java
|
||||||
//Mattrixwv
|
//Mattrixwv
|
||||||
// Created: 03-21-22
|
// Created: 03-21-22
|
||||||
//Modified: 03-21-22
|
//Modified: 03-22-22
|
||||||
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,22 +68,210 @@ public class TestRailFence{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNocapitalEncode() throws InvalidBaseException, InvalidInputException{
|
public void testNocapitalEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "MAOOESGTECDSENE";
|
||||||
|
String output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MOETESENESGCDAO";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital 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 no capital 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 no capital 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 no capital 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 no capital mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidBaseException, InvalidInputException{
|
public void testNoWhitespaceEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "maooesgtecdsene";
|
||||||
|
String output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "moetesenesgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace rail length encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "maooesgtecdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace 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 no whitespace symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Maooesgte^cdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Moetesene^sgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
public void testNoSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "maooesgtecdsene";
|
||||||
|
String output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "moetesenesgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol 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 no symbol whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "maooesgtecdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Maooesg tecdsene";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Moetese nesgcdao";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "MAOOESGTECDSENE";
|
||||||
|
String output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MOETESENESGCDAO";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure rail length encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MAOOESGTECDSENE";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MOETESENESGCDAO";
|
||||||
|
output = cipher.encode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,21 +329,209 @@ public class TestRailFence{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalDecode() throws InvalidBaseException, InvalidInputException{
|
public void testNoCapitalDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "maooesgtecdsene";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
|
String output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "MAOOESGTECDSENE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length decoding
|
||||||
|
inputString = "moetesenesgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no capital 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 no capital 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 no capital 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 no capital 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 no capital mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoWhitespaceDecode() throws InvalidBaseException, InvalidInputException{
|
public void testNoWhitespaceDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "maooesgtecdsene";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "MAOOESGTECDSENE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length decoding
|
||||||
|
inputString = "moetesenesgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace rail length decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "maooesg te cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace 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 no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Maooesg te^cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Messageto^encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Moetese ne^sgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Messageto^encode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
public void testNoSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "maooesgtecdsene";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "MAOOESGTECDSENE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length decoding
|
||||||
|
inputString = "moetesenesgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol 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 no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "maooesg*te+cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Maooesg te^cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "Message toencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Moetese ne^sgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "Message toencode";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||||
//TODO:
|
RailFence cipher = new RailFence(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "maooesgtecdsene";
|
||||||
|
int numRails = 3;
|
||||||
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
|
String output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "MAOOESGTECDSENE";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test rail length decoding
|
||||||
|
inputString = "moetesenesgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure rail length decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "maooesg te cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "maooesg*te+cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Maooesg te^cdsene";
|
||||||
|
numRails = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in rail length for good measure
|
||||||
|
inputString = "Moetese ne^sgcdao";
|
||||||
|
numRails = 5;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(numRails, inputString);
|
||||||
|
assertEquals("RailFence failed secure mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user