Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ab98335814
|
|||
|
09eac66309
|
|||
|
d710375595
|
|||
|
8e41b0a2ad
|
|||
|
1943f19b4e
|
|||
|
ec0bf31906
|
|||
|
d12eb91245
|
|||
| f419e6020b | |||
| f9f61081bc | |||
| dc81847123 | |||
| a1ec1909d4 | |||
| 6b420338df |
2
.mvn/maven.config
Normal file
2
.mvn/maven.config
Normal file
@@ -0,0 +1,2 @@
|
||||
-Dstyle.color=always
|
||||
-T1C
|
||||
57
README.md
57
README.md
@@ -1,15 +1,18 @@
|
||||
# Cipher Stream Java
|
||||
This is a Java port of the C++ library [Cipher Stream](https://bitbucket.org/Mattrixwv/CipherStream)
|
||||
|
||||
[](https://sonarqube.mattrixwv.com/dashboard?id=CipherStreamJava)
|
||||
|
||||
This is a Java port of the C++ library [Cipher Stream](https://git.mattrixwv.com/BaseLibraries/CipherStream)
|
||||
|
||||
## Combination
|
||||
|
||||
TODO:
|
||||
|
||||
### ADFGX
|
||||
|
||||
TODO:
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Square Keyword = SQUAREKEYWORD
|
||||
Keyword = KEYWORD
|
||||
Message = Message to encode
|
||||
@@ -17,114 +20,114 @@ AAGAGADFAGAXXDAXDXADAFAFXDDGDF
|
||||
```
|
||||
|
||||
### ADFGVX
|
||||
|
||||
TODO:
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Square Keyword = SQUAREKEYWORD
|
||||
Keyword = KEYWORD
|
||||
Message = Message to encode
|
||||
AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA
|
||||
```
|
||||
|
||||
|
||||
## Mono-Substitution
|
||||
|
||||
These are simple ciphers where a single character is transformed into a single or multiple characters the same way each time it is encountered in the input. These are simple ciphers and easy to break.
|
||||
|
||||
### BaseX
|
||||
|
||||
This is not technically a cipher, it simply converts ASCII characters to their numeric values at a given base. The most common use for this is to transform text to binary, octal, or hexadecimal. Strictly speaking it does not require a key, however you do need to include the base that you wish to use.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to encode ->
|
||||
1001101 1100101 1110011 1110011 1100001 1100111 1100101 100000 1110100 1101111 100000 1100101 1101110 1100011 1101111 1100100 1100101
|
||||
```
|
||||
|
||||
### Baconian
|
||||
|
||||
The Baconian cipher is similar to Base2 encoding (binary) except that the alphabet starts at A = 0, instead of 0's and 1's it uses a's and b's, and I and J share an encoding space, as do U and V. It does not require a key.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to encode ->
|
||||
ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa
|
||||
```
|
||||
|
||||
### Caesar
|
||||
|
||||
The Caesar cipher offsets the letters in the alphabet by a given amount. It does require a "key" of sorts in that you must set how far the message needs to be shifted.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
offset = 3
|
||||
Message to encode ->
|
||||
Phvvdjh wr hqfrgh
|
||||
```
|
||||
|
||||
### Atbash
|
||||
|
||||
The Atbash cipher reverses the alphabet for encryption. i.e. a = z, b = y, .... It does not require a key.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to enocde ->
|
||||
Nvhhztv gl vmxlwv
|
||||
```
|
||||
|
||||
### Vigenere
|
||||
|
||||
TODO: The Vigenere cipher shifts each letter in the input a varied amount based on the letters in the key, with 'a' shifting the letter 0 places, 'b' shifting the letter 1 place, etc. If the message is longer than the key you simply start back over at the beginning of the key. It does require a key word/phrase.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
key = keyword
|
||||
Message to encode ->
|
||||
Wiqooxh ds cjqfgo
|
||||
```
|
||||
|
||||
### Autokey
|
||||
|
||||
The Autokey cipher works in a similar way to the Vigenere cipher except that instead of reusing the key when you reach the end of it, you tack on the beginning of the message to the key. This way the key does not repeat, making it harder to crack. It does require a key word/phrase.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
key = keyword
|
||||
Message to encode ->
|
||||
Wiqooxh fs wfcuhx
|
||||
```
|
||||
|
||||
|
||||
## Poly-Substitution
|
||||
|
||||
These ciphers are slightly more complex, encoding multiple letters at the same time making the cipher harder to crack. While many of these keep one letter from always being encoded as another single letter it often does so in such a way that if multiple letters are often seen together they will be encoded the same way. This is offset somewhat because they have to appear in the same location in the cipher text % the number of letters you are encoding by. i.e. If you are using a cipher that encodes with pairs the 'es' in 'mess' and 'these' would not encode to the same thing because 'me' and 'ss' are encoded in the first example while 'th', 'es', 'e_' are encoded in the second, unless there were an odd number of characters before one of these words, shifting one of the words by one place.
|
||||
|
||||
### Columnar
|
||||
|
||||
TODO:
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
key = keyword
|
||||
Message to encode ->
|
||||
Edxeoxm te acxgoxsnxsex
|
||||
```
|
||||
|
||||
### Morse
|
||||
|
||||
This is technically not a cipher, at least any more than writing is encoded speach, as it is meant to enocde information for transmission in a different media. It has been around for a long time and used to be widely known and used, though in recent years it is mainly used by hobbyists. Using this code a letter or number is converted to 1 or more .'s and -'s (dots and dashes or dits and dahs). It does not require a key.
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to encode ->
|
||||
-- . ... ... .- --. . - --- . -. -.-. --- -.. .
|
||||
```
|
||||
|
||||
### Playfair
|
||||
|
||||
TODO:
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to encode ->
|
||||
NKQZPCNDZKDULCGD
|
||||
```
|
||||
|
||||
### PolybiusSquare
|
||||
|
||||
TODO:
|
||||
|
||||
Example:
|
||||
```
|
||||
```txt
|
||||
Message to encode ->
|
||||
41124545233212 5115 124225152212
|
||||
```
|
||||
|
||||
369
pom.xml
369
pom.xml
@@ -14,19 +14,19 @@
|
||||
<developer>
|
||||
<name>Matthew Ellison</name>
|
||||
<email>m_ellison@ymail.com</email>
|
||||
<url>https://bitbucket.org/Mattrixwv</url>
|
||||
<url>https://git.mattrixwv.com/matthew</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git://bitbucket.org/Mattrixwv/CipherStreamJava.git</connection>
|
||||
<developerConnection>scm:git:ssh://bitbucket.org:Mattrixwv/CipherStreamJava.git</developerConnection>
|
||||
<url>https://bitbucket.org/Mattrixwv/CipherStreamJava/src</url>
|
||||
<connection>scm:git:git://git.mattrixwv.com/HomeLab/CipherStreamJava.git</connection>
|
||||
<developerConnection>scm:git:ssh://git.mattrixwv.com/HomeLab/CipherStreamJava.git</developerConnection>
|
||||
<url>https://git.mattrixwv.com/HomeLab/CipherStreamJava</url>
|
||||
</scm>
|
||||
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>cipher-stream-java</artifactId>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
|
||||
<name>CipherStreamJava</name>
|
||||
<description>A library to encrypt and decrypt simple ciphers</description>
|
||||
@@ -37,17 +37,16 @@
|
||||
<!--Compile-->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<java.version>25</java.version>
|
||||
|
||||
<!--Sonarqube-->
|
||||
<sonar.java.source>21</sonar.java.source>
|
||||
<sonar.java.source>25</sonar.java.source>
|
||||
<sonar.dependencyCheck.jsonReportPath>target/dependency-check-report.json</sonar.dependencyCheck.jsonReportPath>
|
||||
<sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
|
||||
|
||||
<!--Deployment-->
|
||||
<gpg.keyname>3BA6515C8FF145249BEBBEABA52FDEC4259179D4</gpg.keyname>
|
||||
<argLine></argLine>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -55,47 +54,47 @@
|
||||
<dependency>
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>myClasses</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>matrix</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.16</version>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
|
||||
<!--Test-->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.11.4</version>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>6.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.11.4</version>
|
||||
<version>6.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.15.2</version>
|
||||
<version>5.21.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>5.15.2</version>
|
||||
<version>5.21.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -109,163 +108,55 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--Ensure maven is the correct version-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.8.6</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>${java.version}</release>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
</compilerArgs>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.21.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.18.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>5.0.0.4389</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.12</version>
|
||||
<version>3.9.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
<goal>properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<version>12.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>none</phase>
|
||||
<id>dependency-check</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>json</format>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<nvdApiServerId>nvd</nvdApiServerId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--Deployment-->
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.7.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>ossrh</publishingServerId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.7.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@@ -275,11 +166,9 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -289,11 +178,9 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.2.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
@@ -301,23 +188,201 @@
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<keyname>${gpg.keyname}</keyname>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!--Ensure maven is the correct version-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.6.2</version>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.8.6</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<release>${java.version}</release>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
<arg>-Xlint:-serial</arg>
|
||||
</compilerArgs>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<configuration>
|
||||
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.21.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>5.5.0.6356</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.14</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<version>12.2.0</version>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>json</format>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<nvdApiServerId>nvd</nvdApiServerId>
|
||||
<failBuildOnCVSS>7</failBuildOnCVSS>
|
||||
<ossIndexServerId>ossindex</ossIndexServerId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<!--Deployment-->
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.10.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.2.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare;
|
||||
* <li>Encoding/decoding with a columnar transposition cipher (Columnar)</li>
|
||||
* </ol>
|
||||
*/
|
||||
public class ADFGVX{
|
||||
public final class ADFGVX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class);
|
||||
//?Fields
|
||||
/** The string that needs encoded/decoded */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -43,7 +23,7 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
* <li>Encoding/decoding with a columnar transposition cipher (Columnar)</li>
|
||||
* </ol>
|
||||
*/
|
||||
public class ADFGX{
|
||||
public final class ADFGX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ADFGX.class);
|
||||
|
||||
//?Internal fields
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidBaseException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidCharacterException.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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidInputException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/exceptions/InvalidKeyException.java
|
||||
//Matrixwv
|
||||
// Created: 07-09-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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidKeywordException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
* <li><strong>Key2</strong>: The additive key</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class Affine{
|
||||
public final class Affine{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
|
||||
//?Fields
|
||||
/** The string that needs encoded/decoded */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* </p>
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
* and sequences are converted back to letters for decoding.
|
||||
* </p>
|
||||
*/
|
||||
public class Baconian{
|
||||
public final class Baconian{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
|
||||
//?Conversions
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -42,7 +22,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
* for the specified base.
|
||||
* </p>
|
||||
*/
|
||||
public class BaseX{
|
||||
public final class BaseX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
//?Fields
|
||||
/** The string that needs encoded/decoded */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -37,7 +17,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
* capitalization, whitespace, and symbols.
|
||||
* </p>
|
||||
*/
|
||||
public class Caesar{
|
||||
public final class Caesar{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
//?Fields
|
||||
/** The string that needs encoded/decoded */
|
||||
@@ -64,6 +44,11 @@ public class Caesar{
|
||||
logger.debug("Setting shift {}", shiftAmount);
|
||||
|
||||
//If you shift more than 26 you will just be wrapping back around again
|
||||
if(shiftAmount < 0){
|
||||
logger.debug("Negative shift detected, converting to positive equivalent");
|
||||
|
||||
shiftAmount += 26;
|
||||
}
|
||||
shift = shiftAmount % 26;
|
||||
|
||||
logger.debug("Cleaned shift {}", shift);
|
||||
@@ -120,7 +105,7 @@ public class Caesar{
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
currentChar += shift;
|
||||
currentChar = (char)(currentChar + shift);
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
@@ -135,7 +120,7 @@ public class Caesar{
|
||||
else if(Character.isLowerCase(currentChar)){
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
currentChar += shift;
|
||||
currentChar = (char)(currentChar + shift);
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
@@ -170,7 +155,7 @@ public class Caesar{
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
logger.debug("Decoding uppercase");
|
||||
|
||||
currentChar -= shift;
|
||||
currentChar = (char)(currentChar - shift);
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
@@ -187,7 +172,7 @@ public class Caesar{
|
||||
else if(Character.isLowerCase(currentChar)){
|
||||
logger.debug("Decoding lowercase");
|
||||
|
||||
currentChar -= shift;
|
||||
currentChar = (char)(currentChar - shift);
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
* certain characters based on configuration settings.
|
||||
* </p>
|
||||
*/
|
||||
public class Porta{
|
||||
public final class Porta{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
|
||||
/** Predefined alphabetic tableau used for encoding and decoding */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -39,7 +19,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
* of the alphabet and optionally digits, without duplicates.
|
||||
* </p>
|
||||
*/
|
||||
public class Substitution{
|
||||
public final class Substitution{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Substitution.class);
|
||||
//?Fields
|
||||
/** The string that needs encoded/decoded */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
* them back into text.
|
||||
* </p>
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* </p>
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* </p>
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* </p>
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGVX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -29,12 +25,12 @@ public class ADFGVXTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private static final String encodedStringClean = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String squareKeyword = "SquareKeyword";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private static final String ENCODED_STRING_CLEAN = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -99,10 +95,10 @@ public class ADFGVXTest{
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword(){
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
cipher.setSquareKeyword(SQUARE_KEYWORD);
|
||||
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("squareKeyword '{}'", squareKeyword);
|
||||
assertEquals(SQUARE_KEYWORD, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("squareKeyword '{}'", SQUARE_KEYWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,10 +113,10 @@ public class ADFGVXTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("keyword '{}'", keyword);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
verify(logger, times(1)).debug("keyword '{}'", KEYWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,14 +135,14 @@ public class ADFGVXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,14 +151,14 @@ public class ADFGVXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,14 +167,14 @@ public class ADFGVXTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,14 +183,14 @@ public class ADFGVXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,45 +231,45 @@ public class ADFGVXTest{
|
||||
|
||||
@Test
|
||||
public void testFormateOutputStringEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedStringClean;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||
|
||||
cipher.formatOutputStringEncode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol to output");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOutputStringDecode(){
|
||||
cipher.outputString = decodedStringClean;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.outputString = DECODED_STRING_CLEAN;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.formatOutputStringDecode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol to output");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding using Polybius Square");
|
||||
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
||||
verify(logger, times(1)).debug("Encoding using columnar");
|
||||
@@ -281,13 +277,13 @@ public class ADFGVXTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding using columnar");
|
||||
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||
@@ -295,25 +291,25 @@ public class ADFGVXTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(squareKeyword, cipher.getSquareKeyword());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(SQUARE_KEYWORD, cipher.getSquareKeyword());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
LargePolybiusSquare ps = cipher.largePolybiusSquare;
|
||||
Columnar columnar = cipher.columnar;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -330,47 +326,47 @@ public class ADFGVXTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new ADFGVX(true, true, true);
|
||||
|
||||
String output = cipher.encode(squareKeyword, keyword, decodedString);
|
||||
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new ADFGVX(false, false, false);
|
||||
|
||||
String output = cipher.encode(squareKeyword, keyword, decodedString);
|
||||
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new ADFGVX(true, true, true);
|
||||
|
||||
String output = cipher.decode(squareKeyword, keyword, encodedString);
|
||||
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new ADFGVX(false, false, false);
|
||||
|
||||
String output = cipher.decode(squareKeyword, keyword, encodedString);
|
||||
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-25-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -29,12 +25,12 @@ public class ADFGXTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private static final String encodedStringClean = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String squareKeyword = "SquareKeyword";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private static final String ENCODED_STRING_CLEAN = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -99,9 +95,9 @@ public class ADFGXTest{
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword(){
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("Square keyword '{}'", squareKeyword);
|
||||
cipher.setSquareKeyword(SQUARE_KEYWORD);
|
||||
assertEquals(SQUARE_KEYWORD, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("Square keyword '{}'", SQUARE_KEYWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,10 +112,10 @@ public class ADFGXTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Keyword '{}'", keyword);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Keyword '{}'", KEYWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,14 +134,14 @@ public class ADFGXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,14 +150,14 @@ public class ADFGXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,14 +166,14 @@ public class ADFGXTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,14 +182,14 @@ public class ADFGXTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,45 +230,45 @@ public class ADFGXTest{
|
||||
|
||||
@Test
|
||||
public void testFormatOutputStringEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedStringClean;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||
|
||||
cipher.formatOutputStringEncode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol to output");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOutputStringDecode(){
|
||||
cipher.outputString = decodedStringClean;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.outputString = DECODED_STRING_CLEAN;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.formatOutputStringDecode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol to output");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding using Polybius Square");
|
||||
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
||||
verify(logger, times(1)).debug("Encoding using columnar");
|
||||
@@ -280,13 +276,13 @@ public class ADFGXTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding using columnar");
|
||||
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||
@@ -294,25 +290,25 @@ public class ADFGXTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(squareKeyword, cipher.getSquareKeyword());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(SQUARE_KEYWORD, cipher.getSquareKeyword());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
PolybiusSquare polybius = cipher.polybiusSquare;
|
||||
Columnar columnar = cipher.columnar;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.squareKeyword = squareKeyword;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -329,47 +325,47 @@ public class ADFGXTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new ADFGX(true, true, true);
|
||||
|
||||
String output = cipher.encode(squareKeyword, keyword, decodedString);
|
||||
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new ADFGX(false, false, false);
|
||||
|
||||
String output = cipher.encode(squareKeyword, keyword, decodedString);
|
||||
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new ADFGX(true, true, true);
|
||||
|
||||
String output = cipher.decode(squareKeyword, keyword, encodedString);
|
||||
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new ADFGX(false, false, false);
|
||||
|
||||
String output = cipher.decode(squareKeyword, keyword, encodedString);
|
||||
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java
|
||||
//Mattrixwv
|
||||
// Created: 04-14-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class InvalidBaseExceptionTest{
|
||||
private static final String message = "message";
|
||||
private static final Throwable cause = new Exception();
|
||||
private static final String MESSAGE = "message";
|
||||
private static final Throwable CAUSE = new Exception();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -24,22 +20,22 @@ public class InvalidBaseExceptionTest{
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidBaseException exception = new InvalidBaseException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
InvalidBaseException exception = new InvalidBaseException(MESSAGE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidBaseException exception = new InvalidBaseException(cause);
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidBaseException exception = new InvalidBaseException(CAUSE);
|
||||
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageAndCause(){
|
||||
InvalidBaseException exception = new InvalidBaseException(message, cause);
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidBaseException exception = new InvalidBaseException(MESSAGE, CAUSE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidcharacterException.java
|
||||
//Mattrixwv
|
||||
// Created: 04-14-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class InvalidCharacterExceptionTest{
|
||||
private String message = "message";
|
||||
private Throwable cause = new Exception();
|
||||
private static final String MESSAGE = "message";
|
||||
private static final Throwable CAUSE = new Exception();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -24,22 +20,22 @@ public class InvalidCharacterExceptionTest{
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidCharacterException exception = new InvalidCharacterException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
InvalidCharacterException exception = new InvalidCharacterException(MESSAGE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidCharacterException exception = new InvalidCharacterException(cause);
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidCharacterException exception = new InvalidCharacterException(CAUSE);
|
||||
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageAndCause(){
|
||||
InvalidCharacterException exception = new InvalidCharacterException(message, cause);
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidCharacterException exception = new InvalidCharacterException(MESSAGE, CAUSE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exception/TestInvalidInputException.java
|
||||
//Mattrixwv
|
||||
// Created: 04-14-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class InvalidInputExceptionTest{
|
||||
private String message = "message";
|
||||
private Throwable cause = new Exception();
|
||||
private static final String MESSAGE = "message";
|
||||
private static final Throwable CAUSE = new Exception();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -24,22 +20,22 @@ public class InvalidInputExceptionTest{
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidInputException exception = new InvalidInputException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
InvalidInputException exception = new InvalidInputException(MESSAGE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidInputException exception = new InvalidInputException(cause);
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidInputException exception = new InvalidInputException(CAUSE);
|
||||
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageAndCause(){
|
||||
InvalidInputException exception = new InvalidInputException(message, cause);
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidInputException exception = new InvalidInputException(MESSAGE, CAUSE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java
|
||||
//Mattrixwv
|
||||
// Created: 04-14-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class InvalidKeyExceptionTest{
|
||||
public String message = "message";
|
||||
public Throwable cause = new Exception();
|
||||
public static final String MESSAGE = "message";
|
||||
public static final Throwable CAUSE = new Exception();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -24,22 +20,22 @@ public class InvalidKeyExceptionTest{
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidKeyException exception = new InvalidKeyException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
InvalidKeyException exception = new InvalidKeyException(MESSAGE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidKeyException exception = new InvalidKeyException(cause);
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidKeyException exception = new InvalidKeyException(CAUSE);
|
||||
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageAndCause(){
|
||||
InvalidKeyException exception = new InvalidKeyException(message, cause);
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidKeyException exception = new InvalidKeyException(MESSAGE, CAUSE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java
|
||||
//Mattrixwv
|
||||
// Created: 04-14-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class InvalidKeywordExceptionTest{
|
||||
private String message = "message";
|
||||
private Throwable cause = new Exception();
|
||||
private static final String MESSAGE = "message";
|
||||
private static final Throwable CAUSE = new Exception();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -24,22 +20,22 @@ public class InvalidKeywordExceptionTest{
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidKeywordException exception = new InvalidKeywordException(message);
|
||||
assertEquals(message, exception.getMessage());
|
||||
InvalidKeywordException exception = new InvalidKeywordException(MESSAGE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidKeywordException exception = new InvalidKeywordException(cause);
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidKeywordException exception = new InvalidKeywordException(CAUSE);
|
||||
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageAndCause(){
|
||||
InvalidKeywordException exception = new InvalidKeywordException(message, cause);
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
InvalidKeywordException exception = new InvalidKeywordException(MESSAGE, CAUSE);
|
||||
assertEquals(MESSAGE, exception.getMessage());
|
||||
assertEquals(CAUSE, exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/AffineTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,12 +23,12 @@ public class AffineTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "MEssage to^encode";
|
||||
private static final String decodedStringClean = "messagetoencode";
|
||||
private static final String encodedString = "PBtthlb yz^burzwb";
|
||||
private static final String encodedStringClean = "pbtthlbyzburzwb";
|
||||
private static final int key1 = 5;
|
||||
private static final int key2 = 7;
|
||||
private static final String DECODED_STRING = "MEssage to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "messagetoencode";
|
||||
private static final String ENCODED_STRING = "PBtthlb yz^burzwb";
|
||||
private static final String ENCODED_STRING_CLEAN = "pbtthlbyzburzwb";
|
||||
private static final int KEY_1 = 5;
|
||||
private static final int KEY_2 = 7;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -89,11 +85,11 @@ public class AffineTest{
|
||||
|
||||
@Test
|
||||
public void testKey1(){
|
||||
cipher.setKey1(key1);
|
||||
cipher.setKey1(KEY_1);
|
||||
|
||||
assertEquals(key1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", key1);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", KEY_1);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", KEY_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,20 +113,20 @@ public class AffineTest{
|
||||
|
||||
@Test
|
||||
public void testSetKey1_large(){
|
||||
cipher.setKey1(key1 + 26);
|
||||
cipher.setKey1(KEY_1 + 26);
|
||||
|
||||
assertEquals(key1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", key1 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", KEY_1 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", KEY_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey2(){
|
||||
cipher.setKey2(key2);
|
||||
cipher.setKey2(KEY_2);
|
||||
|
||||
assertEquals(key2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", key2);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", KEY_2);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", KEY_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,11 +140,11 @@ public class AffineTest{
|
||||
|
||||
@Test
|
||||
public void testSetKey2_large(){
|
||||
cipher.setKey2(key2 + 26);
|
||||
cipher.setKey2(KEY_2 + 26);
|
||||
|
||||
assertEquals(key2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", key2 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", KEY_2 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", KEY_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,14 +153,14 @@ public class AffineTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,14 +169,14 @@ public class AffineTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toLowerCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toLowerCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,14 +185,14 @@ public class AffineTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing sybols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,14 +201,14 @@ public class AffineTest{
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,17 +252,17 @@ public class AffineTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.key1 = key1;
|
||||
cipher.key2 = key2;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.key1 = KEY_1;
|
||||
cipher.key2 = KEY_2;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Encoded char {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,39 +270,39 @@ public class AffineTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.key1 = key1;
|
||||
cipher.key2 = key2;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.key1 = KEY_1;
|
||||
cipher.key2 = KEY_2;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Key1 inverse {}", 21);
|
||||
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Decoded char {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.key1 = key1;
|
||||
cipher.key2 = key2;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.key1 = KEY_1;
|
||||
cipher.key2 = KEY_2;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(key1, cipher.getKey1());
|
||||
assertEquals(key2, cipher.getKey2());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEY_1, cipher.getKey1());
|
||||
assertEquals(KEY_2, cipher.getKey2());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.key1 = key1;
|
||||
cipher.key2 = key2;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.key1 = KEY_1;
|
||||
cipher.key2 = KEY_2;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -321,51 +317,51 @@ public class AffineTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Affine(true, true, true);
|
||||
|
||||
String output = cipher.encode(key1, key2, decodedString);
|
||||
String output = cipher.encode(KEY_1, KEY_2, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(key1, cipher.key1);
|
||||
assertEquals(key2, cipher.key2);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Affine(false, false, false);
|
||||
|
||||
String output = cipher.encode(key1, key2, decodedString);
|
||||
String output = cipher.encode(KEY_1, KEY_2, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(key1, cipher.key1);
|
||||
assertEquals(key2, cipher.key2);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Affine(true, true, true);
|
||||
|
||||
String output = cipher.decode(key1, key2, encodedString);
|
||||
String output = cipher.decode(KEY_1, KEY_2, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(key1, cipher.key1);
|
||||
assertEquals(key2, cipher.key2);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testpracticalDecoding_clean(){
|
||||
cipher = new Affine(false, false, false);
|
||||
|
||||
String output = cipher.decode(key1, key2, encodedString);
|
||||
String output = cipher.decode(KEY_1, KEY_2, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(key1, cipher.key1);
|
||||
assertEquals(key2, cipher.key2);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEY_1, cipher.key1);
|
||||
assertEquals(KEY_2, cipher.key2);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/AtbashTest.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -26,10 +22,10 @@ public class AtbashTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
private static final String encodedStringClean = "NVHHZTVGLVMXLWV";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private static final String ENCODED_STRING_CLEAN = "NVHHZTVGLVMXLWV";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -78,17 +74,17 @@ public class AtbashTest{
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(17)).debug(eq("Encoding char {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,14 +93,14 @@ public class AtbashTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,14 +109,14 @@ public class AtbashTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,14 +125,14 @@ public class AtbashTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,14 +141,14 @@ public class AtbashTest{
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +174,7 @@ public class AtbashTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString("");
|
||||
@@ -194,17 +190,17 @@ public class AtbashTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -217,43 +213,43 @@ public class AtbashTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Atbash(true, true, true);
|
||||
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Atbash(false, false, false);
|
||||
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Atbash(true, true, true);
|
||||
|
||||
String output = cipher.decode(encodedString);
|
||||
String output = cipher.decode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Atbash(false, false, false);
|
||||
|
||||
String output = cipher.decode(encodedString);
|
||||
String output = cipher.decode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/AutokeyTest.java
|
||||
//Mattrixwv
|
||||
// Created: 07-26-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,12 +23,12 @@ public class AutokeyTest{
|
||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.Autokey")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "MeSsage to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "WiQooxh fs^wfcuhx";
|
||||
private static final String encodedStringClean = "WIQOOXHFSWFCUHX";
|
||||
private static final String keyword = "keyword";
|
||||
private static final ArrayList<Integer> offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3, 12, 4, 18, 18, 0, 6, 4, 19));
|
||||
private static final String DECODED_STRING = "MeSsage to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "WiQooxh fs^wfcuhx";
|
||||
private static final String ENCODED_STRING_CLEAN = "WIQOOXHFSWFCUHX";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final ArrayList<Integer> OFFSET = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3, 12, 4, 18, 18, 0, 6, 4, 19));
|
||||
|
||||
|
||||
@Test
|
||||
@@ -93,11 +89,11 @@ public class AutokeyTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.encodeSet(keyword, decodedString);
|
||||
cipher.encodeSet(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals((keyword + decodedString.replaceAll("\\s", "").replaceAll("[^a-zA-Z\\s]", "").substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals((KEYWORD + DECODED_STRING.replaceAll("\\s", "").replaceAll("[^a-zA-Z\\s]", "").substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(OFFSET, cipher.offset);
|
||||
verify(logger, times(1)).debug("Setting fields for encoding");
|
||||
verify(logger, times(1)).debug("Setting keyword");
|
||||
verify(logger, times(1)).debug("Adding input to keyword");
|
||||
@@ -110,10 +106,10 @@ public class AutokeyTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.decodeSet(keyword, decodedString);
|
||||
cipher.decodeSet(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting fields for decoding");
|
||||
verify(logger, times(1)).debug("Setting keyword");
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
@@ -124,11 +120,11 @@ public class AutokeyTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.decodeSet(keyword, encodedString);
|
||||
cipher.decodeSet(KEYWORD, ENCODED_STRING);
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(2)).debug("Appending partial output to keyword");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
@@ -137,27 +133,27 @@ public class AutokeyTest{
|
||||
verify(logger, times(13)).debug("Appending lowercase");
|
||||
verify(logger, times(3)).debug("Wrapping around to z");
|
||||
verify(logger, times(17)).debug(eq("Decoded letter {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.offset.add(1);
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
assertEquals(new ArrayList<>(List.of(1)), cipher.getOffsets());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.offset.add(1);
|
||||
|
||||
cipher.reset();
|
||||
@@ -172,47 +168,47 @@ public class AutokeyTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Autokey(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals((keyword + decodedStringClean.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Autokey(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals((keyword + decodedStringClean.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Autokey(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals((keyword + decodedStringClean.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testpracticalDecoding_clean(){
|
||||
cipher = new Autokey(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals((keyword + decodedStringClean.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/BaconianTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,10 +23,10 @@ public class BaconianTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to-encode";
|
||||
private static final String decodedStringClean = "Messagetoencode";
|
||||
private static final String decodedStringCleanLower = "messagetoencode";
|
||||
private static final String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String DECODED_STRING = "Message to-encode";
|
||||
private static final String DECODED_STRING_CLEAN = "Messagetoencode";
|
||||
private static final String DECODED_STRING_CLEAN_LOWER = "messagetoencode";
|
||||
private static final String ENCODED_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -55,24 +51,24 @@ public class BaconianTest{
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.preserveCapitals = true;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringClean);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_noCapitals(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringCleanLower, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringCleanLower);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_CLEAN_LOWER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,30 +103,30 @@ public class BaconianTest{
|
||||
public void testSetInputStringDecode(){
|
||||
cipher.preserveCapitals = true;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring all 'letters' contain 5 characters");
|
||||
verify(logger, times(15)).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode_noCapitals(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring all 'letters' contain 5 characters");
|
||||
verify(logger, times(15)).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.toLowerCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.toLowerCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,49 +200,49 @@ public class BaconianTest{
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = decodedStringClean;
|
||||
cipher.inputString = DECODED_STRING_CLEAN;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(15)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(15)).debug(eq("Output letter {}"), anyString());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(15)).debug(eq("Working letter {}"), anyString());
|
||||
verify(logger, times(15)).debug(eq("Location of letter {}"), anyInt());
|
||||
verify(logger, times(1)).debug("Decoding uppercase");
|
||||
verify(logger, times(14)).debug("Decoding lowercase");
|
||||
verify(logger, times(15)).debug(eq("Decoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedStringClean);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -259,65 +255,65 @@ public class BaconianTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher.preserveCapitals = true;
|
||||
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringCleanLower, cipher.inputString);
|
||||
assertEquals(encodedString.toLowerCase(), cipher.outputString);
|
||||
assertEquals(encodedString.toLowerCase(), output);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), cipher.outputString);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher.preserveCapitals = true;
|
||||
|
||||
String output = cipher.decode(encodedString);
|
||||
String output = cipher.decode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
String output = cipher.decode(encodedString);
|
||||
String output = cipher.decode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
||||
assertEquals(decodedStringCleanLower, output);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_upper(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
String output = cipher.decode(encodedString.toUpperCase());
|
||||
String output = cipher.decode(ENCODED_STRING.toUpperCase());
|
||||
|
||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
||||
assertEquals(decodedStringCleanLower, output);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_lower(){
|
||||
cipher.preserveCapitals = false;
|
||||
|
||||
String output = cipher.decode(encodedString.toLowerCase());
|
||||
String output = cipher.decode(ENCODED_STRING.toLowerCase());
|
||||
|
||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
||||
assertEquals(decodedStringCleanLower, output);
|
||||
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_LOWER, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/BaseXTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -28,11 +24,11 @@ public class BaseXTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "A+B@C d\te\nf";
|
||||
private static final String encodedString_2 = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final String encodedString_8 = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
private static final String encodedString_10 = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
private static final String encodedString_16 = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
private static final String DECODED_STRING = "A+B@C d\te\nf";
|
||||
private static final String ENCODED_STRING_2 = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final String ENCODED_STRING_8 = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
private static final String ENCODED_STRING_10 = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
private static final String ENCODED_STRING_16 = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -55,10 +51,10 @@ public class BaseXTest{
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +74,7 @@ public class BaseXTest{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, never()).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
@@ -87,14 +83,14 @@ public class BaseXTest{
|
||||
public void testSetInputStringDecode(){
|
||||
cipher.base = 16;
|
||||
|
||||
cipher.setInputStringDecode(encodedString_16);
|
||||
cipher.setInputStringDecode(ENCODED_STRING_16);
|
||||
|
||||
assertEquals(encodedString_16, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString_16);
|
||||
assertEquals(ENCODED_STRING_16, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING_16);
|
||||
verify(logger, times(1)).debug("Creating string of valid 'numbers'");
|
||||
verify(logger, times(16)).debug(eq("Current number {}, converted {}"), anyInt(), anyString());
|
||||
verify(logger, times(1)).debug("Checking for invalid characters");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString_16);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING_16);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,29 +172,29 @@ public class BaseXTest{
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.base = 16;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString_16, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_16, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(11)).debug(eq("Working number {}"), anyChar());
|
||||
verify(logger, times(11)).debug(eq("Converted number {}"), anyString());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString_16);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING_16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.base = 16;
|
||||
cipher.inputString = encodedString_16;
|
||||
cipher.inputString = ENCODED_STRING_16;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(11)).debug(eq("Current number {}"), anyString());
|
||||
verify(logger, times(11)).debug(eq("Decoded number {}"), anyInt());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -218,19 +214,19 @@ public class BaseXTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString_2;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_2;
|
||||
cipher.base = 8;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString_2, cipher.getOutputString());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING_2, cipher.getOutputString());
|
||||
assertEquals(8, cipher.getBase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString_2;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_2;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -241,101 +237,101 @@ public class BaseXTest{
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_2(){
|
||||
String output = cipher.encode(2, decodedString);
|
||||
String output = cipher.encode(2, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(encodedString_2, cipher.outputString);
|
||||
assertEquals(encodedString_2, output);
|
||||
assertEquals(ENCODED_STRING_2, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_2, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_8(){
|
||||
String output = cipher.encode(8, decodedString);
|
||||
String output = cipher.encode(8, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(8, cipher.base);
|
||||
assertEquals(encodedString_8, cipher.outputString);
|
||||
assertEquals(encodedString_8, output);
|
||||
assertEquals(ENCODED_STRING_8, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_8, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_10(){
|
||||
String output = cipher.encode(10, decodedString);
|
||||
String output = cipher.encode(10, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(10, cipher.base);
|
||||
assertEquals(encodedString_10, cipher.outputString);
|
||||
assertEquals(encodedString_10, output);
|
||||
assertEquals(ENCODED_STRING_10, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_10, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_16(){
|
||||
String output = cipher.encode(16, decodedString);
|
||||
String output = cipher.encode(16, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(16, cipher.base);
|
||||
assertEquals(encodedString_16, cipher.outputString);
|
||||
assertEquals(encodedString_16, output);
|
||||
assertEquals(ENCODED_STRING_16, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_16, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_inputOnly(){
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(encodedString_2, cipher.outputString);
|
||||
assertEquals(encodedString_2, output);
|
||||
assertEquals(ENCODED_STRING_2, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_2, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_2(){
|
||||
String output = cipher.decode(2, encodedString_2);
|
||||
String output = cipher.decode(2, ENCODED_STRING_2);
|
||||
|
||||
assertEquals(encodedString_2, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_2, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_8(){
|
||||
String output = cipher.decode(8, encodedString_8);
|
||||
String output = cipher.decode(8, ENCODED_STRING_8);
|
||||
|
||||
assertEquals(encodedString_8, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_8, cipher.inputString);
|
||||
assertEquals(8, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_10(){
|
||||
String output = cipher.decode(10, encodedString_10);
|
||||
String output = cipher.decode(10, ENCODED_STRING_10);
|
||||
|
||||
assertEquals(encodedString_10, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_10, cipher.inputString);
|
||||
assertEquals(10, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_16(){
|
||||
String output = cipher.decode(16, encodedString_16);
|
||||
String output = cipher.decode(16, ENCODED_STRING_16);
|
||||
|
||||
assertEquals(encodedString_16, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_16, cipher.inputString);
|
||||
assertEquals(16, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_inputOnly(){
|
||||
String output = cipher.decode(encodedString_2);
|
||||
String output = cipher.decode(ENCODED_STRING_2);
|
||||
|
||||
assertEquals(encodedString_2, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_2, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/BeaufortTest.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,12 +23,12 @@ public class BeaufortTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Yageolz rq^ujmdag";
|
||||
private static final String encodedStringClean = "YAGEOLZRQUJMDAG";
|
||||
private static final String keyword = "Ke*y word";
|
||||
private static final String keywordClean = "KEYWORD";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Yageolz rq^ujmdag";
|
||||
private static final String ENCODED_STRING_CLEAN = "YAGEOLZRQUJMDAG";
|
||||
private static final String KEYWORD = "Ke*y word";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -125,14 +121,14 @@ public class BeaufortTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,14 +137,14 @@ public class BeaufortTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,14 +153,14 @@ public class BeaufortTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,14 +169,14 @@ public class BeaufortTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,13 +213,13 @@ public class BeaufortTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keywordClean);
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -268,51 +264,51 @@ public class BeaufortTest{
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Encoding with Atbash");
|
||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Encoding with Atbash");
|
||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -325,43 +321,43 @@ public class BeaufortTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Beaufort(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Beaufort(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/CaesarTest.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -26,11 +22,11 @@ public class CaesarTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "The quick brown fox jumps over - the lAzy dog";
|
||||
private static final String decodedStringClean = "thequickbrownfoxjumpsoverthelazydog";
|
||||
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
|
||||
private static final String encodedStringClean = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
||||
private static final int shift = 23;
|
||||
private static final String DECODED_STRING = "The quick brown fox jumps over - the lAzy dog";
|
||||
private static final String DECODED_STRING_CLEAN = "thequickbrownfoxjumpsoverthelazydog";
|
||||
private static final String ENCODED_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
|
||||
private static final String ENCODED_STRING_CLEAN = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
||||
private static final int SHIFT = 23;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -83,29 +79,29 @@ public class CaesarTest{
|
||||
|
||||
@Test
|
||||
public void testSetShift(){
|
||||
cipher.setShift(shift);
|
||||
cipher.setShift(SHIFT);
|
||||
|
||||
assertEquals(shift, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", shift);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", shift);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", SHIFT);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetShift_large(){
|
||||
cipher.setShift(shift + 26);
|
||||
cipher.setShift(SHIFT + 26);
|
||||
|
||||
assertEquals(shift, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", shift + 26);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", shift);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", SHIFT + 26);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetShift_negative(){
|
||||
cipher.setShift(shift - 26);
|
||||
cipher.setShift(SHIFT - 26);
|
||||
|
||||
assertEquals(shift - 26, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", shift - 26);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", shift - 26);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
verify(logger, times(1)).debug("Setting shift {}", SHIFT - 26);
|
||||
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,14 +110,14 @@ public class CaesarTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,14 +126,14 @@ public class CaesarTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toLowerCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toLowerCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,14 +142,14 @@ public class CaesarTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,14 +158,14 @@ public class CaesarTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,12 +206,12 @@ public class CaesarTest{
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.shift = shift;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.shift = SHIFT;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Encoding uppercase");
|
||||
@@ -225,17 +221,17 @@ public class CaesarTest{
|
||||
verify(logger, never()).debug("Wrapping around to z");
|
||||
verify(logger, times(31)).debug("Wrapping around to a");
|
||||
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode_negative(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.shift = shift - 26;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.shift = SHIFT - 26;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Encoding uppercase");
|
||||
@@ -245,17 +241,17 @@ public class CaesarTest{
|
||||
verify(logger, times(2)).debug("Wrapping around to z");
|
||||
verify(logger, never()).debug("Wrapping around to a");
|
||||
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.shift = shift;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.shift = SHIFT;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Decoding uppercase");
|
||||
@@ -265,17 +261,17 @@ public class CaesarTest{
|
||||
verify(logger, times(31)).debug("Wrapping around to z");
|
||||
verify(logger, never()).debug("Wrapping around to a");
|
||||
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode_negative(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.shift = shift - 26;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.shift = SHIFT - 26;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Decoding uppercase");
|
||||
@@ -285,25 +281,25 @@ public class CaesarTest{
|
||||
verify(logger, never()).debug("Wrapping around to z");
|
||||
verify(logger, times(2)).debug("Wrapping around to a");
|
||||
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.shift = shift;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.shift = SHIFT;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(shift, cipher.getShift());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(SHIFT, cipher.getShift());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.shift = shift;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.shift = SHIFT;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -317,70 +313,70 @@ public class CaesarTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Caesar(true, true, true);
|
||||
|
||||
String output = cipher.encode(shift, decodedString);
|
||||
String output = cipher.encode(SHIFT, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(shift, cipher.shift);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Caesar(false, false, false);
|
||||
|
||||
String output = cipher.encode(shift, decodedString);
|
||||
String output = cipher.encode(SHIFT, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(shift, cipher.shift);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_negative(){
|
||||
cipher = new Caesar(true, true, true);
|
||||
|
||||
String output = cipher.encode(shift, decodedString);
|
||||
String output = cipher.encode(-3, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(shift, cipher.shift);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Caesar(true, true, true);
|
||||
|
||||
String output = cipher.decode(shift, encodedString);
|
||||
String output = cipher.decode(SHIFT, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(shift, cipher.shift);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Caesar(false, false, false);
|
||||
|
||||
String output = cipher.decode(shift, encodedString);
|
||||
String output = cipher.decode(SHIFT, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(shift, cipher.shift);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_negative(){
|
||||
cipher = new Caesar(true, true, true);
|
||||
String output = cipher.decode(shift - 26, encodedString);
|
||||
String output = cipher.decode(SHIFT - 26, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(shift - 26, cipher.shift);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(SHIFT, cipher.shift);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/OneTimePadTest.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -29,12 +25,12 @@ public class OneTimePadTest{
|
||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.OneTimePad")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Wiqooxh mv^egkgws";
|
||||
private static final String encodedStringClean = "WIQOOXHMVEGKGWS";
|
||||
private static final String keyword = "keywordThatIsTotallyRandom";
|
||||
private static final ArrayList<Integer> offset = new ArrayList<>(Arrays.asList(10, 4, 24, 22, 14, 17, 3, 19, 7, 0, 19, 8, 18, 19, 14, 19, 0, 11, 11, 24, 17, 0, 13, 3, 14, 12));
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Wiqooxh mv^egkgws";
|
||||
private static final String ENCODED_STRING_CLEAN = "WIQOOXHMVEGKGWS";
|
||||
private static final String KEYWORD = "keywordThatIsTotallyRandom";
|
||||
private static final ArrayList<Integer> OFFSET = new ArrayList<>(Arrays.asList(10, 4, 24, 22, 14, 17, 3, 19, 7, 0, 19, 8, 18, 19, 14, 19, 0, 11, 11, 24, 17, 0, 13, 3, 14, 12));
|
||||
|
||||
|
||||
@Test
|
||||
@@ -95,13 +91,13 @@ public class OneTimePadTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
assertEquals(OFFSET, cipher.offset);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
}
|
||||
|
||||
@@ -111,13 +107,13 @@ public class OneTimePadTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
assertEquals(OFFSET, cipher.offset);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
}
|
||||
|
||||
@@ -128,7 +124,7 @@ public class OneTimePadTest{
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.encode("keyword", decodedString);
|
||||
cipher.encode("keyword", DECODED_STRING);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
@@ -144,13 +140,13 @@ public class OneTimePadTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
assertEquals(OFFSET, cipher.offset);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
}
|
||||
|
||||
@@ -160,20 +156,20 @@ public class OneTimePadTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
assertEquals(OFFSET, cipher.offset);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode_short(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.decode("keyword", encodedString);
|
||||
cipher.decode("keyword", ENCODED_STRING);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
@@ -187,47 +183,47 @@ public class OneTimePadTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new OneTimePad(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new OneTimePad(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new OneTimePad(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new OneTimePad(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/PortaTest.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,12 +23,12 @@ public class PortaTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private static final String encodedStringClean = "RTGHUOSBMQCWGRW";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String keywordDirty = "Ke yw*ord";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Rtghuos bm^qcwgrw";
|
||||
private static final String ENCODED_STRING_CLEAN = "RTGHUOSBMQCWGRW";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String KEYWORD_DIRTY = "Ke yw*ord";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -85,24 +81,24 @@ public class PortaTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_dirty(){
|
||||
cipher.setKeyword(keywordDirty);
|
||||
cipher.setKeyword(KEYWORD_DIRTY);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keywordDirty);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD_DIRTY);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,11 +144,11 @@ public class PortaTest{
|
||||
public void testSetKeyword_symbols(){
|
||||
cipher.setKeyword("key*word^");
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", "key*word^");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,14 +157,14 @@ public class PortaTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,14 +173,14 @@ public class PortaTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,14 +189,14 @@ public class PortaTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,14 +205,14 @@ public class PortaTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -639,18 +635,18 @@ public class PortaTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = KEYWORD.toUpperCase();
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(17)).debug(eq("Encoded letter {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -658,36 +654,36 @@ public class PortaTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = KEYWORD.toUpperCase();
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(17)).debug(eq("Encoded letter {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRest(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -700,47 +696,47 @@ public class PortaTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Porta(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Porta(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Porta(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Porta(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/SubstitutionTest.java
|
||||
//Mattrixwv
|
||||
// Created: 02-22-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -27,18 +23,18 @@ public class SubstitutionTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String decodedStringAlNum = "Message to^encode 123";
|
||||
private static final String decodedStringAlNumClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Oguucig vq^gpeqfg";
|
||||
private static final String encodedStringClean = "OGUUCIGVQGPEQFG";
|
||||
private static final String encodedStringAlNum = "Oguucig vq^gpeqfg 876";
|
||||
private static final String encodedStringAlNumClean = "OGUUCIGVQGPEQFG";
|
||||
private static final String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final String keywordClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB";
|
||||
private static final String keywordAlNum = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
private static final String keywordAlNumClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB9876543210";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String DECODED_STRING_AL_NUM = "Message to^encode 123";
|
||||
private static final String DECODED_STRING_AL_NUM_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Oguucig vq^gpeqfg";
|
||||
private static final String ENCODED_STRING_CLEAN = "OGUUCIGVQGPEQFG";
|
||||
private static final String ENCODED_STRING_AL_NUM = "Oguucig vq^gpeqfg 876";
|
||||
private static final String ENCODED_STRING_AL_NUM_CLEAN = "OGUUCIGVQGPEQFG";
|
||||
private static final String KEYWORD = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final String KEYWORD_CLEAN = "CDEFGHIJKLMNOPQRSTUVWXYZAB";
|
||||
private static final String KEYWORD_AL_NUM = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
private static final String KEYWORD_AL_NUM_CLEAN = "CDEFGHIJKLMNOPQRSTUVWXYZAB9876543210";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -91,28 +87,28 @@ public class SubstitutionTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring there are no duplicate mappings");
|
||||
verify(logger, times(1)).debug("Ensuring there are only letters in the key");
|
||||
verify(logger, never()).debug("Ensuring there are only alpha-numeric characters in the key");
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keywordClean);
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_alNum(){
|
||||
cipher.setKeyword(keywordAlNum);
|
||||
cipher.setKeyword(KEYWORD_AL_NUM);
|
||||
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", keywordAlNum);
|
||||
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", KEYWORD_AL_NUM);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring there are no duplicate mappings");
|
||||
verify(logger, never()).debug("Ensuring there are only letters in the key");
|
||||
verify(logger, times(1)).debug("Ensuring there are only alpha-numeric characters in the key");
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keywordAlNumClean);
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", KEYWORD_AL_NUM_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,14 +192,14 @@ public class SubstitutionTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,14 +208,14 @@ public class SubstitutionTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,14 +224,14 @@ public class SubstitutionTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,14 +240,14 @@ public class SubstitutionTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -295,19 +291,19 @@ public class SubstitutionTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = decodedStringAlNum;
|
||||
cipher.keyword = keywordAlNumClean;
|
||||
cipher.inputString = DECODED_STRING_AL_NUM;
|
||||
cipher.keyword = KEYWORD_AL_NUM_CLEAN;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedStringAlNum, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_AL_NUM, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(3)).debug("Encoding digit");
|
||||
verify(logger, times(3)).debug("Passing symbol through");
|
||||
verify(logger, times(1)).debug("Encoded message '{}'", encodedStringAlNum);
|
||||
verify(logger, times(1)).debug("Encoded message '{}'", ENCODED_STRING_AL_NUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,37 +311,37 @@ public class SubstitutionTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = encodedStringAlNum;
|
||||
cipher.keyword = keywordAlNumClean;
|
||||
cipher.inputString = ENCODED_STRING_AL_NUM;
|
||||
cipher.keyword = KEYWORD_AL_NUM_CLEAN;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedStringAlNum, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_AL_NUM, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(3)).debug("Encoding digit");
|
||||
verify(logger, times(3)).debug("Passing symbol through");
|
||||
verify(logger, times(1)).debug("Decoded message '{}'", decodedStringAlNum);
|
||||
verify(logger, times(1)).debug("Decoded message '{}'", DECODED_STRING_AL_NUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -359,119 +355,119 @@ public class SubstitutionTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Substitution(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_alNum(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.encode(keywordAlNum, decodedStringAlNum);
|
||||
String output = cipher.encode(KEYWORD_AL_NUM, DECODED_STRING_AL_NUM);
|
||||
|
||||
assertEquals(decodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(encodedStringAlNum, cipher.outputString);
|
||||
assertEquals(encodedStringAlNum, output);
|
||||
assertEquals(DECODED_STRING_AL_NUM, cipher.inputString);
|
||||
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_AL_NUM, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_AL_NUM, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_alNumClean(){
|
||||
cipher = new Substitution(false, false, false);
|
||||
|
||||
String output = cipher.encode(keywordAlNum, decodedStringAlNum);
|
||||
String output = cipher.encode(KEYWORD_AL_NUM, DECODED_STRING_AL_NUM);
|
||||
|
||||
assertEquals(decodedStringAlNumClean, cipher.inputString);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(encodedStringAlNumClean, cipher.outputString);
|
||||
assertEquals(encodedStringAlNumClean, output);
|
||||
assertEquals(DECODED_STRING_AL_NUM_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_AL_NUM_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_AL_NUM_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrecticalEncoding_noAlNumKey(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedStringAlNum);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING_AL_NUM);
|
||||
|
||||
assertEquals(decodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString + " 123", cipher.outputString);
|
||||
assertEquals(encodedString + " 123", output);
|
||||
assertEquals(DECODED_STRING_AL_NUM, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING + " 123", cipher.outputString);
|
||||
assertEquals(ENCODED_STRING + " 123", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Substitution(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_alNum(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.decode(keywordAlNum, encodedStringAlNum);
|
||||
String output = cipher.decode(KEYWORD_AL_NUM, ENCODED_STRING_AL_NUM);
|
||||
|
||||
assertEquals(encodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(decodedStringAlNum, cipher.outputString);
|
||||
assertEquals(decodedStringAlNum, output);
|
||||
assertEquals(ENCODED_STRING_AL_NUM, cipher.inputString);
|
||||
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_AL_NUM, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_AL_NUM, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_alNumClean(){
|
||||
cipher = new Substitution(false, false, false);
|
||||
|
||||
String output = cipher.decode(keywordAlNum, encodedStringAlNum);
|
||||
String output = cipher.decode(KEYWORD_AL_NUM, ENCODED_STRING_AL_NUM);
|
||||
|
||||
assertEquals(encodedStringAlNumClean, cipher.inputString);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(decodedStringAlNumClean, cipher.outputString);
|
||||
assertEquals(decodedStringAlNumClean, output);
|
||||
assertEquals(ENCODED_STRING_AL_NUM_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_AL_NUM_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_AL_NUM_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_noAlNumKey(){
|
||||
cipher = new Substitution(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString + " 123");
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING + " 123");
|
||||
|
||||
assertEquals(encodedString + " 123", cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString + " 123", cipher.outputString);
|
||||
assertEquals(decodedString + " 123", output);
|
||||
assertEquals(ENCODED_STRING + " 123", cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING + " 123", cipher.outputString);
|
||||
assertEquals(DECODED_STRING + " 123", output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/monosubstitution/VigenereTest.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,6 +8,7 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -30,13 +27,19 @@ public class VigenereTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String inputString = "MeSsage to^encode";
|
||||
private static final String inputStringClean = "MESSAGETOENCODE";
|
||||
private static final String outputString = "WiQooxh ds^cjqfgo";
|
||||
private static final String outputStringClean = "WIQOOXHDSCJQFGO";
|
||||
private static final String keyword = "ke yw*ord";
|
||||
private static final String keywordClean = "KEYWORD";
|
||||
private ArrayList<Integer> offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3));
|
||||
private static final String INPUT_STRING = "MeSsage to^encode";
|
||||
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String OUTPUT_STRING = "WiQooxh ds^cjqfgo";
|
||||
private static final String OUTPUT_STRING_CLEAN = "WIQOOXHDSCJQFGO";
|
||||
private static final String KEYWORD = "ke yw*ord";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||
private ArrayList<Integer> offset;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@@ -93,11 +96,11 @@ public class VigenereTest{
|
||||
|
||||
@Test
|
||||
public void testSetOffset(){
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.setOffset();
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
verify(logger, times(1)).debug("Setting offset array from keyword");
|
||||
verify(logger, times(1)).debug("Offset {}", offset);
|
||||
@@ -108,17 +111,17 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,17 +129,17 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,17 +147,17 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,17 +165,17 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,7 +183,7 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -200,7 +203,7 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -217,14 +220,14 @@ public class VigenereTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
||||
verify(logger, times(1)).debug("Clean keyword '{}'", keywordClean);
|
||||
verify(logger, times(1)).debug("Clean keyword '{}'", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,13 +263,13 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = inputString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Encoding uppercase");
|
||||
@@ -274,7 +277,7 @@ public class VigenereTest{
|
||||
verify(logger, times(13)).debug("Encoding lowercase");
|
||||
verify(logger, times(5)).debug("Wrapping around to a");
|
||||
verify(logger, times(17)).debug(eq("Encoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoded message '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Encoded message '{}'", OUTPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,13 +285,13 @@ public class VigenereTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = outputString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = OUTPUT_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(inputString, cipher.outputString);
|
||||
assertEquals(INPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(2)).debug("Decoding uppercase");
|
||||
@@ -296,27 +299,27 @@ public class VigenereTest{
|
||||
verify(logger, times(13)).debug("Decoding lowercase");
|
||||
verify(logger, times(5)).debug("Wrapping around to z");
|
||||
verify(logger, times(17)).debug(eq("Decoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Decoded message '{}'", inputString);
|
||||
verify(logger, times(1)).debug("Decoded message '{}'", INPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.offset = offset;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
assertEquals(offset, cipher.getOffsets());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.reset();
|
||||
@@ -332,51 +335,51 @@ public class VigenereTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Vigenere(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(INPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Vigenere(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(outputStringClean, cipher.outputString);
|
||||
assertEquals(outputStringClean, output);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Vigenere(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(inputString, cipher.outputString);
|
||||
assertEquals(inputString, output);
|
||||
assertEquals(INPUT_STRING, cipher.outputString);
|
||||
assertEquals(INPUT_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Vigenere(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/BifidTest.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -27,12 +23,12 @@ public class BifidTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Test
|
||||
private static final String inputString = "Message to^encode";
|
||||
private static final String inputStringClean = "MESSAGETOENCODE";
|
||||
private static final String outputString = "Mqaokne kc^vdodzd";
|
||||
private static final String outputStringClean = "MQAOKNEKCVDODZD";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
private static final String INPUT_STRING = "Message to^encode";
|
||||
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String OUTPUT_STRING = "Mqaokne kc^vdodzd";
|
||||
private static final String OUTPUT_STRING_CLEAN = "MQAOKNEKCVDODZD";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -97,10 +93,10 @@ public class BifidTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Setting keyword '{}'", keyword);
|
||||
assertEquals(KEYWORD, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Setting keyword '{}'", KEYWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,14 +114,14 @@ public class BifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,14 +130,14 @@ public class BifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,14 +146,14 @@ public class BifidTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,14 +162,14 @@ public class BifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
cipher.setInputString(INPUT_STRING);
|
||||
|
||||
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
||||
assertEquals(INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,29 +210,29 @@ public class BifidTest{
|
||||
|
||||
@Test
|
||||
public void testFormatOutput(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
|
||||
cipher.formatOutput(outputStringClean);
|
||||
cipher.formatOutput(OUTPUT_STRING_CLEAN);
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output");
|
||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Altering uppercase");
|
||||
verify(logger, times(14)).debug("Altering lowercase");
|
||||
verify(logger, times(2)).debug("Adding symbol");
|
||||
verify(logger, times(1)).debug("Formatted output string '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Formatted output string '{}'", OUTPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(INPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Encoding Polybius");
|
||||
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
||||
@@ -246,14 +242,14 @@ public class BifidTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = OUTPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputString, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(INPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Encoding Polybius Square");
|
||||
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
||||
@@ -263,20 +259,20 @@ public class BifidTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -290,11 +286,11 @@ public class BifidTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Bifid(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(INPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
assertEquals(output, cipher.outputString);
|
||||
}
|
||||
|
||||
@@ -302,35 +298,35 @@ public class BifidTest{
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Bifid(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputStringClean, cipher.outputString);
|
||||
assertEquals(outputStringClean, output);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Bifid(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputString, cipher.outputString);
|
||||
assertEquals(inputString, output);
|
||||
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(INPUT_STRING, cipher.outputString);
|
||||
assertEquals(INPUT_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new Bifid(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
assertEquals(OUTPUT_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//Mattrixwv/src/test/java/com/mattrixwv/cipherstream/polysubstitution/ColumnarTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-16-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -31,16 +27,16 @@ public class ColumnarTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to*encode";
|
||||
private static final String decodedStringPadded = "Message to*encodexxxxxx";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODEXXXXXX";
|
||||
private static final String encodedString = "Edeomte ac*gosnse";
|
||||
private static final String DECODED_STRING = "Message to*encode";
|
||||
private static final String DECODED_STRING_PADDED = "Message to*encodexxxxxx";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODEXXXXXX";
|
||||
private static final String ENCODED_STRING = "Edeomte ac*gosnse";
|
||||
//TODO: This is a bug that needs fixed
|
||||
private static final String encodedStringPadingAdded = "Edxeoxmte ac*xgoxsnxsex"; //When padding is added to outputString for decoding
|
||||
private static final String encodedStringPadded = "Edxeoxm te*acxgoxsnxsex"; //When padding is left in outputString
|
||||
private static final String encodedStringClean = "EDXEOXMTEACXGOXSNXSEX";
|
||||
private static final String keyword = "ke yw*ord";
|
||||
private static final String keywordClean = "KEYWORD";
|
||||
private static final String ENCODED_STRING_PADDING_ADDED = "Edxeoxmte ac*xgoxsnxsex"; //When padding is added to outputString for decoding
|
||||
private static final String ENCODED_STRING_PADDED = "Edxeoxm te*acxgoxsnxsex"; //When padding is left in outputString
|
||||
private static final String ENCODED_STRING_CLEAN = "EDXEOXMTEACXGOXSNXSEX";
|
||||
private static final String KEYWORD = "ke yw*ord";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||
private static final ArrayList<ArrayList<Character>> encodeGrid = new ArrayList<>(
|
||||
List.of(
|
||||
new ArrayList<>(
|
||||
@@ -237,17 +233,17 @@ public class ColumnarTest{
|
||||
|
||||
@Test
|
||||
public void testGetCleanInputString(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
String output = cipher.getCleanInputString();
|
||||
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("[^A-Z]", ""), output);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^A-Z]", ""), output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGridEncode(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGridEncode();
|
||||
|
||||
@@ -257,8 +253,8 @@ public class ColumnarTest{
|
||||
|
||||
@Test
|
||||
public void testCreateGridDecode(){
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGridDecode();
|
||||
|
||||
@@ -271,19 +267,19 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -291,19 +287,19 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'X';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.toUpperCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,19 +307,19 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -331,19 +327,19 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -351,7 +347,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -373,7 +369,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -395,7 +391,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -417,18 +413,18 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringPadingAdded, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_PADDING_ADDED, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedStringPadingAdded);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING_PADDING_ADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -436,7 +432,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode("Message to encod");
|
||||
@@ -455,18 +451,18 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'X';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringPadingAdded.toUpperCase(), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_PADDING_ADDED.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedStringPadingAdded.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING_PADDING_ADDED.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -474,18 +470,18 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringPadingAdded.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_PADDING_ADDED.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedStringPadingAdded.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING_PADDING_ADDED.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -493,18 +489,18 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringPadingAdded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING_PADDING_ADDED.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedStringPadingAdded.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING_PADDING_ADDED.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -512,7 +508,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -533,7 +529,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -554,7 +550,7 @@ public class ColumnarTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -573,53 +569,53 @@ public class ColumnarTest{
|
||||
@Test
|
||||
public void testCreateOutputStringFromColumns(){
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = decodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.createOutputStringFromColumns();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Creating output string for encoding");
|
||||
verify(logger, times(1)).debug("Getting added characters");
|
||||
verify(logger, times(1)).debug("Turning grid into string");
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(1)).debug("Output string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Output string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOutputStringFromColumns_padding(){
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = decodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.createOutputStringFromColumns();
|
||||
|
||||
assertEquals(encodedStringPadded, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Creating output string for encoding");
|
||||
verify(logger, times(1)).debug("Getting added characters");
|
||||
verify(logger, times(1)).debug("Turning grid into string");
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(1)).debug("Output string '{}'", encodedStringPadded);
|
||||
verify(logger, times(1)).debug("Output string '{}'", ENCODED_STRING_PADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOutputStringFromRows(){
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = encodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = ENCODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = encodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.createOutputStringFromRows();
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Creating output string for decoding");
|
||||
verify(logger, times(1)).debug("Transforming grid to a string");
|
||||
verify(logger, times(1)).debug("Removing padding");
|
||||
@@ -628,21 +624,21 @@ public class ColumnarTest{
|
||||
verify(logger, times(1)).debug("Adding upper case");
|
||||
verify(logger, times(20)).debug("Adding lower case");
|
||||
verify(logger, times(2)).debug("Adding symbol");
|
||||
verify(logger, times(1)).debug("Decoded output string '{}'", decodedStringPadded);
|
||||
verify(logger, times(1)).debug("Decoded output string '{}'", DECODED_STRING_PADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOuputStringFromRows_removePadding(){
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = encodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.createOutputStringFromRows();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Creating output string for decoding");
|
||||
verify(logger, times(1)).debug("Transforming grid to a string");
|
||||
verify(logger, times(1)).debug("Removing padding");
|
||||
@@ -651,16 +647,16 @@ public class ColumnarTest{
|
||||
verify(logger, times(1)).debug("Adding upper case");
|
||||
verify(logger, times(14)).debug("Adding lower case");
|
||||
verify(logger, times(2)).debug("Adding symbol");
|
||||
verify(logger, times(1)).debug("Decoded output string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Decoded output string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword {}", KEYWORD);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -722,7 +718,7 @@ public class ColumnarTest{
|
||||
public void testGetKeywordAlphaLocations(){
|
||||
ArrayList<Integer> alphaLocations = new ArrayList<>(List.of(6, 1, 0, 4, 5, 3, 2));
|
||||
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
ArrayList<Integer> returnedLocations = cipher.getKeywordAlphaLocations();
|
||||
|
||||
@@ -735,7 +731,7 @@ public class ColumnarTest{
|
||||
public void testGetKeywordOriginalLocations(){
|
||||
ArrayList<Integer> orderedLocations = new ArrayList<>(List.of(2, 1, 6, 5, 3, 4, 0));
|
||||
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
ArrayList<Integer> returnedLocations = cipher.getKeywordOriginalLocations();
|
||||
|
||||
@@ -774,14 +770,14 @@ public class ColumnarTest{
|
||||
public void testEncode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Creating grid for encoding");
|
||||
verify(logger, times(2)).debug("Creating an array of keyword letter locations");
|
||||
@@ -793,14 +789,14 @@ public class ColumnarTest{
|
||||
public void testEncode_padding(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedStringPadded, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Creating grid for encoding");
|
||||
verify(logger, times(1)).debug("Creating an array of keyword letter locations");
|
||||
@@ -812,14 +808,14 @@ public class ColumnarTest{
|
||||
public void testDecode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Creating grid for decoding");
|
||||
verify(logger, times(2)).debug("Creating array of original keyword locations");
|
||||
@@ -831,14 +827,14 @@ public class ColumnarTest{
|
||||
public void testDecode_padding(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = encodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = ENCODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Creating grid for decoding");
|
||||
verify(logger, times(1)).debug("Creating array of original keyword locations");
|
||||
@@ -848,20 +844,20 @@ public class ColumnarTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.grid = encodeGrid;
|
||||
cipher.charsAdded = 5;
|
||||
|
||||
@@ -878,71 +874,71 @@ public class ColumnarTest{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new Columnar(true, true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_noPadding(){
|
||||
cipher = new Columnar(true, true, true, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringPadded, cipher.outputString);
|
||||
assertEquals(encodedStringPadded, output);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_PADDED, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_PADDED, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new Columnar(false, false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode(){
|
||||
cipher = new Columnar(true, true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringPadingAdded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING_PADDING_ADDED, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_noPadding(){
|
||||
cipher = new Columnar(true, true, true, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedStringPadded);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING_PADDED);
|
||||
|
||||
assertEquals(encodedStringPadded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
assertEquals(ENCODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new Columnar(false, false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/HillTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-31-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -31,13 +27,13 @@ public class HillTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String decodedString = "Message to^encoded";
|
||||
private static final String decodedStringPadded = "Message to^encodedxx";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODEDXX";
|
||||
private static final String encodedString = "Mgkeqge ul^ikhisplrd";
|
||||
private static final String encodedStringClean = "MGKEQGEULIKHISPLRD";
|
||||
private static final int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private static final ModMatrix key = new ModMatrix(keyArray, 26);
|
||||
private static final String DECODED_STRING = "Message to^encoded";
|
||||
private static final String DECODED_STRING_PADDED = "Message to^encodedxx";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODEDXX";
|
||||
private static final String ENCODED_STRING = "Mgkeqge ul^ikhisplrd";
|
||||
private static final String ENCODED_STRING_CLEAN = "MGKEQGEULIKHISPLRD";
|
||||
private static final int[][] KEY_ARRAY = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private static final ModMatrix KEY = new ModMatrix(KEY_ARRAY, 26);
|
||||
|
||||
|
||||
@Test
|
||||
@@ -133,19 +129,19 @@ public class HillTest{
|
||||
|
||||
@Test
|
||||
public void testSetKey(){
|
||||
cipher.setKey(key);
|
||||
cipher.setKey(KEY);
|
||||
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(KEY, cipher.key);
|
||||
verify(logger, times(1)).debug("Setting key");
|
||||
verify(logger, times(1)).debug("Testing mod");
|
||||
verify(logger, times(1)).debug("Testing square");
|
||||
verify(logger, times(1)).debug("Testing invertable");
|
||||
verify(logger, times(1)).debug("key\n{}", key);
|
||||
verify(logger, times(1)).debug("key\n{}", KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_invalidMod(){
|
||||
ModMatrix matrix = new ModMatrix(keyArray, 30);
|
||||
ModMatrix matrix = new ModMatrix(KEY_ARRAY, 30);
|
||||
|
||||
assertThrows(InvalidKeyException.class, () -> {
|
||||
cipher.setKey(matrix);
|
||||
@@ -196,20 +192,20 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,20 +213,20 @@ public class HillTest{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'X';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.toUpperCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,20 +234,20 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,20 +255,20 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -280,7 +276,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -303,7 +299,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -326,7 +322,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -349,17 +345,17 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
}
|
||||
|
||||
@@ -368,17 +364,17 @@ public class HillTest{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.toUpperCase());
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
}
|
||||
|
||||
@@ -387,17 +383,17 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
}
|
||||
|
||||
@@ -406,17 +402,17 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(ENCODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
}
|
||||
|
||||
@@ -425,19 +421,19 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(encodedString + "a");
|
||||
cipher.setInputStringDecode(ENCODED_STRING + "a");
|
||||
});
|
||||
|
||||
assertEquals(encodedString + "a", cipher.inputString);
|
||||
assertEquals(ENCODED_STRING + "a", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Original input string '{}'", ENCODED_STRING + "a");
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING + "a");
|
||||
verify(logger, times(1)).debug("Checking length");
|
||||
}
|
||||
|
||||
@@ -446,7 +442,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode("");
|
||||
@@ -467,7 +463,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode("*^&");
|
||||
@@ -488,7 +484,7 @@ public class HillTest{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.key = key;
|
||||
cipher.key = KEY;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(null);
|
||||
@@ -506,13 +502,13 @@ public class HillTest{
|
||||
|
||||
@Test
|
||||
public void testGetCleanInputString(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
|
||||
String output = cipher.getCleanInputString();
|
||||
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
verify(logger, times(1)).debug("Cleaning inputString");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedStringClean);
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", DECODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -555,18 +551,18 @@ public class HillTest{
|
||||
|
||||
@Test
|
||||
public void testPolishOutputString(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.outputString = encodedStringClean;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||
|
||||
String output = cipher.polishOutputString();
|
||||
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
verify(logger, times(1)).debug("Polishing output string");
|
||||
verify(logger, times(20)).debug(eq("Current char {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Uppercase");
|
||||
verify(logger, times(17)).debug("Lowercase");
|
||||
verify(logger, times(2)).debug("Symbol");
|
||||
verify(logger, times(1)).debug("Polished string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Polished string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -579,8 +575,8 @@ public class HillTest{
|
||||
expectedVectors.add(new ModMatrix(new int[][]{{14}, { 3}, { 4}}, 26));
|
||||
expectedVectors.add(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26));
|
||||
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.key = key;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.key = KEY;
|
||||
|
||||
ArrayList<ModMatrix> returnedVectors = cipher.getInputVectors();
|
||||
|
||||
@@ -593,29 +589,29 @@ public class HillTest{
|
||||
@Test
|
||||
public void testGetOutputFromVectors(){
|
||||
ArrayList<ModMatrix> outputVectors = new ArrayList<>();
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{12}, { 4}, {18}}, 26)));
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{18}, { 0}, { 6}}, 26)));
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{ 4}, {19}, {14}}, 26)));
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{ 4}, {13}, { 2}}, 26)));
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{14}, { 3}, { 4}}, 26)));
|
||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{12}, { 4}, {18}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{18}, { 0}, { 6}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{ 4}, {19}, {14}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{ 4}, {13}, { 2}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{14}, { 3}, { 4}}, 26)));
|
||||
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26)));
|
||||
|
||||
String returnedString = cipher.getOutputFromVectors(outputVectors);
|
||||
|
||||
assertEquals(encodedStringClean, returnedString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, returnedString);
|
||||
verify(logger, times(1)).debug("Turning vectors into a string");
|
||||
verify(logger, times(6)).debug(eq("Current vector {}"), any(ModMatrix.class));
|
||||
verify(logger, times(1)).debug("Converted string '{}'", encodedStringClean);
|
||||
verify(logger, times(1)).debug("Converted string '{}'", ENCODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.key = key;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Multiplying vectors");
|
||||
verify(logger, times(6)).debug(eq("Current input vector {}"), any(ModMatrix.class));
|
||||
@@ -624,35 +620,35 @@ public class HillTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.key = key;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Getting inverse of key");
|
||||
verify(logger, times(1)).debug("Inverse of key {}", key.inverse());
|
||||
verify(logger, times(1)).debug("Inverse of key {}", KEY.inverse());
|
||||
verify(logger, times(6)).debug(eq("Current input vector {}"), any(ModMatrix.class));
|
||||
verify(logger, times(6)).debug(eq("Multiplied vector {}"), any(ModMatrix.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.key = key;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.key = KEY;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(key, cipher.getKey());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEY, cipher.getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.key = key;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.key = KEY;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -666,46 +662,46 @@ public class HillTest{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new Hill(true, true, true);
|
||||
|
||||
String output = cipher.encode(key, decodedString);
|
||||
String output = cipher.encode(KEY, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new Hill(false, false, false);
|
||||
|
||||
String output = cipher.encode(key, decodedString);
|
||||
String output = cipher.encode(KEY, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_array(){
|
||||
cipher = new Hill(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyArray, decodedString);
|
||||
String output = cipher.encode(KEY_ARRAY, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_padding(){
|
||||
cipher = new Hill(true, true, true, 'j');
|
||||
|
||||
String output = cipher.encode(key, decodedString);
|
||||
String output = cipher.encode(KEY, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString + "jj", cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(DECODED_STRING + "jj", cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals("Mgkeqge ul^ikhispfzn", cipher.outputString);
|
||||
assertEquals("Mgkeqge ul^ikhispfzn", output);
|
||||
}
|
||||
@@ -714,47 +710,47 @@ public class HillTest{
|
||||
public void testPracticalDecode(){
|
||||
cipher = new Hill(true, true, true);
|
||||
|
||||
String output = cipher.decode(key, encodedString);
|
||||
String output = cipher.decode(KEY, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new Hill(false, false, false);
|
||||
|
||||
String output = cipher.decode(key, encodedString);
|
||||
String output = cipher.decode(KEY, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_array(){
|
||||
cipher = new Hill(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyArray, encodedString);
|
||||
String output = cipher.decode(KEY_ARRAY, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_padding(){
|
||||
cipher = new Hill(true, true, true, 'j');
|
||||
|
||||
String output = cipher.decode(key, "Mgkeqge ul^ikhispfzn");
|
||||
String output = cipher.decode(KEY, "Mgkeqge ul^ikhispfzn");
|
||||
|
||||
assertEquals("Mgkeqge ul^ikhispfzn", cipher.inputString);
|
||||
assertEquals(key, cipher.key);
|
||||
assertEquals(decodedString + "jj", cipher.outputString);
|
||||
assertEquals(decodedString + "jj", output);
|
||||
assertEquals(KEY, cipher.key);
|
||||
assertEquals(DECODED_STRING + "jj", cipher.outputString);
|
||||
assertEquals(DECODED_STRING + "jj", output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/LargePolybiusSquareTest.java
|
||||
//Mattrixwv
|
||||
// Created: 04-21-23
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -27,14 +23,14 @@ public class LargePolybiusSquareTest{
|
||||
@Mock(name = "com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "35124343222612 4415^123624152112";
|
||||
private static final String encodedStringClean = "31 15 41 41 11 21 15 42 33 15 32 13 33 14 15";
|
||||
private static final String keyword = "ke yw*ord";
|
||||
private static final String keywordClean = "KEYWORDABCFGHIJLMNPQSTUVXZ0123456789";
|
||||
private static final String keywordBlank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final char[][] grid = {
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "35124343222612 4415^123624152112";
|
||||
private static final String ENCODED_STRING_CLEAN = "31 15 41 41 11 21 15 42 33 15 32 13 33 14 15";
|
||||
private static final String KEYWORD = "ke yw*ord";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHIJLMNPQSTUVXZ0123456789";
|
||||
private static final String KEYWORD_BLANK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final char[][] GRID = {
|
||||
{'K', 'E', 'Y', 'W', 'O', 'R'},
|
||||
{'D', 'A', 'B', 'C', 'F', 'G'},
|
||||
{'H', 'I', 'J', 'L', 'M', 'N'},
|
||||
@@ -42,7 +38,7 @@ public class LargePolybiusSquareTest{
|
||||
{'X', 'Z', '0', '1', '2', '3'},
|
||||
{'4', '5', '6', '7', '8', '9'}
|
||||
};
|
||||
private static final char[][] gridClean = {
|
||||
private static final char[][] GRID_CLEAN = {
|
||||
{'A', 'B', 'C', 'D', 'E', 'F'},
|
||||
{'G', 'H', 'I', 'J', 'K', 'L'},
|
||||
{'M', 'N', 'O', 'P', 'Q', 'R'},
|
||||
@@ -90,11 +86,11 @@ public class LargePolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testCreateGrid(){
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGrid();
|
||||
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Creating grid");
|
||||
}
|
||||
|
||||
@@ -103,13 +99,13 @@ public class LargePolybiusSquareTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,13 +113,13 @@ public class LargePolybiusSquareTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase().replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,13 +127,13 @@ public class LargePolybiusSquareTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,10 +141,10 @@ public class LargePolybiusSquareTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals("M E S S A G E T O E N C O D E", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "M E S S A G E T O E N C O D E");
|
||||
@@ -204,34 +200,34 @@ public class LargePolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputStringEncoding(){
|
||||
cipher.inputString = decodedString.toUpperCase();
|
||||
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||
|
||||
String preparedInputString = cipher.getPreparedInputStringEncode();
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""), preparedInputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", ""), preparedInputString);
|
||||
verify(logger, times(1)).debug("Preparing input string for encoding");
|
||||
verify(logger, times(1)).debug("Prepared input string '{}'", preparedInputString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keywordClean);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD);
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_blank(){
|
||||
cipher.setKeyword("");
|
||||
|
||||
assertEquals(keywordBlank, cipher.keyword);
|
||||
assertArrayEquals(gridClean, cipher.grid);
|
||||
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||
assertArrayEquals(GRID_CLEAN, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", "");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keywordBlank);
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD_BLANK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -250,43 +246,43 @@ public class LargePolybiusSquareTest{
|
||||
public void testAddCharactersToCleanStringEncode(){
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = decodedString.toUpperCase();
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||
|
||||
cipher.addCharactersToCleanStringEncode(encodedString.replaceAll("\\s", "").replaceAll("[^0-9]", ""));
|
||||
cipher.addCharactersToCleanStringEncode(ENCODED_STRING.replaceAll("\\s", "").replaceAll("[^0-9]", ""));
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Appending character");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Saving output string {}", encodedString);
|
||||
verify(logger, times(1)).debug("Saving output string {}", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanStringDecode(){
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.addCharactersToCleanStringDecode(decodedStringClean);
|
||||
cipher.addCharactersToCleanStringDecode(DECODED_STRING_CLEAN);
|
||||
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Appending character");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Saving output string {}", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Saving output string {}", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -302,47 +298,47 @@ public class LargePolybiusSquareTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new LargePolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new LargePolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.encode(decodedString);
|
||||
String output = cipher.encode(DECODED_STRING);
|
||||
|
||||
assertEquals("M E S S A G E T O E N C O D E", cipher.inputString);
|
||||
assertEquals(keywordBlank, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new LargePolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(decodedString.toUpperCase(), output);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean(){
|
||||
cipher = new LargePolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.decode(encodedStringClean);
|
||||
String output = cipher.decode(ENCODED_STRING_CLEAN);
|
||||
|
||||
assertEquals(encodedStringClean.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(keywordBlank, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_CLEAN.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/MoresTest.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -26,9 +22,9 @@ public class MorseTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String inputString = "Message to^encode123";
|
||||
private static final String inputStringClean = "MESSAGETOENCODE123";
|
||||
private static final String outputString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
private static final String INPUT_STRING = "Message to^encode123";
|
||||
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE123";
|
||||
private static final String OUTPUT_STRING = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -41,13 +37,13 @@ public class MorseTest{
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(INPUT_STRING);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", INPUT_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace and symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringClean);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", INPUT_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,10 +89,10 @@ public class MorseTest{
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode(){
|
||||
cipher.setInputStringDecode(outputString);
|
||||
cipher.setInputStringDecode(OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", OUTPUT_STRING);
|
||||
verify(logger, times(1)).debug("Checking for invalid characters");
|
||||
verify(logger, times(1)).debug("Saving");
|
||||
}
|
||||
@@ -141,16 +137,16 @@ public class MorseTest{
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = inputStringClean;
|
||||
cipher.inputString = INPUT_STRING_CLEAN;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Appending letter");
|
||||
verify(logger, times(3)).debug("Appending number");
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", OUTPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,20 +162,20 @@ public class MorseTest{
|
||||
verify(logger, times(1)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, never()).debug("Appending letter");
|
||||
verify(logger, never()).debug("Appending number");
|
||||
verify(logger, never()).debug("Saving encoded string '{}'", outputString);
|
||||
verify(logger, never()).debug("Saving encoded string '{}'", OUTPUT_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.inputString = OUTPUT_STRING;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(18)).debug(eq("Working letter {}"), anyString());
|
||||
verify(logger, times(18)).debug(eq("Decoded letter {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", inputStringClean);
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", INPUT_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,17 +195,17 @@ public class MorseTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = INPUT_STRING;
|
||||
cipher.outputString = OUTPUT_STRING;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -220,19 +216,19 @@ public class MorseTest{
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode(){
|
||||
String output = cipher.encode(inputString);
|
||||
String output = cipher.encode(INPUT_STRING);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||
assertEquals(OUTPUT_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode(){
|
||||
String output = cipher.decode(outputString);
|
||||
String output = cipher.decode(OUTPUT_STRING);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(INPUT_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/PlayfairTest.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -29,14 +25,14 @@ public class PlayfairTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private static final String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private static final String decodedStringClean = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
private static final String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String encodedStringClean = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
private static final String keyword = "Play-fair@Exam ple";
|
||||
private static final String keywordClean = "PLAYFIREXMBCDGHKNOQSTUVWZ";
|
||||
private static final char[][] grid = new char[][]{
|
||||
private static final String DECODED_STRING = "Hide the gold in - the@tree+stump";
|
||||
private static final String DECODED_STRING_PADDED = "Hide the gold in - the@trexe+stump";
|
||||
private static final String DECODED_STRING_CLEAN = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
private static final String ENCODED_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String ENCODED_STRING_CLEAN = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
private static final String KEYWORD = "Play-fair@Exam ple";
|
||||
private static final String KEYWORD_CLEAN = "PLAYFIREXMBCDGHKNOQSTUVWZ";
|
||||
private static final char[][] GRID = new char[][]{
|
||||
{'P', 'L', 'A', 'Y', 'F'},
|
||||
{'I', 'R', 'E', 'X', 'M'},
|
||||
{'B', 'C', 'D', 'G', 'H'},
|
||||
@@ -394,11 +390,11 @@ public class PlayfairTest{
|
||||
@Test
|
||||
public void testCreateGrid(){
|
||||
String expectedGridString = "[P L A Y F]\n[I R E X M]\n[B C D G H]\n[K N O Q S]\n[T U V W Z]";
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGrid();
|
||||
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
||||
verify(logger, times(25)).debug(eq("Letter {} going to position [{}] [{}]"), anyChar(), anyInt(), anyInt());
|
||||
verify(logger, times(1)).debug("Grid\n{}", expectedGridString);
|
||||
@@ -411,11 +407,11 @@ public class PlayfairTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(decodedString, true);
|
||||
cipher.setInputString(DECODED_STRING, true);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -428,11 +424,11 @@ public class PlayfairTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'X';
|
||||
|
||||
cipher.setInputString(decodedString, true);
|
||||
cipher.setInputString(DECODED_STRING, true);
|
||||
|
||||
assertEquals(decodedStringPadded.toUpperCase(), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -445,11 +441,11 @@ public class PlayfairTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(decodedString, true);
|
||||
cipher.setInputString(DECODED_STRING, true);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -462,11 +458,11 @@ public class PlayfairTest{
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(decodedString, true);
|
||||
cipher.setInputString(DECODED_STRING, true);
|
||||
|
||||
assertEquals(decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string {}", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
@@ -498,15 +494,15 @@ public class PlayfairTest{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(encodedString, false);
|
||||
cipher.setInputString(ENCODED_STRING, false);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString);
|
||||
verify(logger, times(1)).debug("Original input string {}", ENCODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -517,16 +513,16 @@ public class PlayfairTest{
|
||||
cipher.doubled = 'x';
|
||||
|
||||
assertThrows(InvalidCharacterException.class, () -> {
|
||||
cipher.setInputString(encodedString + cipher.replaced, false);
|
||||
cipher.setInputString(ENCODED_STRING + cipher.replaced, false);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString + Character.toString(cipher.replaced));
|
||||
verify(logger, times(1)).debug("Original input string {}", ENCODED_STRING + Character.toString(cipher.replaced));
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug("Clean input string '{}'", encodedString);
|
||||
verify(logger, never()).debug("Clean input string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -537,16 +533,16 @@ public class PlayfairTest{
|
||||
cipher.doubled = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(encodedString + "a", false);
|
||||
cipher.setInputString(ENCODED_STRING + "a", false);
|
||||
});
|
||||
|
||||
assertEquals(encodedString + "a", cipher.inputString);
|
||||
assertEquals(ENCODED_STRING + "a", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Original input string {}", ENCODED_STRING + "a");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", ENCODED_STRING + "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -593,48 +589,48 @@ public class PlayfairTest{
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(13)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(13)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, never()).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_odd(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedStringPadded + 'a');
|
||||
cipher.setInputStringEncode(DECODED_STRING_PADDED + 'a');
|
||||
|
||||
assertEquals(decodedStringPadded + "ax", cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED + "ax", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "ax");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED + "ax");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_oddEndSymbol(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedStringPadded + "a*");
|
||||
cipher.setInputStringEncode(DECODED_STRING_PADDED + "a*");
|
||||
|
||||
assertEquals(decodedStringPadded + "a*x", cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED + "a*x", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "a*x");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED + "a*x");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -642,41 +638,41 @@ public class PlayfairTest{
|
||||
cipher.doubled = 'x';
|
||||
cipher.replacer = 'i';
|
||||
|
||||
cipher.setInputStringEncode(decodedStringPadded + 'x');
|
||||
cipher.setInputStringEncode(DECODED_STRING_PADDED + 'x');
|
||||
|
||||
assertEquals(decodedStringPadded + "xi", cipher.inputString);
|
||||
assertEquals(DECODED_STRING_PADDED + "xi", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "xi");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_PADDED + "xi");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputString(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
|
||||
String output = cipher.getPreparedInputString();
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
verify(logger, times(1)).debug("Getting input string ready for encoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", decodedStringClean);
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", DECODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Setting keyword");
|
||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
||||
verify(logger, times(1)).debug("Original keyword {}", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
||||
verify(logger, times(1)).debug("Appending the alphabet to the keyword");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Removing duplicate characters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -698,7 +694,7 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testFindChar(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
CharLocation returnedLocation = cipher.findChar('E');
|
||||
|
||||
@@ -710,7 +706,7 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testFindChar_invalid(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.findChar('J');
|
||||
@@ -722,61 +718,61 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testGetGridChar(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
char output = cipher.getGridChar(1, 1);
|
||||
|
||||
assertEquals(grid[1][1], output);
|
||||
assertEquals(GRID[1][1], output);
|
||||
verify(logger, times(1)).debug("Getting character from grid[{}][{}]", 1, 1);
|
||||
verify(logger, times(1)).debug("Character {}", grid[1][1]);
|
||||
verify(logger, times(1)).debug("Character {}", GRID[1][1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGridChar_large(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
char output = cipher.getGridChar(-4, -4);
|
||||
|
||||
assertEquals(grid[1][1], output);
|
||||
assertEquals(GRID[1][1], output);
|
||||
verify(logger, times(1)).debug("Getting character from grid[{}][{}]", -4, -4);
|
||||
verify(logger, times(1)).debug("Character {}", grid[1][1]);
|
||||
verify(logger, times(1)).debug("Character {}", GRID[1][1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGridChar_negative(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
char output = cipher.getGridChar(6, 6);
|
||||
|
||||
assertEquals(grid[1][1], output);
|
||||
assertEquals(GRID[1][1], output);
|
||||
verify(logger, times(1)).debug("Getting character from grid[{}][{}]", 6, 6);
|
||||
verify(logger, times(1)).debug("Character {}", grid[1][1]);
|
||||
verify(logger, times(1)).debug("Character {}", GRID[1][1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanString(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
|
||||
cipher.addCharactersToCleanString(encodedStringClean);
|
||||
cipher.addCharactersToCleanString(ENCODED_STRING_CLEAN);
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(34)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Appending uppercase");
|
||||
verify(logger, times(25)).debug("Appending lowercase");
|
||||
verify(logger, times(8)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING_PADDED;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(2)).debug("Row encoding");
|
||||
@@ -787,13 +783,13 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(2)).debug("Row decoding");
|
||||
@@ -804,10 +800,10 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -820,14 +816,14 @@ public class PlayfairTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD, cipher.getKeyword());
|
||||
assertEquals("[P L A Y F]\n[I R E X M]\n[B C D G H]\n[K N O Q S]\n[T U V W Z]", cipher.getGrid());
|
||||
assertEquals('J', cipher.getReplaced());
|
||||
assertEquals('I', cipher.getReplacer());
|
||||
@@ -839,51 +835,51 @@ public class PlayfairTest{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new Playfair(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new Playfair(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode(){
|
||||
cipher = new Playfair(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_PADDED, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new Playfair(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/PolybiusSquareTest.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -29,20 +25,20 @@ public class PolybiusSquareTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "M E S S A G E T O E N C O D E";
|
||||
private static final String encodedString = "41124545233212 5115^124225152212";
|
||||
private static final String encodedStringClean = "41 12 45 45 23 32 12 51 15 12 42 25 15 22 12";
|
||||
private static final String keyword = "ke yw*ord";
|
||||
private static final String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
private static final char[][] grid = new char[][]{
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "M E S S A G E T O E N C O D E";
|
||||
private static final String ENCODED_STRING = "41124545233212 5115^124225152212";
|
||||
private static final String ENCODED_STRING_CLEAN = "41 12 45 45 23 32 12 51 15 12 42 25 15 22 12";
|
||||
private static final String KEYWORD = "ke yw*ord";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
private static final char[][] GRID = new char[][]{
|
||||
{'K', 'E', 'Y', 'W', 'O'},
|
||||
{'R', 'D', 'A', 'B', 'C'},
|
||||
{'F', 'G', 'H', 'I', 'L'},
|
||||
{'M', 'N', 'P', 'Q', 'S'},
|
||||
{'T', 'U', 'V', 'X', 'Z'}
|
||||
};
|
||||
private static final String gridString = "[K E Y W O]\n[R D A B C]\n[F G H I L]\n[M N P Q S]\n[T U V X Z]";
|
||||
private static final String GRID_STRING = "[K E Y W O]\n[R D A B C]\n[F G H I L]\n[M N P Q S]\n[T U V X Z]";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -121,7 +117,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 +130,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 +143,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 +154,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 +167,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,20 +180,20 @@ 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGrid(){
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGrid();
|
||||
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
||||
verify(logger, times(1)).debug("Created grid\n{}", gridString);
|
||||
verify(logger, times(1)).debug("Created grid\n{}", GRID_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,16 +203,16 @@ public class PolybiusSquareTest{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,16 +222,16 @@ public class PolybiusSquareTest{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase().replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,16 +241,16 @@ public class PolybiusSquareTest{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -264,16 +260,16 @@ public class PolybiusSquareTest{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
cipher.setInputStringEncode(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringClean);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -365,14 +361,14 @@ public class PolybiusSquareTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,14 +376,14 @@ public class PolybiusSquareTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
assertEquals(ENCODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,14 +391,14 @@ public class PolybiusSquareTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
cipher.setInputStringDecode(ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
assertEquals(ENCODED_STRING.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("[^0-9\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", ENCODED_STRING.replaceAll("[^0-9\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -411,11 +407,11 @@ public class PolybiusSquareTest{
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(encodedString + "a");
|
||||
cipher.setInputStringDecode(ENCODED_STRING + "a");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING + "a");
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -428,11 +424,11 @@ public class PolybiusSquareTest{
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(encodedString + "0");
|
||||
cipher.setInputStringDecode(ENCODED_STRING + "0");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString + "0");
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING + "0");
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -492,38 +488,38 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputStringEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
String output = cipher.getPreparedInputStringEncode();
|
||||
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), output);
|
||||
assertEquals(DECODED_STRING_CLEAN.replaceAll("\\s", ""), output);
|
||||
verify(logger, times(1)).debug("Preparing input string for encoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", decodedStringClean.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", DECODED_STRING_CLEAN.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputStringDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
String output = cipher.getPreparedInputStringDecode();
|
||||
|
||||
assertEquals(encodedStringClean.replaceAll("\\s", ""), output);
|
||||
assertEquals(ENCODED_STRING_CLEAN.replaceAll("\\s", ""), output);
|
||||
verify(logger, times(1)).debug("Preparing input string for decoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", encodedStringClean.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", ENCODED_STRING_CLEAN.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword {}", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
||||
verify(logger, times(1)).debug("Appending entire alphabet");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -566,7 +562,7 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testFindChar(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
CharLocation returnedLocation = cipher.findChar('A');
|
||||
|
||||
@@ -578,7 +574,7 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testFindChar_invalid(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.findChar(cipher.replaced);
|
||||
@@ -590,41 +586,41 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanStringEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.addCharactersToCleanStringEncode(encodedStringClean.replaceAll("\\D", ""));
|
||||
cipher.addCharactersToCleanStringEncode(ENCODED_STRING_CLEAN.replaceAll("\\D", ""));
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string for encoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Adding encoded characters");
|
||||
verify(logger, times(2)).debug("Adding symbols");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanStringDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
|
||||
cipher.addCharactersToCleanStringDecode(decodedStringClean.replaceAll("\\s", ""));
|
||||
cipher.addCharactersToCleanStringDecode(DECODED_STRING_CLEAN.replaceAll("\\s", ""));
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string for decoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Adding decoded characters");
|
||||
verify(logger, times(2)).debug("Adding symbols");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(15)).debug(eq("Current working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Location {}, {}"), anyInt(), anyInt());
|
||||
@@ -632,13 +628,13 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(15)).debug(eq("Digits to decode {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Decoded letter {}"), anyChar());
|
||||
@@ -646,14 +642,14 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(keywordClean, cipher.getKeyword());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(KEYWORD_CLEAN, cipher.getKeyword());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals("[K E Y W O]\n[R D A B C]\n[F G H I L]\n[M N P Q S]\n[T U V X Z]", cipher.getGrid());
|
||||
assertEquals('J', cipher.getReplaced());
|
||||
assertEquals('I', cipher.getReplacer());
|
||||
@@ -661,10 +657,10 @@ public class PolybiusSquareTest{
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -680,51 +676,51 @@ public class PolybiusSquareTest{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new PolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new PolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode(){
|
||||
cipher = new PolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(decodedString.toUpperCase(), output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new PolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString.replaceAll("\\s", "").replaceAll("[^0-9]", ""), cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), cipher.outputString);
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING.replaceAll("\\s", "").replaceAll("[^0-9]", ""), cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN.replaceAll("\\s", ""), cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN.replaceAll("\\s", ""), output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/RailFenceTest.java
|
||||
//Mattrixwv
|
||||
// Created: 03-21-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -27,18 +23,18 @@ public class RailFenceTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
||||
private static final String encodedString3 = "Maooesg te^cdsene";
|
||||
private static final String encodedString3Clean = "MAOOESGTECDSENE";
|
||||
private static final String encodedString5 = "Moetese ne^sgcdao";
|
||||
private static final String encodedString5Clean = "MOETESENESGCDAO";
|
||||
private static final StringBuilder[] fence3 = new StringBuilder[]{
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING_3 = "Maooesg te^cdsene";
|
||||
private static final String ENCODED_STRING_3_CLEAN = "MAOOESGTECDSENE";
|
||||
private static final String ENCODED_STRING_5 = "Moetese ne^sgcdao";
|
||||
private static final String ENCODED_STRING_5_CLEAN = "MOETESENESGCDAO";
|
||||
private static final StringBuilder[] FENCE_3 = new StringBuilder[]{
|
||||
new StringBuilder("Maoo"),
|
||||
new StringBuilder("esgtecd"),
|
||||
new StringBuilder("sene")
|
||||
};
|
||||
private static final StringBuilder[] fence5 = new StringBuilder[]{
|
||||
private static final StringBuilder[] FENCE_5 = new StringBuilder[]{
|
||||
new StringBuilder("Mo"),
|
||||
new StringBuilder("ete"),
|
||||
new StringBuilder("sene"),
|
||||
@@ -101,14 +97,14 @@ public class RailFenceTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,14 +113,14 @@ public class RailFenceTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,14 +129,14 @@ public class RailFenceTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,14 +145,14 @@ public class RailFenceTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,43 +211,43 @@ public class RailFenceTest{
|
||||
|
||||
@Test
|
||||
public void testGetCleanInputString(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
String output = cipher.getCleanInputString();
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z]", ""), output);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z]", ""), output);
|
||||
verify(logger, times(1)).debug("Getting input string for encoding");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOutput(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.formatOutput(encodedString3Clean);
|
||||
cipher.formatOutput(ENCODED_STRING_3_CLEAN);
|
||||
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Formatting uppercase");
|
||||
verify(logger, times(14)).debug("Formatting lowercase");
|
||||
verify(logger, times(2)).debug("Inserting symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString3);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", ENCODED_STRING_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDecodedStringFromFence(){
|
||||
cipher.fence = fence3;
|
||||
cipher.fence = FENCE_3;
|
||||
|
||||
String output = cipher.getDecodedStringFromFence();
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z]", ""), output);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z]", ""), output);
|
||||
verify(logger, times(1)).debug("Getting decoded string from the fence");
|
||||
verify(logger, times(1)).debug(eq("Fence output '{}'"), any(StringBuilder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.fence = new StringBuilder[]{
|
||||
new StringBuilder(),
|
||||
new StringBuilder(),
|
||||
@@ -260,7 +256,7 @@ public class RailFenceTest{
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(15)).debug(eq("Working character '{}'"), anyChar());
|
||||
verify(logger, times(9)).debug("Moving up");
|
||||
@@ -272,7 +268,7 @@ public class RailFenceTest{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString3;
|
||||
cipher.inputString = ENCODED_STRING_3;
|
||||
cipher.fence = new StringBuilder[]{
|
||||
new StringBuilder(),
|
||||
new StringBuilder(),
|
||||
@@ -281,14 +277,14 @@ public class RailFenceTest{
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Number of characters in the top rail {}", 4);
|
||||
verify(logger, times(1)).debug("Number of characters in the middle rails {}", 8);
|
||||
verify(logger, times(1)).debug("Number of characters in the bottom rail {}", 4);
|
||||
verify(logger, times(1)).debug("Adding characters to the rails");
|
||||
verify(logger, times(1)).debug("Appending the bottom rail");
|
||||
verify(logger, times(1)).debug("Fence output '{}'", decodedString.replaceAll("[^a-zA-Z]", ""));
|
||||
verify(logger, times(1)).debug("Fence output '{}'", DECODED_STRING.replaceAll("[^a-zA-Z]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -314,20 +310,20 @@ public class RailFenceTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString3;
|
||||
cipher.fence = fence3;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_3;
|
||||
cipher.fence = FENCE_3;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString3, cipher.getOutputString());
|
||||
assertEquals(fence3.length, cipher.getNumRails());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING_3, cipher.getOutputString());
|
||||
assertEquals(FENCE_3.length, cipher.getNumRails());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString3;
|
||||
cipher.fence = fence3;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING_3;
|
||||
cipher.fence = FENCE_3;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -340,127 +336,127 @@ public class RailFenceTest{
|
||||
public void testPracticalEncoding_3(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.encode(3, decodedString);
|
||||
String output = cipher.encode(3, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(encodedString3, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||
assertEquals(FENCE_3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_3Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.encode(3, decodedString);
|
||||
String output = cipher.encode(3, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(encodedString3Clean, cipher.outputString);
|
||||
assertEquals(encodedString3Clean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||
assertEquals(FENCE_3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(ENCODED_STRING_3_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_5(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.encode(5, decodedString);
|
||||
String output = cipher.encode(5, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(encodedString5, cipher.outputString);
|
||||
assertEquals(encodedString5, output);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||
assertEquals(FENCE_5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(FENCE_5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(FENCE_5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(ENCODED_STRING_5, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_5, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_5Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.encode(5, decodedString);
|
||||
String output = cipher.encode(5, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(encodedString5Clean, cipher.outputString);
|
||||
assertEquals(encodedString5Clean, output);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||
assertEquals(FENCE_5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(FENCE_5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(FENCE_5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(ENCODED_STRING_5_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_5_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_3(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.decode(3, encodedString3);
|
||||
String output = cipher.decode(3, ENCODED_STRING_3);
|
||||
|
||||
assertEquals(encodedString3, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING_3, cipher.inputString);
|
||||
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||
assertEquals(FENCE_3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_3Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.decode(3, encodedString3);
|
||||
String output = cipher.decode(3, ENCODED_STRING_3);
|
||||
|
||||
assertEquals(encodedString3Clean, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_3_CLEAN, cipher.inputString);
|
||||
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||
assertEquals(FENCE_3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_5(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.decode(5, encodedString5);
|
||||
String output = cipher.decode(5, ENCODED_STRING_5);
|
||||
|
||||
assertEquals(encodedString5, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertEquals(ENCODED_STRING_5, cipher.inputString);
|
||||
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||
assertEquals(FENCE_5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(FENCE_5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(FENCE_5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_5Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.decode(5, encodedString5);
|
||||
String output = cipher.decode(5, ENCODED_STRING_5);
|
||||
|
||||
assertEquals(encodedString5Clean, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertEquals(ENCODED_STRING_5_CLEAN, cipher.inputString);
|
||||
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||
assertEquals(FENCE_5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(FENCE_5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(FENCE_5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(FENCE_5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(FENCE_5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/TrifidTest.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 04-19-24
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -32,19 +28,19 @@ public class TrifidTest{
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private static final String decodedString = "Message to^encode+";
|
||||
private static final String decodedStringClean = "MESSAGETOENCODE+";
|
||||
private static final String decodedStringCleanAlt = "MESSAGETOENCODE";
|
||||
private static final String encodedString = "Gqdokxy eg^ranmoqr";
|
||||
private static final String encodedStringAlt = "Gqdokpd od^ljvflf+";
|
||||
private static final String encodedString3 = "Gpjqdvd of^odlklf+";
|
||||
private static final String encodedStringClean = "GQDOKXYEGRANMOQR";
|
||||
private static final String encodedStringCleanAlt = "GQDOKPDODLJVFLF";
|
||||
private static final String encodedStringClean3 = "GPJQDVDOFODLKLF+";
|
||||
private static final String keyword = "ke yw*ord";
|
||||
private static final String keywordClean = "KEYWORDABCFGHIJLMNPQSTUVXZ+";
|
||||
private static final String keywordCleanAlt = "KEYWORDABCFGHIJLMNPQSTUVXZ=";
|
||||
private static final char[][][] grid = new char[][][]{
|
||||
private static final String DECODED_STRING = "Message to^encode+";
|
||||
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE+";
|
||||
private static final String DECODED_STRING_CLEAN_ALT = "MESSAGETOENCODE";
|
||||
private static final String ENCODED_STRING = "Gqdokxy eg^ranmoqr";
|
||||
private static final String ENCODED_STRING_ALT = "Gqdokpd od^ljvflf+";
|
||||
private static final String ENCODED_STRING_3 = "Gpjqdvd of^odlklf+";
|
||||
private static final String ENCODED_STRING_CLEAN = "GQDOKXYEGRANMOQR";
|
||||
private static final String ENCODED_STRING_CLEAN_ALT = "GQDOKPDODLJVFLF";
|
||||
private static final String ENCODED_STRING_CLEAN_3 = "GPJQDVDOFODLKLF+";
|
||||
private static final String KEYWORD = "ke yw*ord";
|
||||
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHIJLMNPQSTUVXZ+";
|
||||
private static final String KEYWORD_CLEAN_ALT = "KEYWORDABCFGHIJLMNPQSTUVXZ=";
|
||||
private static final char[][][] GRID = new char[][][]{
|
||||
{
|
||||
{'K', 'E', 'Y'},
|
||||
{'W', 'O', 'R'},
|
||||
@@ -61,8 +57,8 @@ public class TrifidTest{
|
||||
{'X', 'Z', '+'}
|
||||
}
|
||||
};
|
||||
private static final String gridString = "[K E Y]\n[W O R]\n[D A B]\n\n[C F G]\n[H I J]\n[L M N]\n\n[P Q S]\n[T U V]\n[X Z +]";
|
||||
private static final char[][][] gridAlt = new char[][][]{
|
||||
private static final String GRID_STRING = "[K E Y]\n[W O R]\n[D A B]\n\n[C F G]\n[H I J]\n[L M N]\n\n[P Q S]\n[T U V]\n[X Z +]";
|
||||
private static final char[][][] GRID_ALT = new char[][][]{
|
||||
{
|
||||
{'K', 'E', 'Y'},
|
||||
{'W', 'O', 'R'},
|
||||
@@ -226,16 +222,16 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
cipher.setKeyword(KEYWORD);
|
||||
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Original keyword {}", KEYWORD);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all invalid characters");
|
||||
verify(logger, times(1)).debug("Appending entire alphabet to keyword");
|
||||
verify(logger, times(1)).debug("Removing duplicate characters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", KEYWORD_CLEAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -287,13 +283,13 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void setCreateGrid(){
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
|
||||
cipher.createGrid();
|
||||
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
||||
verify(logger, times(1)).debug("Completed grid\n{}", gridString);
|
||||
verify(logger, times(1)).debug("Completed grid\n{}", GRID_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -320,14 +316,14 @@ public class TrifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,14 +332,14 @@ public class TrifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -352,14 +348,14 @@ public class TrifidTest{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -370,11 +366,11 @@ public class TrifidTest{
|
||||
cipher.fillIn = ' ';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -387,14 +383,14 @@ public class TrifidTest{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
cipher.setInputString(DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s+]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s+]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s+]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s+]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -435,17 +431,17 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void testGetCleanInputString(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
String returnedInput = cipher.getCleanInputString();
|
||||
|
||||
assertEquals(decodedStringClean, returnedInput);
|
||||
assertEquals(DECODED_STRING_CLEAN, returnedInput);
|
||||
verify(logger, times(1)).debug("Cleaning input string for encoding");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChar(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
CharLocation returnedLocation = cipher.findChar('G');
|
||||
|
||||
@@ -456,7 +452,7 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void testFindChar_invalid(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertThrows(InvalidCharacterException.class, () -> {
|
||||
cipher.findChar('=');
|
||||
@@ -468,7 +464,7 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void testGetChar(){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
char returnedChar = cipher.getChar(cipher.new CharLocation(0, 1, 2));
|
||||
|
||||
@@ -483,7 +479,7 @@ public class TrifidTest{
|
||||
"0, 1, 3"
|
||||
})
|
||||
public void testGetChar_invalidLocation(int x, int y, int z){
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
CharLocation location = cipher.new CharLocation(x, y, z);
|
||||
|
||||
assertThrows(InvalidCharacterException.class, () -> {
|
||||
@@ -496,47 +492,47 @@ public class TrifidTest{
|
||||
@Test
|
||||
public void testFormatOutput(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
|
||||
cipher.formatOutput(encodedStringClean);
|
||||
cipher.formatOutput(ENCODED_STRING_CLEAN);
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output");
|
||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Formatting uppercase");
|
||||
verify(logger, times(14)).debug("Formatting lowercase");
|
||||
verify(logger, times(1)).debug("Adding fillIn");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", ENCODED_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOutput_noCapitals(){
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.inputString = decodedString.toUpperCase();
|
||||
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||
|
||||
cipher.formatOutput(encodedStringClean);
|
||||
cipher.formatOutput(ENCODED_STRING_CLEAN);
|
||||
|
||||
assertEquals(encodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(ENCODED_STRING.toUpperCase(), cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output");
|
||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Formatting uppercase");
|
||||
verify(logger, never()).debug("Formatting lowercase");
|
||||
verify(logger, times(1)).debug("Adding fillIn");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", ENCODED_STRING.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||
@@ -548,14 +544,14 @@ public class TrifidTest{
|
||||
@Test
|
||||
public void testEncode_3(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
cipher.groupSize = 3;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||
@@ -567,13 +563,13 @@ public class TrifidTest{
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||
@@ -585,14 +581,14 @@ public class TrifidTest{
|
||||
@Test
|
||||
public void testDecode_3(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.inputString = encodedString3;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
cipher.inputString = ENCODED_STRING_3;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.grid = GRID;
|
||||
cipher.groupSize = 3;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||
@@ -603,28 +599,28 @@ public class TrifidTest{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD_CLEAN;
|
||||
cipher.groupSize = 3;
|
||||
cipher.fillIn = '=';
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keywordClean, cipher.getKeyword());
|
||||
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||
assertEquals(KEYWORD_CLEAN, cipher.getKeyword());
|
||||
assertEquals(3, cipher.getGroupSize());
|
||||
assertEquals('=', cipher.getFillIn());
|
||||
assertEquals(gridString, cipher.getGrid());
|
||||
assertEquals(GRID_STRING, cipher.getGrid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.inputString = DECODED_STRING;
|
||||
cipher.outputString = ENCODED_STRING;
|
||||
cipher.keyword = KEYWORD;
|
||||
cipher.groupSize = 3;
|
||||
cipher.grid = grid;
|
||||
cipher.grid = GRID;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
@@ -639,155 +635,155 @@ public class TrifidTest{
|
||||
public void testPracticalEncoding(){
|
||||
cipher = new Trifid(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_3(){
|
||||
cipher = new Trifid(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, 3, decodedString);
|
||||
String output = cipher.encode(KEYWORD, 3, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(encodedString3, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_3, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_fill(){
|
||||
cipher = new Trifid(true, true, true, '=');
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
||||
assertEquals(encodedStringAlt, cipher.outputString);
|
||||
assertEquals(encodedStringAlt, output);
|
||||
assertArrayEquals(gridAlt, cipher.grid);
|
||||
assertEquals(DECODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_ALT, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_ALT, output);
|
||||
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean(){
|
||||
cipher = new Trifid(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_clean3(){
|
||||
cipher = new Trifid(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, 3, decodedString);
|
||||
String output = cipher.encode(KEYWORD, 3, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean3, cipher.outputString);
|
||||
assertEquals(encodedStringClean3, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN_3, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN_3, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_cleanFill(){
|
||||
cipher = new Trifid(false, false, false, '=');
|
||||
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||
|
||||
assertEquals(decodedStringCleanAlt, cipher.inputString);
|
||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
||||
assertEquals(encodedStringCleanAlt, cipher.outputString);
|
||||
assertEquals(encodedStringCleanAlt, output);
|
||||
assertArrayEquals(gridAlt, cipher.grid);
|
||||
assertEquals(DECODED_STRING_CLEAN_ALT, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||
assertEquals(ENCODED_STRING_CLEAN_ALT, cipher.outputString);
|
||||
assertEquals(ENCODED_STRING_CLEAN_ALT, output);
|
||||
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding(){
|
||||
cipher = new Trifid(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_3(){
|
||||
cipher = new Trifid(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, 3, encodedString3);
|
||||
String output = cipher.decode(KEYWORD, 3, ENCODED_STRING_3);
|
||||
|
||||
assertEquals(encodedString3, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_3, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_fill(){
|
||||
cipher = new Trifid(true, true, true, '=');
|
||||
|
||||
String output = cipher.decode(keyword, encodedStringAlt);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING_ALT);
|
||||
|
||||
assertEquals(encodedStringAlt, cipher.inputString);
|
||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
assertArrayEquals(gridAlt, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_ALT, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||
assertEquals(DECODED_STRING, cipher.outputString);
|
||||
assertEquals(DECODED_STRING, output);
|
||||
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testpracticalDecoding_clean(){
|
||||
cipher = new Trifid(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_clean3(){
|
||||
cipher = new Trifid(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, 3, encodedString3);
|
||||
String output = cipher.decode(KEYWORD, 3, ENCODED_STRING_3);
|
||||
|
||||
assertEquals(encodedStringClean3, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_CLEAN_3, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN, output);
|
||||
assertArrayEquals(GRID, cipher.grid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_cleanFill(){
|
||||
cipher = new Trifid(false, false, false, '=');
|
||||
|
||||
String output = cipher.decode(keyword, encodedStringAlt);
|
||||
String output = cipher.decode(KEYWORD, ENCODED_STRING_ALT);
|
||||
|
||||
assertEquals(encodedStringCleanAlt, cipher.inputString);
|
||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
||||
assertEquals(decodedStringCleanAlt, cipher.outputString);
|
||||
assertEquals(decodedStringCleanAlt, output);
|
||||
assertArrayEquals(gridAlt, cipher.grid);
|
||||
assertEquals(ENCODED_STRING_CLEAN_ALT, cipher.inputString);
|
||||
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||
assertEquals(DECODED_STRING_CLEAN_ALT, cipher.outputString);
|
||||
assertEquals(DECODED_STRING_CLEAN_ALT, output);
|
||||
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user