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