Added Javadoc comments to the classes
This commit is contained in:
@@ -1,7 +1,23 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Autokey.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 05-04-23
|
||||
//Modified: 08-11-24
|
||||
/*
|
||||
Copyright (C) 2024 Mattrixwv
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,11 +28,28 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
/**
|
||||
* Implements the Autokey cipher, an extension of the Vigenère cipher that uses a keyword combined with the plaintext itself as the key.
|
||||
* The Autokey cipher adds the plaintext to the end of the keyword to create a longer key, which helps to make the encryption stronger.
|
||||
* This class inherits from the {@code Vigenere} class and overrides methods to handle encoding and decoding with the Autokey cipher.
|
||||
*
|
||||
* <p>
|
||||
* The Autokey cipher is symmetric, meaning that encoding and decoding are essentially the same process, but with a different key setup for decoding.
|
||||
* </p>
|
||||
*/
|
||||
public class Autokey extends Vigenere{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Autokey.class);
|
||||
|
||||
|
||||
//Special rules for setting the strings for encoding
|
||||
/**
|
||||
* Sets up the keyword and input string for encoding, generating a longer key that includes the plaintext.
|
||||
* This method is used internally to prepare the cipher for encoding.
|
||||
*
|
||||
* @param keyword the keyword used for encoding
|
||||
* @param inputString the string to be encoded
|
||||
* @throws InvalidKeywordException if the keyword is invalid
|
||||
* @throws InvalidInputException if the input string is invalid
|
||||
*/
|
||||
protected void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Setting fields for encoding");
|
||||
|
||||
@@ -44,7 +77,15 @@ public class Autokey extends Vigenere{
|
||||
offset.clear();
|
||||
setOffset();
|
||||
}
|
||||
//Setting the strings for decoding
|
||||
/**
|
||||
* Sets up the keyword and input string for decoding. The keyword is used to decode the input string.
|
||||
* This method is used internally to prepare the cipher for decoding.
|
||||
*
|
||||
* @param keyword the keyword used for decoding
|
||||
* @param inputString the string to be decoded
|
||||
* @throws InvalidKeywordException if the keyword is invalid
|
||||
* @throws InvalidInputException if the input string is invalid
|
||||
*/
|
||||
protected void decodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Setting fields for decoding");
|
||||
|
||||
@@ -56,7 +97,10 @@ public class Autokey extends Vigenere{
|
||||
logger.debug("Setting input string");
|
||||
setInputString(inputString);
|
||||
}
|
||||
//Decodes the inputString
|
||||
/**
|
||||
* Decodes the input string using the Autokey cipher.
|
||||
* This method is overridden to handle decoding with the Autokey cipher, which involves using the key and updating it with decoded characters.
|
||||
*/
|
||||
@Override
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
@@ -113,14 +157,32 @@ public class Autokey extends Vigenere{
|
||||
}
|
||||
|
||||
|
||||
//Constructor
|
||||
//?Constructor
|
||||
/**
|
||||
* Constructs a new {@code Autokey} instance with default settings for preserving capitals, whitespace, and symbols.
|
||||
*/
|
||||
public Autokey(){
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Constructs a new {@code Autokey} instance with specified settings for preserving capitals, whitespace, and symbols.
|
||||
*
|
||||
* @param preserveCapitals whether to preserve capital letters in the output
|
||||
* @param preserveWhitespace whether to preserve whitespace in the output
|
||||
* @param preserveSymbols whether to preserve symbols in the output
|
||||
*/
|
||||
public Autokey(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){
|
||||
super(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
}
|
||||
//Encodes inputString using the Autokey cipher
|
||||
/**
|
||||
* Encodes the input string using the Autokey cipher with the provided keyword.
|
||||
*
|
||||
* @param keyword the keyword used for encoding
|
||||
* @param inputString the string to be encoded
|
||||
* @return the encoded string
|
||||
* @throws InvalidKeywordException if the keyword is invalid
|
||||
* @throws InvalidInputException if the input string is invalid
|
||||
*/
|
||||
@Override
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
@@ -128,7 +190,15 @@ public class Autokey extends Vigenere{
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString using the Autokey cipher
|
||||
/**
|
||||
* Decodes the input string using the Autokey cipher with the provided keyword.
|
||||
*
|
||||
* @param keyword the keyword used for decoding
|
||||
* @param inputString the string to be decoded
|
||||
* @return the decoded string
|
||||
* @throws InvalidKeywordException if the keyword is invalid
|
||||
* @throws InvalidInputException if the input string is invalid
|
||||
*/
|
||||
@Override
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
|
||||
Reference in New Issue
Block a user