diff --git a/pom.xml b/pom.xml index d70157a..d9c5d75 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,8 @@ 25 target/dependency-check-report.json target/dependency-check-report.html + + @@ -119,6 +121,19 @@ + + org.apache.maven.plugins + maven-dependency-plugin + 3.9.0 + + + + properties + + + + + org.owasp @@ -206,6 +221,7 @@ ${java.version} -Xlint:all + -Xlint:-serial true true @@ -215,6 +231,9 @@ org.apache.maven.plugins maven-surefire-plugin 3.5.4 + + @{argLine} -javaagent:${org.mockito:mockito-core:jar} + org.apache.maven.plugins diff --git a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGVX.java b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGVX.java index b551ea1..4e256e6 100644 --- a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGVX.java +++ b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGVX.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/combination/ADFGVX.java -//Mattrixwv -// Created: 01-26-22 -//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 . -*/ package com.mattrixwv.cipherstream.combination; @@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare; *
  • Encoding/decoding with a columnar transposition cipher (Columnar)
  • * */ -public class ADFGVX{ +public final class ADFGVX{ private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class); //?Fields /** The string that needs encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java index a92824a..2ee7d46 100644 --- a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java +++ b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java -//Mattrixwv -// Created: 01-25-22 -//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 . -*/ package com.mattrixwv.cipherstream.combination; @@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare; *
  • Encoding/decoding with a columnar transposition cipher (Columnar)
  • * */ -public class ADFGX{ +public final class ADFGX{ private static final Logger logger = LoggerFactory.getLogger(ADFGX.class); //?Internal fields diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Affine.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Affine.java index 5ea97a1..3f4592d 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Affine.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Affine.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Affine.java -//Mattrixwv -// Created: 01-26-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; *
  • Key2: The additive key
  • * */ -public class Affine{ +public final class Affine{ private static final Logger logger = LoggerFactory.getLogger(Affine.class); //?Fields /** The string that needs encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.java index f410960..ea359fa 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Atbash.java -//Mattrixwv -// Created: 07-25-21 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -36,7 +16,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * The Atbash cipher is symmetric, meaning that encoding and decoding are the same operation. *

    */ -public class Atbash{ +public final class Atbash{ private static final Logger logger = LoggerFactory.getLogger(Atbash.class); //?Fields /** Holds the string that needs encoded or decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Baconian.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Baconian.java index 3b7e9e1..bc022bb 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Baconian.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Baconian.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java -//Mattrixwv -// Created: 01-12-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * and sequences are converted back to letters for decoding. *

    */ -public class Baconian{ +public final class Baconian{ private static final Logger logger = LoggerFactory.getLogger(Baconian.class); //?Conversions diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java index e23c335..7bef323 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java -//Mattrixwv -// Created: 01-08-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -42,7 +22,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * for the specified base. *

    */ -public class BaseX{ +public final class BaseX{ private static final Logger logger = LoggerFactory.getLogger(BaseX.class); //?Fields /** The string that needs encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Beaufort.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Beaufort.java index 44caa2d..bb00a58 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Beaufort.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Beaufort.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Beaufort.java -//Mattrixwv -// Created: 02-23-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * This class allows you to encode and decode strings with options to preserve * capitalization, whitespace, and symbols. */ -public class Beaufort{ +public final class Beaufort{ private static final Logger logger = LoggerFactory.getLogger(Beaufort.class); //?Fields /** This is the string that needs encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Caesar.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Caesar.java index b6cabb2..f8a9501 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Caesar.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Caesar.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Caesar.java -//Matthew Ellison -// Created: 07-25-21 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -37,7 +17,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * capitalization, whitespace, and symbols. *

    */ -public class Caesar{ +public final class Caesar{ private static final Logger logger = LoggerFactory.getLogger(Caesar.class); //?Fields /** The string that needs encoded/decoded */ @@ -120,7 +100,7 @@ public class Caesar{ if(Character.isUpperCase(currentChar)){ logger.debug("Encoding uppercase"); - currentChar += shift; + currentChar = (char)((int)currentChar + shift); //Wrap around if the letter is now out of bounds if(currentChar < 'A'){ logger.debug("Wrapping around to Z"); @@ -135,7 +115,7 @@ public class Caesar{ else if(Character.isLowerCase(currentChar)){ logger.debug("Encoding lowercase"); - currentChar += shift; + currentChar = (char)((int)currentChar + shift); //Wrap around if the letter is now out of bounds if(currentChar < 'a'){ logger.debug("Wrapping around to z"); @@ -170,7 +150,7 @@ public class Caesar{ if(Character.isUpperCase(currentChar)){ logger.debug("Decoding uppercase"); - currentChar -= shift; + currentChar = (char)((int)currentChar - shift); //Wrap around if the letter is now out of bounds if(currentChar < 'A'){ logger.debug("Wrapping around to Z"); @@ -187,7 +167,7 @@ public class Caesar{ else if(Character.isLowerCase(currentChar)){ logger.debug("Decoding lowercase"); - currentChar -= shift; + currentChar = (char)((int)currentChar - shift); //Wrap around if the letter is now out of bounds if(currentChar < 'a'){ logger.debug("Wrapping around to z"); diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Porta.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Porta.java index 68e4437..2a1d243 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Porta.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Porta.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Porta.java -//Mattrixwv -// Created: 02-28-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * certain characters based on configuration settings. *

    */ -public class Porta{ +public final class Porta{ private static final Logger logger = LoggerFactory.getLogger(Porta.class); /** Predefined alphabetic tableau used for encoding and decoding */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Substitution.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Substitution.java index 9f520d2..6419cd0 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Substitution.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Substitution.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Substitution.java -//Mattrixwv -// Created: 02-22-22 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -39,7 +19,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * of the alphabet and optionally digits, without duplicates. *

    */ -public class Substitution{ +public final class Substitution{ private static final Logger logger = LoggerFactory.getLogger(Substitution.class); //?Fields /** The string that needs encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Vigenere.java b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Vigenere.java index 4aee140..86034f4 100644 --- a/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Vigenere.java +++ b/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Vigenere.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/Vigenere.java -//Matthew Ellison -// Created: 07-25-21 -//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 . -*/ package com.mattrixwv.cipherstream.monosubstitution; @@ -248,7 +228,10 @@ public class Vigenere{ */ public Vigenere(){ offset = new ArrayList<>(); - reset(); + inputString = ""; + outputString = ""; + keyword = ""; + offset.clear(); preserveCapitals = false; preserveWhitespace = false; preserveSymbols = false; @@ -262,7 +245,10 @@ public class Vigenere{ */ public Vigenere(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){ offset = new ArrayList<>(); - reset(); + inputString = ""; + outputString = ""; + keyword = ""; + offset.clear(); this.preserveCapitals = preserveCapitals; this.preserveWhitespace = preserveWhitespace; this.preserveSymbols = preserveSymbols; diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Bifid.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Bifid.java index 94fe932..888b635 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Bifid.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Bifid.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Bifid.java -//Mattrixwv -// Created: 03-03-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * them back into text. *

    */ -public class Bifid{ +public final class Bifid{ private static final Logger logger = LoggerFactory.getLogger(Bifid.class); //?Fields /** The message that needs to be encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Columnar.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Columnar.java index a65795a..7bd524a 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Columnar.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Columnar.java @@ -1,23 +1,3 @@ -//MattrixwvWebsite/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Columnar.java -//Mattrixwv -// Created: 01-16-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * It also includes options to preserve capitalization, whitespace, symbols, and to handle padding characters. *

    */ -public class Columnar{ +public final class Columnar{ private static final Logger logger = LoggerFactory.getLogger(Columnar.class); //?Fields /** The message that needs to be encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Hill.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Hill.java index 0eb2f16..2b07c40 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Hill.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Hill.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Hill.java -//Mattrixwv -// Created: 01-31-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -41,7 +21,7 @@ import com.mattrixwv.matrix.exceptions.InvalidScalarException; * messages. It operates on blocks of text by representing them as vectors and applying matrix transformations. *

    */ -public class Hill{ +public final class Hill{ private static final Logger logger = LoggerFactory.getLogger(Hill.class); //?Fields /** The message that needs to be encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/LargePolybiusSquare.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/LargePolybiusSquare.java index bd9a884..db5c299 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/LargePolybiusSquare.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/LargePolybiusSquare.java @@ -36,7 +36,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * The Polybius square cipher is a classical encryption method that uses a 6x6 grid * to encode and decode messages based on the positions of letters and numbers in the grid. */ -public class LargePolybiusSquare extends PolybiusSquare{ +public final class LargePolybiusSquare extends PolybiusSquare{ private static final Logger logger = LoggerFactory.getLogger(LargePolybiusSquare.class); @@ -239,6 +239,7 @@ public class LargePolybiusSquare extends PolybiusSquare{ */ public LargePolybiusSquare() throws InvalidCharacterException{ super(); + reset(); } /** * Constructs a PolybiusSquare cipher instance with specified settings. @@ -249,5 +250,6 @@ public class LargePolybiusSquare extends PolybiusSquare{ */ public LargePolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{ super(preserveWhitespace, preserveSymbols); + reset(); } } diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Morse.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Morse.java index 6893a70..4ffb12d 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Morse.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Morse.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Morse.java -//Mattrixwv -// Created: 07-28-21 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -38,7 +18,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * It supports alphanumeric characters (A-Z, 0-9) and validates input to ensure it contains valid characters. *

    */ -public class Morse{ +public final class Morse{ private static final Logger logger = LoggerFactory.getLogger(Morse.class); //?Code representations /** Morse code representations for letters A-Z */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Playfair.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Playfair.java index 06b9fe8..87f18cb 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Playfair.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Playfair.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Playfair.java -//Matthew Ellison -// Created: 07-30-21 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -35,7 +15,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * Represents the Playfair cipher encryption and decryption. * The Playfair cipher is a digraph substitution cipher that encrypts pairs of letters. */ -public class Playfair{ +public final class Playfair{ private static final Logger logger = LoggerFactory.getLogger(Playfair.class); /** A class representing the location of a character in the grid */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquare.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquare.java index e8895ab..f412305 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquare.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquare.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquare.java -//Mattrixwv -// Created: 01-04-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -94,14 +74,14 @@ public class PolybiusSquare{ /** - * Sets the replaced character. + * Validates the Replaced character. * - * @param replaced the character to be replaced + * @param replaced the character to be validated * @throws InvalidCharacterException if the character is not a letter or is invalid + * @return the validated character */ - protected void setReplaced(char replaced) throws InvalidCharacterException{ - logger.debug("Setting replaced"); - logger.debug("Original character {}", replaced); + private char validateReplaced(char replaced) throws InvalidCharacterException{ + logger.debug("Validating replaced character {}", replaced); if(!Character.isAlphabetic(replaced)){ throw new InvalidCharacterException("The replaced character must be a letter"); @@ -112,18 +92,30 @@ public class PolybiusSquare{ throw new InvalidCharacterException("The replaced letter cannot be the same as the replacing letter"); } - this.replaced = Character.toUpperCase(replaced); - logger.debug("Cleaned character {}", this.replaced); + replaced = Character.toUpperCase(replaced); + logger.debug("Cleaned character {}", replaced); + return replaced; } /** - * Sets the replacer character. + * Sets the replaced character. * - * @param replacer the character the replaces replaced + * @param replaced the character to be replaced * @throws InvalidCharacterException if the character is not a letter or is invalid */ - protected void setReplacer(char replacer) throws InvalidCharacterException{ - logger.debug("Setting replacer"); - logger.debug("Original character {}", replacer); + protected void setReplaced(char replaced) throws InvalidCharacterException{ + logger.debug("Setting replaced"); + + this.replaced = validateReplaced(replaced); + } + /** + * Validates the Replacer character. + * + * @param replacer the character to be validated + * @throws InvalidCharacterException if the character is not a letter or is invalid + * @return the validated character + */ + private char validateReplacer(char replacer) throws InvalidCharacterException{ + logger.debug("Validating replacer character {}", replacer); if(!Character.isAlphabetic(replacer)){ throw new InvalidCharacterException("The replacer character must be a letter"); @@ -134,8 +126,20 @@ public class PolybiusSquare{ throw new InvalidCharacterException("The replacer letter cannot be the same as the replaced letter"); } - this.replacer = Character.toUpperCase(replacer); - logger.debug("Cleaned character {}", this.replacer); + replacer = Character.toUpperCase(replacer); + logger.debug("Cleaned character {}", replacer); + return replacer; + } + /** + * Sets the replacer character. + * + * @param replacer the character the replaces replaced + * @throws InvalidCharacterException if the character is not a letter or is invalid + */ + protected void setReplacer(char replacer) throws InvalidCharacterException{ + logger.debug("Setting replacer"); + + this.replacer = validateReplacer(replacer); } /** * Creates the grid from the keyword. @@ -478,9 +482,12 @@ public class PolybiusSquare{ * @throws InvalidCharacterException if default characters are invalid */ public PolybiusSquare() throws InvalidCharacterException{ - reset(); - setReplaced('J'); - setReplacer('I'); + grid = new char[5][5]; + inputString = ""; + outputString = ""; + keyword = ""; + this.replaced = validateReplaced('J'); + this.replacer = validateReplacer('I'); preserveWhitespace = false; preserveSymbols = false; } @@ -492,9 +499,12 @@ public class PolybiusSquare{ * @throws InvalidCharacterException if default characters are invalid */ public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{ - reset(); - setReplaced('J'); - setReplacer('I'); + grid = new char[5][5]; + inputString = ""; + outputString = ""; + keyword = ""; + this.replaced = validateReplaced('J'); + this.replacer = validateReplacer('I'); this.preserveWhitespace = preserveWhitespace; this.preserveSymbols = preserveSymbols; } @@ -508,9 +518,12 @@ public class PolybiusSquare{ * @throws InvalidCharacterException if any character is invalid */ public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols, char replaced, char replacer) throws InvalidCharacterException{ - reset(); - setReplaced(replaced); - setReplacer(replacer); + grid = new char[5][5]; + inputString = ""; + outputString = ""; + keyword = ""; + this.replaced = validateReplaced(replaced); + this.replacer = validateReplacer(replacer); this.preserveWhitespace = preserveWhitespace; this.preserveSymbols = preserveSymbols; } diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/RailFence.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/RailFence.java index 41a7b0d..167268d 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/RailFence.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/RailFence.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/RailFence.java -//Mattrixwv -// Created: 03-21-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -35,7 +15,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException; * The Rail Fence cipher is a form of transposition cipher that writes the message in a zigzag pattern * across multiple "rails" and then reads it off row by row to encode or decode the message. */ -public class RailFence{ +public final class RailFence{ private static final Logger logger = LoggerFactory.getLogger(RailFence.class); //?Fields /** The message that needs to be encoded/decoded */ diff --git a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Trifid.java b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Trifid.java index 29439bc..867b1af 100644 --- a/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Trifid.java +++ b/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Trifid.java @@ -1,23 +1,3 @@ -//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/polysubstitution/Trifid.java -//Mattrixwv -// Created: 03-03-22 -//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 . -*/ package com.mattrixwv.cipherstream.polysubstitution; @@ -37,7 +17,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; * The {@code Trifid} class implements the Trifid cipher, a polyalphabetic substitution cipher * that uses a 3x3x3 grid to encode and decode messages. */ -public class Trifid{ +public final class Trifid{ private static final Logger logger = LoggerFactory.getLogger(Trifid.class); /** A class representing the location of a character in the grid */ diff --git a/src/test/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquareTest.java b/src/test/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquareTest.java index f316722..f25c7e8 100644 --- a/src/test/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquareTest.java +++ b/src/test/java/com/mattrixwv/cipherstream/polysubstitution/PolybiusSquareTest.java @@ -121,7 +121,7 @@ public class PolybiusSquareTest{ assertEquals('A', cipher.replaced); verify(logger, times(1)).debug("Setting replaced"); - verify(logger, times(1)).debug("Original character {}", 'a'); + verify(logger, times(1)).debug("Validating replaced character {}", 'a'); verify(logger, times(1)).debug("Checking replacer"); verify(logger, times(1)).debug("Cleaned character {}", 'A'); } @@ -134,7 +134,7 @@ public class PolybiusSquareTest{ assertEquals('J', cipher.replaced); verify(logger, times(1)).debug("Setting replaced"); - verify(logger, times(1)).debug("Original character {}", '1'); + verify(logger, times(1)).debug("Validating replaced character {}", '1'); verify(logger, never()).debug("Checking replacer"); verify(logger, never()).debug(eq("Cleaned character {}"), anyChar()); } @@ -147,7 +147,7 @@ public class PolybiusSquareTest{ assertEquals('J', cipher.replaced); verify(logger, times(1)).debug("Setting replaced"); - verify(logger, times(1)).debug("Original character {}", cipher.replacer); + verify(logger, times(1)).debug("Validating replaced character {}", cipher.replacer); verify(logger, times(1)).debug("Checking replacer"); verify(logger, never()).debug(eq("Cleaned character {}"), anyChar()); } @@ -158,7 +158,7 @@ public class PolybiusSquareTest{ assertEquals('A', cipher.replacer); verify(logger, times(1)).debug("Setting replacer"); - verify(logger, times(1)).debug("Original character {}", 'a'); + verify(logger, times(1)).debug("Validating replacer character {}", 'a'); verify(logger, times(1)).debug("Checking replaced"); verify(logger, times(1)).debug("Cleaned character {}", 'A'); } @@ -171,7 +171,7 @@ public class PolybiusSquareTest{ assertEquals('I', cipher.replacer); verify(logger, times(1)).debug("Setting replacer"); - verify(logger, times(1)).debug("Original character {}", '1'); + verify(logger, times(1)).debug("Validating replacer character {}", '1'); verify(logger, never()).debug("Checking replaced"); verify(logger, never()).debug(eq("Cleaned character {}"), anyChar()); } @@ -184,7 +184,7 @@ public class PolybiusSquareTest{ assertEquals('I', cipher.replacer); verify(logger, times(1)).debug("Setting replacer"); - verify(logger, times(1)).debug("Original character {}", cipher.replaced); + verify(logger, times(1)).debug("Validating replacer character {}", cipher.replaced); verify(logger, times(1)).debug("Checking replaced"); verify(logger, never()).debug(eq("Cleaned character {}"), anyChar()); }