Added Javadoc comments to the classes
This commit is contained in:
@@ -1,7 +1,23 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.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;
|
||||
|
||||
|
||||
@@ -11,18 +27,34 @@ import org.slf4j.LoggerFactory;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
/**
|
||||
* Implements the Atbash cipher, a simple substitution cipher where each letter of the alphabet is mapped to its reverse.
|
||||
* For example, 'A' is mapped to 'Z', 'B' to 'Y', and so on.
|
||||
* This class provides methods to encode and decode strings using the Atbash cipher.
|
||||
*
|
||||
* <p>
|
||||
* The Atbash cipher is symmetric, meaning that encoding and decoding are the same operation.
|
||||
* </p>
|
||||
*/
|
||||
public class Atbash{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
|
||||
//Fields
|
||||
protected String inputString; //Holds the string that needs encoded or decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
//Settings
|
||||
protected boolean preserveCapitals; //Persist capitals in the output string
|
||||
protected boolean preserveWhitespace; //Persist whitespace in the output string
|
||||
protected boolean preserveSymbols; //Persist symbols in the output string
|
||||
//?Fields
|
||||
/** Holds the string that needs encoded or decoded */
|
||||
protected String inputString;
|
||||
/** The encoded/decoded string */
|
||||
protected String outputString;
|
||||
//?Settings
|
||||
/** Persist capitals in the output string */
|
||||
protected boolean preserveCapitals;
|
||||
/** Persist whitespace in the output string */
|
||||
protected boolean preserveWhitespace;
|
||||
/** Persist symbols in the output string */
|
||||
protected boolean preserveSymbols;
|
||||
|
||||
|
||||
//Encodes inputString and stores in outputString
|
||||
/**
|
||||
* Encodes the input string using the Atbash cipher.
|
||||
*/
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -57,7 +89,12 @@ public class Atbash{
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
}
|
||||
//Removes all invalid characters and sets inputString
|
||||
/**
|
||||
* Sets and sanitizes the input string according to the preservation settings.
|
||||
*
|
||||
* @param inputString the string to be processed
|
||||
* @throws InvalidInputException if the input string is null or blank after processing
|
||||
*/
|
||||
protected void setInputString(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
@@ -95,13 +132,24 @@ public class Atbash{
|
||||
}
|
||||
|
||||
|
||||
//Constructor
|
||||
//?Constructor
|
||||
/**
|
||||
* Constructs a new {@code Atbash} instance with default settings:
|
||||
* capitals, symbols, and whitespace are not preserved.
|
||||
*/
|
||||
public Atbash(){
|
||||
reset();
|
||||
preserveCapitals = false;
|
||||
preserveWhitespace = false;
|
||||
preserveSymbols = false;
|
||||
}
|
||||
/**
|
||||
* Constructs a new {@code Atbash} 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 Atbash(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){
|
||||
reset();
|
||||
this.preserveCapitals = preserveCapitals;
|
||||
@@ -109,7 +157,13 @@ public class Atbash{
|
||||
this.preserveSymbols = preserveSymbols;
|
||||
}
|
||||
|
||||
//Encodes inputString and returns the result
|
||||
/**
|
||||
* Encodes the provided input string using the Atbash cipher and returns the encoded result.
|
||||
*
|
||||
* @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{
|
||||
//Make sure everything is empty before you begin
|
||||
reset();
|
||||
@@ -117,19 +171,38 @@ public class Atbash{
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString and returns the result
|
||||
/**
|
||||
* Decodes the provided input string using the Atbash cipher and returns the decoded result.
|
||||
* Since the Atbash cipher is symmetric, this method performs the same operation as encoding.
|
||||
*
|
||||
* @param inputString the string to be decoded
|
||||
* @return the decoded string
|
||||
* @throws InvalidInputException if the input string is invalid
|
||||
*/
|
||||
public String decode(String inputString) throws InvalidInputException{
|
||||
return encode(inputString);
|
||||
}
|
||||
|
||||
//Getters
|
||||
//?Getters
|
||||
/**
|
||||
* Returns the current input string.
|
||||
*
|
||||
* @return the input string
|
||||
*/
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
/**
|
||||
* Returns the current output string.
|
||||
*
|
||||
* @return the output string
|
||||
*/
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
/**
|
||||
* Resets all fields to their default values.
|
||||
*/
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user