Added Javadoc comments to the classes

This commit is contained in:
Mattrixwv
2024-08-11 23:48:02 -04:00
parent b16956b184
commit c10df8e5df
29 changed files with 3270 additions and 431 deletions

View File

@@ -1,7 +1,23 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java
//Mattrixwv
// Created: 01-12-22
//Modified: 04-19-24
//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;
@@ -16,20 +32,38 @@ import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
/**
* Implements the Baconian cipher, a method of steganography where each letter of the alphabet is represented by a unique sequence of five characters ('a' or 'b').
* The Baconian cipher is a simple substitution cipher that can encode and decode text based on these sequences.
*
* <p>
* The cipher uses a predefined list of five-character strings to represent each letter of the alphabet (A-Z). The input string is converted to these sequences for encoding,
* and sequences are converted back to letters for decoding.
* </p>
*/
public class Baconian{
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
//Conversions
//?Conversions
/** Predefined code for Baconian cipher (5-character strings for A-Z) */
protected static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba","aabbb", "abaaa", "abaaa", "abaab", "ababa", "ababb", //A-M
"abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb", "babaa", "babab", "babba", "babbb" //N-Z
));
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The encoded/decoded string
protected boolean preserveCapitals; //Persist capitals in the output string
/** The string that needs encoded/decoded */
protected String inputString;
/** The encoded/decoded string */
protected String outputString;
/** Persist capitals in the output string */
protected boolean preserveCapitals;
//Sets the input string
/**
* Sets the input string for encoding, removing whitespace and symbols, and handling capitalization based on the flag.
*
* @param inputString the string to be encoded
* @throws InvalidInputException if the input string is null, empty, or invalid
*/
protected void setInputStringEncode(String inputString) throws InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
@@ -53,6 +87,13 @@ public class Baconian{
throw new InvalidInputException("Input must contain at least 1 letter");
}
}
/**
* Sets the input string for decoding, ensuring it contains only valid Baconian characters (a's and b's) with a length of 5.
*
* @param inputString the string to be decoded
* @throws InvalidCharacterException if the input string contains invalid Baconian characters
* @throws InvalidInputException if the input string is null or empty
*/
protected void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
@@ -91,7 +132,10 @@ public class Baconian{
logger.debug("Cleaned input string '{}'", inputString);
}
//Encodes the inputString and stores the result in outputString
/**
* Encodes the input string using the Baconian cipher.
* Each character in the input string is converted to its corresponding Baconian sequence.
*/
protected void encode(){
logger.debug("Encoding");
StringJoiner output = new StringJoiner(" ");
@@ -121,7 +165,10 @@ public class Baconian{
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
}
//Decodes the inputString and stores the result in outputString
/**
* Decodes the input string using the Baconian cipher.
* Each Baconian sequence in the input string is converted back to its corresponding character.
*/
protected void decode(){
logger.debug("Decoding");
@@ -157,24 +204,45 @@ public class Baconian{
logger.debug("Saving output string '{}'", outputString);
}
//Constructor
//?Constructor
/**
* Constructs a new {@code Baconian} instance with default settings for preserving capitals.
*/
public Baconian(){
reset();
preserveCapitals = false;
}
/**
* Constructs a new {@code Baconian} instance with a specified setting for preserving capitals.
*
* @param preserveCapitals whether to preserve capital letters in the output
*/
public Baconian(boolean preserveCapitals){
reset();
this.preserveCapitals = preserveCapitals;
}
//Sets the inputString and encodes the message
/**
* Encodes the input string using the Baconian cipher.
*
* @param inputString the string to be encoded
* @return the encoded string
* @throws InvalidInputException if the input string is invalid
*/
public String encode(String inputString) throws InvalidInputException{
reset();
setInputStringEncode(inputString);
encode();
return outputString;
}
//Sets the inputString and decodes the message
/**
* Decodes the input string using the Baconian cipher.
*
* @param inputString the string to be decoded
* @return the decoded string
* @throws InvalidCharacterException if the input string contains invalid Baconian characters
* @throws InvalidInputException if the input string is invalid
*/
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
reset();
setInputStringDecode(inputString);
@@ -182,14 +250,26 @@ public class Baconian{
return outputString;
}
//Getters
//?Getters
/**
* Gets the current input string.
*
* @return the input string
*/
public String getInputString(){
return inputString;
}
/**
* Gets the current output string.
*
* @return the output string
*/
public String getOutputString(){
return outputString;
}
//Makes sure all variables are empty
/**
* Resets the input and output strings to empty.
*/
public void reset(){
logger.debug("Resetting fields");