TestAffine.java created online with Bitbucket

This commit is contained in:
2022-01-27 15:43:49 +00:00
parent 3273aa77af
commit 9f3e7ff7a3

View File

@@ -0,0 +1,449 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestAffine.java
//Mattrixwv
// Created: 01-26-22
//Modified: 01-26-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 TestAffine{
@Test
public void testEncode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, true, true);
//Test lowercase encoding
String inputString = "messagetoencode";
int key1 = 5;
int key2 = 7;
String correctOutput = "pbtthlbyzburzwb";
String output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
key1 = 5;
key2 = 7;
correctOutput = "PBTTHLBYZBURZWB";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb yz burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb*yz+burzwb-";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, symbol encoding
inputString = "Message to^encode";
key1 = 5;
key2 = 7;
correctOutput = "Pbtthlb yz^burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(false, true, true);
//Test lowercase encoding
String inputString = "messagetoencode";
int key1 = 5;
int key2 = 7;
String correctOutput = "pbtthlbyzburzwb";
String output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no capital lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no capital uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb yz burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no capital whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb*yz+burzwb-";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no capital symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, symbol encoding
inputString = "Message to^encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb yz^burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, false, true);
//Test lowercase encoding
String inputString = "messagetoencode";
int key1 = 5;
int key2 = 7;
String correctOutput = "pbtthlbyzburzwb";
String output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no whitespace lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
key1 = 5;
key2 = 7;
correctOutput = "PBTTHLBYZBURZWB";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no whitespace uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no whitespace whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb*yz+burzwb-";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no whitespace symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, symbol encoding
inputString = "Message to^encode";
key1 = 5;
key2 = 7;
correctOutput = "Pbtthlbyz^burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, true, false);
//Test lowercase encoding
String inputString = "messagetoencode";
int key1 = 5;
int key2 = 7;
String correctOutput = "pbtthlbyzburzwb";
String output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no symbol lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
key1 = 5;
key2 = 7;
correctOutput = "PBTTHLBYZBURZWB";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no symbol uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlb yz burzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no symbol whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no symbol symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, symbol encoding
inputString = "Message to^encode";
key1 = 5;
key2 = 7;
correctOutput = "Pbtthlb yzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(false, false, false);
//Test lowercase encoding
String inputString = "messagetoencode";
int key1 = 5;
int key2 = 7;
String correctOutput = "pbtthlbyzburzwb";
String output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed secure lowercase encoding.", correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed secure uppercase encoding.", correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed secure whitespace encoding.", correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed secure symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, symbol encoding
inputString = "Message to^encode";
key1 = 5;
key2 = 7;
correctOutput = "pbtthlbyzburzwb";
output = cipher.encode(key1, key2, inputString);
assertEquals("Affine failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
}
@Test
public void testDecode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, true, true);
//Test lowercase decoding
String inputString = "pbtthlbyzburzwb";
int key1 = 5;
int key2 = 7;
String correctOutput = "messagetoencode";
String output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed lowercase decoding.", correctOutput, output);
//Test uppsercase decoding
inputString = "PBTTHLBYZBURZWB";
key1 = 5;
key2 = 7;
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "pbtthlb yz burzwb";
key1 = 5;
key2 = 7;
correctOutput = "message to encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "pbtthlb*yz+burzwb-";
key1 = 5;
key2 = 7;
correctOutput = "message*to+encode-";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, symbol decoding
inputString = "Pbtthlb yz^burzwb";
key1 = 5;
key2 = 7;
correctOutput = "Message to^encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(false, true, true);
//Test lowercase decoding
String inputString = "pbtthlbyzburzwb";
int key1 = 5;
int key2 = 7;
String correctOutput = "messagetoencode";
String output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no capital lowercase decoding.", correctOutput, output);
//Test uppsercase decoding
inputString = "PBTTHLBYZBURZWB";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no capital uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "pbtthlb yz burzwb";
key1 = 5;
key2 = 7;
correctOutput = "message to encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no capital whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "pbtthlb*yz+burzwb-";
key1 = 5;
key2 = 7;
correctOutput = "message*to+encode-";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no capital symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, symbol decoding
inputString = "Pbtthlb yz^burzwb";
key1 = 5;
key2 = 7;
correctOutput = "message to^encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, false, true);
//Test lowercase decoding
String inputString = "pbtthlbyzburzwb";
int key1 = 5;
int key2 = 7;
String correctOutput = "messagetoencode";
String output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no whitespace lowercase decoding.", correctOutput, output);
//Test uppsercase decoding
inputString = "PBTTHLBYZBURZWB";
key1 = 5;
key2 = 7;
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no whitespace uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "pbtthlb yz burzwb";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no whitespace whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "pbtthlb*yz+burzwb-";
key1 = 5;
key2 = 7;
correctOutput = "message*to+encode-";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no whitespace symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, symbol decoding
inputString = "Pbtthlb yz^burzwb";
key1 = 5;
key2 = 7;
correctOutput = "Messageto^encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(true, true, false);
//Test lowercase decoding
String inputString = "pbtthlbyzburzwb";
int key1 = 5;
int key2 = 7;
String correctOutput = "messagetoencode";
String output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no symbol lowercase decoding.", correctOutput, output);
//Test uppsercase decoding
inputString = "PBTTHLBYZBURZWB";
key1 = 5;
key2 = 7;
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no symbol uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "pbtthlb yz burzwb";
key1 = 5;
key2 = 7;
correctOutput = "message to encode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no symbol whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "pbtthlb*yz+burzwb-";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no symbol symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, symbol decoding
inputString = "Pbtthlb yz^burzwb";
key1 = 5;
key2 = 7;
correctOutput = "Message toencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
Affine cipher = new Affine(false, false, false);
//Test lowercase decoding
String inputString = "pbtthlbyzburzwb";
int key1 = 5;
int key2 = 7;
String correctOutput = "messagetoencode";
String output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed secure lowercase decoding.", correctOutput, output);
//Test uppsercase decoding
inputString = "PBTTHLBYZBURZWB";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed secure uppercase decoding.", correctOutput, output);
//Test whitespace decoding
inputString = "pbtthlb yz burzwb";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed secure whitespace decoding.", correctOutput, output);
//Test symbol decoding
inputString = "pbtthlb*yz+burzwb-";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed secure symbol decoding.", correctOutput, output);
//Test mixed case, whitespace, symbol decoding
inputString = "Pbtthlb yz^burzwb";
key1 = 5;
key2 = 7;
correctOutput = "messagetoencode";
output = cipher.decode(key1, key2, inputString);
assertEquals("Affine failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
}
}