Updated tests
This commit is contained in:
@@ -1,41 +1,43 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Autokey.java
|
||||
//Matthew Ellison
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-16-22
|
||||
//Modified: 02-22-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Autokey extends Vigenere{
|
||||
//Special rules for setting the strings for encoding
|
||||
private void encodeSet(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||
private void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
//Set the input
|
||||
setInputString(input);
|
||||
setInputString(inputString);
|
||||
|
||||
StringBuilder newKey = new StringBuilder();
|
||||
//Remove all unneccessary elements from the key
|
||||
setKeyword(key);
|
||||
setKeyword(keyword);
|
||||
newKey.append(keyword);
|
||||
//Remove all unneccessary elements from the input
|
||||
setKeyword(input);
|
||||
setKeyword(inputString);
|
||||
newKey.append(getKeyword());
|
||||
|
||||
//Make sure the key is not any longer than the input
|
||||
key = newKey.substring(0, getKeyword().length());
|
||||
keyword = newKey.substring(0, getKeyword().length());
|
||||
|
||||
//Set the new keyword
|
||||
setKeyword(key);
|
||||
setKeyword(keyword);
|
||||
//Make sure to update the offset
|
||||
offset.clear();
|
||||
setOffset();
|
||||
}
|
||||
//Setting the strings for decoding
|
||||
private void decodeSet(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||
private void decodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
//Remove all unneccessary elements from the key
|
||||
setKeyword(key);
|
||||
setKeyword(keyword);
|
||||
//Remove all unneccessary elements from the input
|
||||
setInputString(input);
|
||||
setInputString(inputString);
|
||||
}
|
||||
//Decodes the inputString
|
||||
protected String decode() throws InvalidKeywordException{
|
||||
@@ -91,15 +93,15 @@ public class Autokey extends Vigenere{
|
||||
super(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
}
|
||||
//Encodes inputString using the Autokey cipher
|
||||
public String encode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
encodeSet(key, input);
|
||||
encodeSet(keyword, inputString);
|
||||
return encode();
|
||||
}
|
||||
//Decodes inputString using the Autokey cipher
|
||||
public String decode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
decodeSet(key, input);
|
||||
decodeSet(keyword, inputString);
|
||||
return decode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user