Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
d710375595
|
|||
|
8e41b0a2ad
|
|||
|
1943f19b4e
|
|||
|
ec0bf31906
|
|||
|
d12eb91245
|
|||
| f419e6020b | |||
| f9f61081bc | |||
| dc81847123 | |||
| a1ec1909d4 | |||
| 6b420338df | |||
| 01eb38d360 | |||
| cf64e3c933 | |||
| f41e7aefb4 |
57
README.md
57
README.md
@@ -1,15 +1,18 @@
|
|||||||
# Cipher Stream Java
|
# 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
|
## Combination
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
### ADFGX
|
### ADFGX
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Example:
|
```txt
|
||||||
```
|
|
||||||
Square Keyword = SQUAREKEYWORD
|
Square Keyword = SQUAREKEYWORD
|
||||||
Keyword = KEYWORD
|
Keyword = KEYWORD
|
||||||
Message = Message to encode
|
Message = Message to encode
|
||||||
@@ -17,114 +20,114 @@ AAGAGADFAGAXXDAXDXADAFAFXDDGDF
|
|||||||
```
|
```
|
||||||
|
|
||||||
### ADFGVX
|
### ADFGVX
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Example:
|
```txt
|
||||||
```
|
|
||||||
Square Keyword = SQUAREKEYWORD
|
Square Keyword = SQUAREKEYWORD
|
||||||
Keyword = KEYWORD
|
Keyword = KEYWORD
|
||||||
Message = Message to encode
|
Message = Message to encode
|
||||||
AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA
|
AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Mono-Substitution
|
## 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.
|
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
|
### 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.
|
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 ->
|
Message to encode ->
|
||||||
1001101 1100101 1110011 1110011 1100001 1100111 1100101 100000 1110100 1101111 100000 1100101 1101110 1100011 1101111 1100100 1100101
|
1001101 1100101 1110011 1110011 1100001 1100111 1100101 100000 1110100 1101111 100000 1100101 1101110 1100011 1101111 1100100 1100101
|
||||||
```
|
```
|
||||||
|
|
||||||
### Baconian
|
### 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.
|
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 ->
|
Message to encode ->
|
||||||
ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa
|
ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa
|
||||||
```
|
```
|
||||||
|
|
||||||
### Caesar
|
### 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.
|
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
|
offset = 3
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
Phvvdjh wr hqfrgh
|
Phvvdjh wr hqfrgh
|
||||||
```
|
```
|
||||||
|
|
||||||
### Atbash
|
### Atbash
|
||||||
|
|
||||||
The Atbash cipher reverses the alphabet for encryption. i.e. a = z, b = y, .... It does not require a key.
|
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 ->
|
Message to enocde ->
|
||||||
Nvhhztv gl vmxlwv
|
Nvhhztv gl vmxlwv
|
||||||
```
|
```
|
||||||
|
|
||||||
### Vigenere
|
### 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.
|
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
|
key = keyword
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
Wiqooxh ds cjqfgo
|
Wiqooxh ds cjqfgo
|
||||||
```
|
```
|
||||||
|
|
||||||
### Autokey
|
### 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.
|
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
|
key = keyword
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
Wiqooxh fs wfcuhx
|
Wiqooxh fs wfcuhx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Poly-Substitution
|
## 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.
|
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
|
### Columnar
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Example:
|
```txt
|
||||||
```
|
|
||||||
key = keyword
|
key = keyword
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
Edxeoxm te acxgoxsnxsex
|
Edxeoxm te acxgoxsnxsex
|
||||||
```
|
```
|
||||||
|
|
||||||
### Morse
|
### 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.
|
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 ->
|
Message to encode ->
|
||||||
-- . ... ... .- --. . - --- . -. -.-. --- -.. .
|
-- . ... ... .- --. . - --- . -. -.-. --- -.. .
|
||||||
```
|
```
|
||||||
|
|
||||||
### Playfair
|
### Playfair
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Example:
|
```txt
|
||||||
```
|
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
NKQZPCNDZKDULCGD
|
NKQZPCNDZKDULCGD
|
||||||
```
|
```
|
||||||
|
|
||||||
### PolybiusSquare
|
### PolybiusSquare
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Example:
|
```txt
|
||||||
```
|
|
||||||
Message to encode ->
|
Message to encode ->
|
||||||
41124545233212 5115 124225152212
|
41124545233212 5115 124225152212
|
||||||
```
|
```
|
||||||
|
|||||||
222
pom.xml
222
pom.xml
@@ -14,19 +14,19 @@
|
|||||||
<developer>
|
<developer>
|
||||||
<name>Matthew Ellison</name>
|
<name>Matthew Ellison</name>
|
||||||
<email>m_ellison@ymail.com</email>
|
<email>m_ellison@ymail.com</email>
|
||||||
<url>https://bitbucket.org/Mattrixwv</url>
|
<url>https://git.mattrixwv.com/matthew</url>
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git://bitbucket.org/Mattrixwv/CipherStreamJava.git</connection>
|
<connection>scm:git:git://git.mattrixwv.com/HomeLab/CipherStreamJava.git</connection>
|
||||||
<developerConnection>scm:git:ssh://bitbucket.org:Mattrixwv/CipherStreamJava.git</developerConnection>
|
<developerConnection>scm:git:ssh://git.mattrixwv.com/HomeLab/CipherStreamJava.git</developerConnection>
|
||||||
<url>https://bitbucket.org/Mattrixwv/CipherStreamJava/src</url>
|
<url>https://git.mattrixwv.com/HomeLab/CipherStreamJava</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<groupId>com.mattrixwv</groupId>
|
<groupId>com.mattrixwv</groupId>
|
||||||
<artifactId>cipher-stream-java</artifactId>
|
<artifactId>cipher-stream-java</artifactId>
|
||||||
<version>1.3.6</version>
|
<version>1.4.0</version>
|
||||||
|
|
||||||
<name>CipherStreamJava</name>
|
<name>CipherStreamJava</name>
|
||||||
<description>A library to encrypt and decrypt simple ciphers</description>
|
<description>A library to encrypt and decrypt simple ciphers</description>
|
||||||
@@ -37,17 +37,16 @@
|
|||||||
<!--Compile-->
|
<!--Compile-->
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
<java.version>21</java.version>
|
<java.version>25</java.version>
|
||||||
|
|
||||||
<!--Sonarqube-->
|
<!--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.jsonReportPath>target/dependency-check-report.json</sonar.dependencyCheck.jsonReportPath>
|
||||||
<sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
|
<sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
|
||||||
|
|
||||||
<!--Deployment-->
|
<argLine></argLine>
|
||||||
<gpg.keyname>3BA6515C8FF145249BEBBEABA52FDEC4259179D4</gpg.keyname>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
@@ -55,71 +54,151 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mattrixwv</groupId>
|
<groupId>com.mattrixwv</groupId>
|
||||||
<artifactId>myClasses</artifactId>
|
<artifactId>myClasses</artifactId>
|
||||||
<version>1.3.6</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mattrixwv</groupId>
|
<groupId>com.mattrixwv</groupId>
|
||||||
<artifactId>matrix</artifactId>
|
<artifactId>matrix</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>2.0.16</version>
|
<version>2.0.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Test-->
|
<!--Test-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>5.10.3</version>
|
<version>6.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-params</artifactId>
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
<version>5.10.3</version>
|
<version>6.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>5.12.0</version>
|
<version>5.21.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-junit-jupiter</artifactId>
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
<version>5.12.0</version>
|
<version>5.21.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.simplify4u</groupId>
|
<groupId>org.simplify4u</groupId>
|
||||||
<artifactId>slf4j2-mock</artifactId>
|
<artifactId>slf4j2-mock</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.4.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!--Ensure maven is the correct version-->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-enforcer-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
<version>3.5.0</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>enforce-maven</id>
|
<id>enforce-maven</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>enforce</goal>
|
<goal>enforce</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.9.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>properties</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!--Sonarqube-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.owasp</groupId>
|
||||||
|
<artifactId>dependency-check-maven</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>dependency-check</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!--Deployment-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.central</groupId>
|
||||||
|
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign-artifacts</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<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>
|
<configuration>
|
||||||
<rules>
|
<rules>
|
||||||
<requireMavenVersion>
|
<requireMavenVersion>
|
||||||
@@ -127,61 +206,68 @@
|
|||||||
</requireMavenVersion>
|
</requireMavenVersion>
|
||||||
</rules>
|
</rules>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<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>
|
<version>3.4.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>3.3.1</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.13.0</version>
|
<version>3.14.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<release>${java.version}</release>
|
<release>${java.version}</release>
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
<arg>-Xlint:all</arg>
|
<arg>-Xlint:all</arg>
|
||||||
|
<arg>-Xlint:-serial</arg>
|
||||||
</compilerArgs>
|
</compilerArgs>
|
||||||
<showWarnings>true</showWarnings>
|
<showWarnings>true</showWarnings>
|
||||||
<showDeprecation>true</showDeprecation>
|
<showDeprecation>true</showDeprecation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.5.4</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.5.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.1.4</version>
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
<version>3.1.2</version>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.7.1</version>
|
<version>3.8.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
<version>3.12.1</version>
|
<version>3.21.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
<version>3.6.2</version>
|
<version>3.9.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>versions-maven-plugin</artifactId>
|
<artifactId>versions-maven-plugin</artifactId>
|
||||||
<version>2.17.1</version>
|
<version>2.21.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -189,18 +275,18 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
<version>3.7.1</version>
|
<version>3.9.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!--Sonarqube-->
|
<!--Sonarqube-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||||
<artifactId>sonar-maven-plugin</artifactId>
|
<artifactId>sonar-maven-plugin</artifactId>
|
||||||
<version>4.0.0.4121</version>
|
<version>5.5.0.6356</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.12</version>
|
<version>0.8.14</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>jacoco-initialize</id>
|
<id>jacoco-initialize</id>
|
||||||
@@ -221,20 +307,15 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.owasp</groupId>
|
<groupId>org.owasp</groupId>
|
||||||
<artifactId>dependency-check-maven</artifactId>
|
<artifactId>dependency-check-maven</artifactId>
|
||||||
<version>10.0.3</version>
|
<version>12.2.0</version>
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>none</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<formats>
|
<formats>
|
||||||
<format>json</format>
|
<format>json</format>
|
||||||
<format>html</format>
|
<format>html</format>
|
||||||
</formats>
|
</formats>
|
||||||
|
<nvdApiServerId>nvd</nvdApiServerId>
|
||||||
|
<failBuildOnCVSS>7</failBuildOnCVSS>
|
||||||
|
<ossIndexServerId>ossindex</ossIndexServerId>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
@@ -242,29 +323,27 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.central</groupId>
|
<groupId>org.sonatype.central</groupId>
|
||||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||||
<version>0.5.0</version>
|
<version>0.10.0</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<publishingServerId>ossrh</publishingServerId>
|
<publishingServerId>central</publishingServerId>
|
||||||
|
<autoPublish>true</autoPublish>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>3.1.4</version>
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<serverId>ossrh</serverId>
|
<skip>true</skip>
|
||||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
|
||||||
<autoReleaseAfterCloase>true</autoReleaseAfterCloase>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.4.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<id>attach-sources</id>
|
||||||
@@ -278,7 +357,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.12.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-javadocs</id>
|
<id>attach-javadocs</id>
|
||||||
@@ -292,7 +371,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.2.8</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@@ -300,23 +379,10 @@
|
|||||||
<goals>
|
<goals>
|
||||||
<goal>sign</goal>
|
<goal>sign</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
|
||||||
<keyname>${gpg.keyname}</keyname>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<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>
|
|
||||||
</project>
|
</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;
|
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>
|
* <li>Encoding/decoding with a columnar transposition cipher (Columnar)</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
public class ADFGVX{
|
public final class ADFGVX{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class);
|
private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The string that needs encoded/decoded */
|
/** 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;
|
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>
|
* <li>Encoding/decoding with a columnar transposition cipher (Columnar)</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
public class ADFGX{
|
public final class ADFGX{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ADFGX.class);
|
private static final Logger logger = LoggerFactory.getLogger(ADFGX.class);
|
||||||
|
|
||||||
//?Internal fields
|
//?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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|||||||
* <li><strong>Key2</strong>: The additive key</li>
|
* <li><strong>Key2</strong>: The additive key</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class Affine{
|
public final class Affine{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
|
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The string that needs encoded/decoded */
|
/** 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;
|
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.
|
* The Atbash cipher is symmetric, meaning that encoding and decoding are the same operation.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Atbash{
|
public final class Atbash{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
|
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** Holds the string that needs encoded or decoded */
|
/** 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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +21,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
|||||||
* and sequences are converted back to letters for decoding.
|
* and sequences are converted back to letters for decoding.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Baconian{
|
public final class Baconian{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||||
|
|
||||||
//?Conversions
|
//?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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +22,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
|||||||
* for the specified base.
|
* for the specified base.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class BaseX{
|
public final class BaseX{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The string that needs encoded/decoded */
|
/** 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;
|
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
|
* This class allows you to encode and decode strings with options to preserve
|
||||||
* capitalization, whitespace, and symbols.
|
* capitalization, whitespace, and symbols.
|
||||||
*/
|
*/
|
||||||
public class Beaufort{
|
public final class Beaufort{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Beaufort.class);
|
private static final Logger logger = LoggerFactory.getLogger(Beaufort.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** This is the string that needs encoded/decoded */
|
/** 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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +17,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
|||||||
* capitalization, whitespace, and symbols.
|
* capitalization, whitespace, and symbols.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Caesar{
|
public final class Caesar{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The string that needs encoded/decoded */
|
/** The string that needs encoded/decoded */
|
||||||
@@ -64,6 +44,11 @@ public class Caesar{
|
|||||||
logger.debug("Setting shift {}", shiftAmount);
|
logger.debug("Setting shift {}", shiftAmount);
|
||||||
|
|
||||||
//If you shift more than 26 you will just be wrapping back around again
|
//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;
|
shift = shiftAmount % 26;
|
||||||
|
|
||||||
logger.debug("Cleaned shift {}", shift);
|
logger.debug("Cleaned shift {}", shift);
|
||||||
@@ -120,7 +105,7 @@ public class Caesar{
|
|||||||
if(Character.isUpperCase(currentChar)){
|
if(Character.isUpperCase(currentChar)){
|
||||||
logger.debug("Encoding uppercase");
|
logger.debug("Encoding uppercase");
|
||||||
|
|
||||||
currentChar += shift;
|
currentChar = (char)(currentChar + shift);
|
||||||
//Wrap around if the letter is now out of bounds
|
//Wrap around if the letter is now out of bounds
|
||||||
if(currentChar < 'A'){
|
if(currentChar < 'A'){
|
||||||
logger.debug("Wrapping around to Z");
|
logger.debug("Wrapping around to Z");
|
||||||
@@ -135,7 +120,7 @@ public class Caesar{
|
|||||||
else if(Character.isLowerCase(currentChar)){
|
else if(Character.isLowerCase(currentChar)){
|
||||||
logger.debug("Encoding lowercase");
|
logger.debug("Encoding lowercase");
|
||||||
|
|
||||||
currentChar += shift;
|
currentChar = (char)(currentChar + shift);
|
||||||
//Wrap around if the letter is now out of bounds
|
//Wrap around if the letter is now out of bounds
|
||||||
if(currentChar < 'a'){
|
if(currentChar < 'a'){
|
||||||
logger.debug("Wrapping around to z");
|
logger.debug("Wrapping around to z");
|
||||||
@@ -170,7 +155,7 @@ public class Caesar{
|
|||||||
if(Character.isUpperCase(currentChar)){
|
if(Character.isUpperCase(currentChar)){
|
||||||
logger.debug("Decoding uppercase");
|
logger.debug("Decoding uppercase");
|
||||||
|
|
||||||
currentChar -= shift;
|
currentChar = (char)(currentChar - shift);
|
||||||
//Wrap around if the letter is now out of bounds
|
//Wrap around if the letter is now out of bounds
|
||||||
if(currentChar < 'A'){
|
if(currentChar < 'A'){
|
||||||
logger.debug("Wrapping around to Z");
|
logger.debug("Wrapping around to Z");
|
||||||
@@ -187,7 +172,7 @@ public class Caesar{
|
|||||||
else if(Character.isLowerCase(currentChar)){
|
else if(Character.isLowerCase(currentChar)){
|
||||||
logger.debug("Decoding lowercase");
|
logger.debug("Decoding lowercase");
|
||||||
|
|
||||||
currentChar -= shift;
|
currentChar = (char)(currentChar - shift);
|
||||||
//Wrap around if the letter is now out of bounds
|
//Wrap around if the letter is now out of bounds
|
||||||
if(currentChar < 'a'){
|
if(currentChar < 'a'){
|
||||||
logger.debug("Wrapping around to z");
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|||||||
* certain characters based on configuration settings.
|
* certain characters based on configuration settings.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Porta{
|
public final class Porta{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||||
|
|
||||||
/** Predefined alphabetic tableau used for encoding and decoding */
|
/** 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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +19,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|||||||
* of the alphabet and optionally digits, without duplicates.
|
* of the alphabet and optionally digits, without duplicates.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Substitution{
|
public final class Substitution{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Substitution.class);
|
private static final Logger logger = LoggerFactory.getLogger(Substitution.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The string that needs encoded/decoded */
|
/** 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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -248,7 +228,10 @@ public class Vigenere{
|
|||||||
*/
|
*/
|
||||||
public Vigenere(){
|
public Vigenere(){
|
||||||
offset = new ArrayList<>();
|
offset = new ArrayList<>();
|
||||||
reset();
|
inputString = "";
|
||||||
|
outputString = "";
|
||||||
|
keyword = "";
|
||||||
|
offset.clear();
|
||||||
preserveCapitals = false;
|
preserveCapitals = false;
|
||||||
preserveWhitespace = false;
|
preserveWhitespace = false;
|
||||||
preserveSymbols = false;
|
preserveSymbols = false;
|
||||||
@@ -262,7 +245,10 @@ public class Vigenere{
|
|||||||
*/
|
*/
|
||||||
public Vigenere(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){
|
public Vigenere(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){
|
||||||
offset = new ArrayList<>();
|
offset = new ArrayList<>();
|
||||||
reset();
|
inputString = "";
|
||||||
|
outputString = "";
|
||||||
|
keyword = "";
|
||||||
|
offset.clear();
|
||||||
this.preserveCapitals = preserveCapitals;
|
this.preserveCapitals = preserveCapitals;
|
||||||
this.preserveWhitespace = preserveWhitespace;
|
this.preserveWhitespace = preserveWhitespace;
|
||||||
this.preserveSymbols = preserveSymbols;
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +20,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|||||||
* them back into text.
|
* them back into text.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Bifid{
|
public final class Bifid{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Bifid.class);
|
private static final Logger logger = LoggerFactory.getLogger(Bifid.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The message that needs to be encoded/decoded */
|
/** 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;
|
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.
|
* It also includes options to preserve capitalization, whitespace, symbols, and to handle padding characters.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Columnar{
|
public final class Columnar{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
private static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The message that needs to be encoded/decoded */
|
/** 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;
|
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.
|
* messages. It operates on blocks of text by representing them as vectors and applying matrix transformations.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Hill{
|
public final class Hill{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Hill.class);
|
private static final Logger logger = LoggerFactory.getLogger(Hill.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The message that needs to be encoded/decoded */
|
/** 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
|
* 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.
|
* 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);
|
private static final Logger logger = LoggerFactory.getLogger(LargePolybiusSquare.class);
|
||||||
|
|
||||||
|
|
||||||
@@ -239,6 +239,7 @@ public class LargePolybiusSquare extends PolybiusSquare{
|
|||||||
*/
|
*/
|
||||||
public LargePolybiusSquare() throws InvalidCharacterException{
|
public LargePolybiusSquare() throws InvalidCharacterException{
|
||||||
super();
|
super();
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Constructs a PolybiusSquare cipher instance with specified settings.
|
* 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{
|
public LargePolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{
|
||||||
super(preserveWhitespace, preserveSymbols);
|
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;
|
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.
|
* It supports alphanumeric characters (A-Z, 0-9) and validates input to ensure it contains valid characters.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class Morse{
|
public final class Morse{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Morse.class);
|
private static final Logger logger = LoggerFactory.getLogger(Morse.class);
|
||||||
//?Code representations
|
//?Code representations
|
||||||
/** Morse code representations for letters A-Z */
|
/** 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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +15,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
|||||||
* Represents the Playfair cipher encryption and decryption.
|
* Represents the Playfair cipher encryption and decryption.
|
||||||
* The Playfair cipher is a digraph substitution cipher that encrypts pairs of letters.
|
* 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);
|
private static final Logger logger = LoggerFactory.getLogger(Playfair.class);
|
||||||
|
|
||||||
/** A class representing the location of a character in the grid */
|
/** 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;
|
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
|
* @throws InvalidCharacterException if the character is not a letter or is invalid
|
||||||
|
* @return the validated character
|
||||||
*/
|
*/
|
||||||
protected void setReplaced(char replaced) throws InvalidCharacterException{
|
private char validateReplaced(char replaced) throws InvalidCharacterException{
|
||||||
logger.debug("Setting replaced");
|
logger.debug("Validating replaced character {}", replaced);
|
||||||
logger.debug("Original character {}", replaced);
|
|
||||||
|
|
||||||
if(!Character.isAlphabetic(replaced)){
|
if(!Character.isAlphabetic(replaced)){
|
||||||
throw new InvalidCharacterException("The replaced character must be a letter");
|
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");
|
throw new InvalidCharacterException("The replaced letter cannot be the same as the replacing letter");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.replaced = Character.toUpperCase(replaced);
|
replaced = Character.toUpperCase(replaced);
|
||||||
logger.debug("Cleaned character {}", this.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
|
* @throws InvalidCharacterException if the character is not a letter or is invalid
|
||||||
*/
|
*/
|
||||||
protected void setReplacer(char replacer) throws InvalidCharacterException{
|
protected void setReplaced(char replaced) throws InvalidCharacterException{
|
||||||
logger.debug("Setting replacer");
|
logger.debug("Setting replaced");
|
||||||
logger.debug("Original character {}", replacer);
|
|
||||||
|
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)){
|
if(!Character.isAlphabetic(replacer)){
|
||||||
throw new InvalidCharacterException("The replacer character must be a letter");
|
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");
|
throw new InvalidCharacterException("The replacer letter cannot be the same as the replaced letter");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.replacer = Character.toUpperCase(replacer);
|
replacer = Character.toUpperCase(replacer);
|
||||||
logger.debug("Cleaned character {}", this.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.
|
* Creates the grid from the keyword.
|
||||||
@@ -478,9 +482,12 @@ public class PolybiusSquare{
|
|||||||
* @throws InvalidCharacterException if default characters are invalid
|
* @throws InvalidCharacterException if default characters are invalid
|
||||||
*/
|
*/
|
||||||
public PolybiusSquare() throws InvalidCharacterException{
|
public PolybiusSquare() throws InvalidCharacterException{
|
||||||
reset();
|
grid = new char[5][5];
|
||||||
setReplaced('J');
|
inputString = "";
|
||||||
setReplacer('I');
|
outputString = "";
|
||||||
|
keyword = "";
|
||||||
|
this.replaced = validateReplaced('J');
|
||||||
|
this.replacer = validateReplacer('I');
|
||||||
preserveWhitespace = false;
|
preserveWhitespace = false;
|
||||||
preserveSymbols = false;
|
preserveSymbols = false;
|
||||||
}
|
}
|
||||||
@@ -492,9 +499,12 @@ public class PolybiusSquare{
|
|||||||
* @throws InvalidCharacterException if default characters are invalid
|
* @throws InvalidCharacterException if default characters are invalid
|
||||||
*/
|
*/
|
||||||
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{
|
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{
|
||||||
reset();
|
grid = new char[5][5];
|
||||||
setReplaced('J');
|
inputString = "";
|
||||||
setReplacer('I');
|
outputString = "";
|
||||||
|
keyword = "";
|
||||||
|
this.replaced = validateReplaced('J');
|
||||||
|
this.replacer = validateReplacer('I');
|
||||||
this.preserveWhitespace = preserveWhitespace;
|
this.preserveWhitespace = preserveWhitespace;
|
||||||
this.preserveSymbols = preserveSymbols;
|
this.preserveSymbols = preserveSymbols;
|
||||||
}
|
}
|
||||||
@@ -508,9 +518,12 @@ public class PolybiusSquare{
|
|||||||
* @throws InvalidCharacterException if any character is invalid
|
* @throws InvalidCharacterException if any character is invalid
|
||||||
*/
|
*/
|
||||||
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols, char replaced, char replacer) throws InvalidCharacterException{
|
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols, char replaced, char replacer) throws InvalidCharacterException{
|
||||||
reset();
|
grid = new char[5][5];
|
||||||
setReplaced(replaced);
|
inputString = "";
|
||||||
setReplacer(replacer);
|
outputString = "";
|
||||||
|
keyword = "";
|
||||||
|
this.replaced = validateReplaced(replaced);
|
||||||
|
this.replacer = validateReplacer(replacer);
|
||||||
this.preserveWhitespace = preserveWhitespace;
|
this.preserveWhitespace = preserveWhitespace;
|
||||||
this.preserveSymbols = preserveSymbols;
|
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;
|
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
|
* 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.
|
* 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);
|
private static final Logger logger = LoggerFactory.getLogger(RailFence.class);
|
||||||
//?Fields
|
//?Fields
|
||||||
/** The message that needs to be encoded/decoded */
|
/** 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;
|
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
|
* The {@code Trifid} class implements the Trifid cipher, a polyalphabetic substitution cipher
|
||||||
* that uses a 3x3x3 grid to encode and decode messages.
|
* 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);
|
private static final Logger logger = LoggerFactory.getLogger(Trifid.class);
|
||||||
|
|
||||||
/** A class representing the location of a character in the grid */
|
/** 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;
|
package com.mattrixwv.cipherstream.combination;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,12 +25,12 @@ public class ADFGVXTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
private static final String ENCODED_STRING = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||||
private static final String encodedStringClean = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
private static final String ENCODED_STRING_CLEAN = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||||
private static final String keyword = "keyword";
|
private static final String KEYWORD = "keyword";
|
||||||
private static final String squareKeyword = "SquareKeyword";
|
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -99,10 +95,10 @@ public class ADFGVXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetSquareKeyword(){
|
public void testSetSquareKeyword(){
|
||||||
cipher.setSquareKeyword(squareKeyword);
|
cipher.setSquareKeyword(SQUARE_KEYWORD);
|
||||||
|
|
||||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
assertEquals(SQUARE_KEYWORD, cipher.squareKeyword);
|
||||||
verify(logger, times(1)).debug("squareKeyword '{}'", squareKeyword);
|
verify(logger, times(1)).debug("squareKeyword '{}'", SQUARE_KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -117,10 +113,10 @@ public class ADFGVXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("keyword '{}'", keyword);
|
verify(logger, times(1)).debug("keyword '{}'", KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -139,14 +135,14 @@ public class ADFGVXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -155,14 +151,14 @@ public class ADFGVXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 capitals");
|
verify(logger, times(1)).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -171,14 +167,14 @@ public class ADFGVXTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -187,14 +183,14 @@ public class ADFGVXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -235,45 +231,45 @@ public class ADFGVXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormateOutputStringEncode(){
|
public void testFormateOutputStringEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedStringClean;
|
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||||
|
|
||||||
cipher.formatOutputStringEncode();
|
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(1)).debug("Formatting output string to match input string");
|
||||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||||
verify(logger, times(2)).debug("Appending symbol to output");
|
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
|
@Test
|
||||||
public void testFormatOutputStringDecode(){
|
public void testFormatOutputStringDecode(){
|
||||||
cipher.outputString = decodedStringClean;
|
cipher.outputString = DECODED_STRING_CLEAN;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.formatOutputStringDecode();
|
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(1)).debug("Formatting output string to match input string");
|
||||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||||
verify(logger, times(2)).debug("Appending symbol to output");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
|
|
||||||
cipher.encode();
|
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("Encoding using Polybius Square");
|
||||||
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
||||||
verify(logger, times(1)).debug("Encoding using columnar");
|
verify(logger, times(1)).debug("Encoding using columnar");
|
||||||
@@ -281,13 +277,13 @@ public class ADFGVXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding using columnar");
|
verify(logger, times(1)).debug("Decoding using columnar");
|
||||||
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
||||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||||
@@ -295,25 +291,25 @@ public class ADFGVXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(squareKeyword, cipher.getSquareKeyword());
|
assertEquals(SQUARE_KEYWORD, cipher.getSquareKeyword());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
LargePolybiusSquare ps = cipher.largePolybiusSquare;
|
LargePolybiusSquare ps = cipher.largePolybiusSquare;
|
||||||
Columnar columnar = cipher.columnar;
|
Columnar columnar = cipher.columnar;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -330,47 +326,47 @@ public class ADFGVXTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new ADFGVX(true, true, true);
|
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(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new ADFGVX(false, false, false);
|
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(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new ADFGVX(true, true, true);
|
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(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new ADFGVX(false, false, false);
|
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(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.combination;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,12 +25,12 @@ public class ADFGXTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
private static final String ENCODED_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||||
private static final String encodedStringClean = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
private static final String ENCODED_STRING_CLEAN = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||||
private static final String keyword = "keyword";
|
private static final String KEYWORD = "keyword";
|
||||||
private static final String squareKeyword = "SquareKeyword";
|
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -99,9 +95,9 @@ public class ADFGXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetSquareKeyword(){
|
public void testSetSquareKeyword(){
|
||||||
cipher.setSquareKeyword(squareKeyword);
|
cipher.setSquareKeyword(SQUARE_KEYWORD);
|
||||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
assertEquals(SQUARE_KEYWORD, cipher.squareKeyword);
|
||||||
verify(logger, times(1)).debug("Square keyword '{}'", squareKeyword);
|
verify(logger, times(1)).debug("Square keyword '{}'", SQUARE_KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -116,10 +112,10 @@ public class ADFGXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Keyword '{}'", keyword);
|
verify(logger, times(1)).debug("Keyword '{}'", KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,14 +134,14 @@ public class ADFGXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -154,14 +150,14 @@ public class ADFGXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 capitals");
|
verify(logger, times(1)).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -170,14 +166,14 @@ public class ADFGXTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -186,14 +182,14 @@ public class ADFGXTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 capitals");
|
verify(logger, never()).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -234,45 +230,45 @@ public class ADFGXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatOutputStringEncode(){
|
public void testFormatOutputStringEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedStringClean;
|
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||||
|
|
||||||
cipher.formatOutputStringEncode();
|
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(1)).debug("Formatting output string to match input string");
|
||||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||||
verify(logger, times(2)).debug("Appending symbol to output");
|
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
|
@Test
|
||||||
public void testFormatOutputStringDecode(){
|
public void testFormatOutputStringDecode(){
|
||||||
cipher.outputString = decodedStringClean;
|
cipher.outputString = DECODED_STRING_CLEAN;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.formatOutputStringDecode();
|
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(1)).debug("Formatting output string to match input string");
|
||||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Converting output to uppercase");
|
verify(logger, times(1)).debug("Converting output to uppercase");
|
||||||
verify(logger, times(14)).debug("Converting output to lowercase");
|
verify(logger, times(14)).debug("Converting output to lowercase");
|
||||||
verify(logger, times(2)).debug("Appending symbol to output");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
|
|
||||||
cipher.encode();
|
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("Encoding using Polybius Square");
|
||||||
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
verify(logger, times(1)).debug("Replacing coordinates with letters");
|
||||||
verify(logger, times(1)).debug("Encoding using columnar");
|
verify(logger, times(1)).debug("Encoding using columnar");
|
||||||
@@ -280,13 +276,13 @@ public class ADFGXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding using columnar");
|
verify(logger, times(1)).debug("Decoding using columnar");
|
||||||
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
verify(logger, times(1)).debug("Replacing letters with coordinates");
|
||||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||||
@@ -294,25 +290,25 @@ public class ADFGXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(squareKeyword, cipher.getSquareKeyword());
|
assertEquals(SQUARE_KEYWORD, cipher.getSquareKeyword());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
PolybiusSquare polybius = cipher.polybiusSquare;
|
PolybiusSquare polybius = cipher.polybiusSquare;
|
||||||
Columnar columnar = cipher.columnar;
|
Columnar columnar = cipher.columnar;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.squareKeyword = squareKeyword;
|
cipher.squareKeyword = SQUARE_KEYWORD;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -329,47 +325,47 @@ public class ADFGXTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new ADFGX(true, true, true);
|
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(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new ADFGX(false, false, false);
|
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(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new ADFGX(true, true, true);
|
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(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new ADFGX(false, false, false);
|
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(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.exceptions;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class InvalidBaseExceptionTest{
|
public class InvalidBaseExceptionTest{
|
||||||
private static final String message = "message";
|
private static final String MESSAGE = "message";
|
||||||
private static final Throwable cause = new Exception();
|
private static final Throwable CAUSE = new Exception();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,22 +20,22 @@ public class InvalidBaseExceptionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_message(){
|
public void testConstructor_message(){
|
||||||
InvalidBaseException exception = new InvalidBaseException(message);
|
InvalidBaseException exception = new InvalidBaseException(MESSAGE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_cause(){
|
public void testConstructor_cause(){
|
||||||
InvalidBaseException exception = new InvalidBaseException(cause);
|
InvalidBaseException exception = new InvalidBaseException(CAUSE);
|
||||||
assertEquals(cause.toString(), exception.getMessage());
|
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
assertEquals(CAUSE, exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_messageAndCause(){
|
public void testConstructor_messageAndCause(){
|
||||||
InvalidBaseException exception = new InvalidBaseException(message, cause);
|
InvalidBaseException exception = new InvalidBaseException(MESSAGE, CAUSE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
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;
|
package com.mattrixwv.cipherstream.exceptions;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class InvalidCharacterExceptionTest{
|
public class InvalidCharacterExceptionTest{
|
||||||
private String message = "message";
|
private static final String MESSAGE = "message";
|
||||||
private Throwable cause = new Exception();
|
private static final Throwable CAUSE = new Exception();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,22 +20,22 @@ public class InvalidCharacterExceptionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_message(){
|
public void testConstructor_message(){
|
||||||
InvalidCharacterException exception = new InvalidCharacterException(message);
|
InvalidCharacterException exception = new InvalidCharacterException(MESSAGE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_cause(){
|
public void testConstructor_cause(){
|
||||||
InvalidCharacterException exception = new InvalidCharacterException(cause);
|
InvalidCharacterException exception = new InvalidCharacterException(CAUSE);
|
||||||
assertEquals(cause.toString(), exception.getMessage());
|
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
assertEquals(CAUSE, exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_messageAndCause(){
|
public void testConstructor_messageAndCause(){
|
||||||
InvalidCharacterException exception = new InvalidCharacterException(message, cause);
|
InvalidCharacterException exception = new InvalidCharacterException(MESSAGE, CAUSE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
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;
|
package com.mattrixwv.cipherstream.exceptions;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class InvalidInputExceptionTest{
|
public class InvalidInputExceptionTest{
|
||||||
private String message = "message";
|
private static final String MESSAGE = "message";
|
||||||
private Throwable cause = new Exception();
|
private static final Throwable CAUSE = new Exception();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,22 +20,22 @@ public class InvalidInputExceptionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_message(){
|
public void testConstructor_message(){
|
||||||
InvalidInputException exception = new InvalidInputException(message);
|
InvalidInputException exception = new InvalidInputException(MESSAGE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_cause(){
|
public void testConstructor_cause(){
|
||||||
InvalidInputException exception = new InvalidInputException(cause);
|
InvalidInputException exception = new InvalidInputException(CAUSE);
|
||||||
assertEquals(cause.toString(), exception.getMessage());
|
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
assertEquals(CAUSE, exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_messageAndCause(){
|
public void testConstructor_messageAndCause(){
|
||||||
InvalidInputException exception = new InvalidInputException(message, cause);
|
InvalidInputException exception = new InvalidInputException(MESSAGE, CAUSE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
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;
|
package com.mattrixwv.cipherstream.exceptions;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class InvalidKeyExceptionTest{
|
public class InvalidKeyExceptionTest{
|
||||||
public String message = "message";
|
public static final String MESSAGE = "message";
|
||||||
public Throwable cause = new Exception();
|
public static final Throwable CAUSE = new Exception();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,22 +20,22 @@ public class InvalidKeyExceptionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_message(){
|
public void testConstructor_message(){
|
||||||
InvalidKeyException exception = new InvalidKeyException(message);
|
InvalidKeyException exception = new InvalidKeyException(MESSAGE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_cause(){
|
public void testConstructor_cause(){
|
||||||
InvalidKeyException exception = new InvalidKeyException(cause);
|
InvalidKeyException exception = new InvalidKeyException(CAUSE);
|
||||||
assertEquals(cause.toString(), exception.getMessage());
|
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
assertEquals(CAUSE, exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_messageAndCause(){
|
public void testConstructor_messageAndCause(){
|
||||||
InvalidKeyException exception = new InvalidKeyException(message, cause);
|
InvalidKeyException exception = new InvalidKeyException(MESSAGE, CAUSE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
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;
|
package com.mattrixwv.cipherstream.exceptions;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class InvalidKeywordExceptionTest{
|
public class InvalidKeywordExceptionTest{
|
||||||
private String message = "message";
|
private static final String MESSAGE = "message";
|
||||||
private Throwable cause = new Exception();
|
private static final Throwable CAUSE = new Exception();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,22 +20,22 @@ public class InvalidKeywordExceptionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_message(){
|
public void testConstructor_message(){
|
||||||
InvalidKeywordException exception = new InvalidKeywordException(message);
|
InvalidKeywordException exception = new InvalidKeywordException(MESSAGE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_cause(){
|
public void testConstructor_cause(){
|
||||||
InvalidKeywordException exception = new InvalidKeywordException(cause);
|
InvalidKeywordException exception = new InvalidKeywordException(CAUSE);
|
||||||
assertEquals(cause.toString(), exception.getMessage());
|
assertEquals(CAUSE.toString(), exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
assertEquals(CAUSE, exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor_messageAndCause(){
|
public void testConstructor_messageAndCause(){
|
||||||
InvalidKeywordException exception = new InvalidKeywordException(message, cause);
|
InvalidKeywordException exception = new InvalidKeywordException(MESSAGE, CAUSE);
|
||||||
assertEquals(message, exception.getMessage());
|
assertEquals(MESSAGE, exception.getMessage());
|
||||||
assertEquals(cause, exception.getCause());
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +23,12 @@ public class AffineTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "MEssage to^encode";
|
private static final String DECODED_STRING = "MEssage to^encode";
|
||||||
private static final String decodedStringClean = "messagetoencode";
|
private static final String DECODED_STRING_CLEAN = "messagetoencode";
|
||||||
private static final String encodedString = "PBtthlb yz^burzwb";
|
private static final String ENCODED_STRING = "PBtthlb yz^burzwb";
|
||||||
private static final String encodedStringClean = "pbtthlbyzburzwb";
|
private static final String ENCODED_STRING_CLEAN = "pbtthlbyzburzwb";
|
||||||
private static final int key1 = 5;
|
private static final int KEY_1 = 5;
|
||||||
private static final int key2 = 7;
|
private static final int KEY_2 = 7;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -89,11 +85,11 @@ public class AffineTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKey1(){
|
public void testKey1(){
|
||||||
cipher.setKey1(key1);
|
cipher.setKey1(KEY_1);
|
||||||
|
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
verify(logger, times(1)).debug("Setting key1 {}", key1);
|
verify(logger, times(1)).debug("Setting key1 {}", KEY_1);
|
||||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
verify(logger, times(1)).debug("Cleaned key1 {}", KEY_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -117,20 +113,20 @@ public class AffineTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKey1_large(){
|
public void testSetKey1_large(){
|
||||||
cipher.setKey1(key1 + 26);
|
cipher.setKey1(KEY_1 + 26);
|
||||||
|
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
verify(logger, times(1)).debug("Setting key1 {}", key1 + 26);
|
verify(logger, times(1)).debug("Setting key1 {}", KEY_1 + 26);
|
||||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
verify(logger, times(1)).debug("Cleaned key1 {}", KEY_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKey2(){
|
public void testSetKey2(){
|
||||||
cipher.setKey2(key2);
|
cipher.setKey2(KEY_2);
|
||||||
|
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
verify(logger, times(1)).debug("Setting key2 {}", key2);
|
verify(logger, times(1)).debug("Setting key2 {}", KEY_2);
|
||||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
verify(logger, times(1)).debug("Cleaned key2 {}", KEY_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,11 +140,11 @@ public class AffineTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKey2_large(){
|
public void testSetKey2_large(){
|
||||||
cipher.setKey2(key2 + 26);
|
cipher.setKey2(KEY_2 + 26);
|
||||||
|
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
verify(logger, times(1)).debug("Setting key2 {}", key2 + 26);
|
verify(logger, times(1)).debug("Setting key2 {}", KEY_2 + 26);
|
||||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
verify(logger, times(1)).debug("Cleaned key2 {}", KEY_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,14 +153,14 @@ public class AffineTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -173,14 +169,14 @@ public class AffineTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toLowerCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toLowerCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -189,14 +185,14 @@ public class AffineTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing sybols");
|
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
|
@Test
|
||||||
@@ -205,14 +201,14 @@ public class AffineTest{
|
|||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -256,17 +252,17 @@ public class AffineTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.key1 = key1;
|
cipher.key1 = KEY_1;
|
||||||
cipher.key2 = key2;
|
cipher.key2 = KEY_2;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
||||||
verify(logger, times(15)).debug(eq("Encoded 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
|
@Test
|
||||||
@@ -274,39 +270,39 @@ public class AffineTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.key1 = key1;
|
cipher.key1 = KEY_1;
|
||||||
cipher.key2 = key2;
|
cipher.key2 = KEY_2;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Key1 inverse {}", 21);
|
verify(logger, times(1)).debug("Key1 inverse {}", 21);
|
||||||
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Current char {}"), anyChar());
|
||||||
verify(logger, times(15)).debug(eq("Decoded 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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.key1 = key1;
|
cipher.key1 = KEY_1;
|
||||||
cipher.key2 = key2;
|
cipher.key2 = KEY_2;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(key1, cipher.getKey1());
|
assertEquals(KEY_1, cipher.getKey1());
|
||||||
assertEquals(key2, cipher.getKey2());
|
assertEquals(KEY_2, cipher.getKey2());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.key1 = key1;
|
cipher.key1 = KEY_1;
|
||||||
cipher.key2 = key2;
|
cipher.key2 = KEY_2;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -321,51 +317,51 @@ public class AffineTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Affine(true, true, true);
|
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(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Affine(false, false, false);
|
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(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Affine(true, true, true);
|
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(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testpracticalDecoding_clean(){
|
public void testpracticalDecoding_clean(){
|
||||||
cipher = new Affine(false, false, false);
|
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(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(key1, cipher.key1);
|
assertEquals(KEY_1, cipher.key1);
|
||||||
assertEquals(key2, cipher.key2);
|
assertEquals(KEY_2, cipher.key2);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,10 +22,10 @@ public class AtbashTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Nvhhztv gl^vmxlwv";
|
private static final String ENCODED_STRING = "Nvhhztv gl^vmxlwv";
|
||||||
private static final String encodedStringClean = "NVHHZTVGLVMXLWV";
|
private static final String ENCODED_STRING_CLEAN = "NVHHZTVGLVMXLWV";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,17 +74,17 @@ public class AtbashTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(17)).debug(eq("Encoding char {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Encoding char {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(2)).debug("Appending symbol");
|
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
|
@Test
|
||||||
@@ -97,14 +93,14 @@ public class AtbashTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -113,14 +109,14 @@ public class AtbashTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -129,14 +125,14 @@ public class AtbashTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -145,14 +141,14 @@ public class AtbashTest{
|
|||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -178,7 +174,7 @@ public class AtbashTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputString("");
|
cipher.setInputString("");
|
||||||
@@ -194,17 +190,17 @@ public class AtbashTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -217,43 +213,43 @@ public class AtbashTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Atbash(true, true, true);
|
cipher = new Atbash(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(decodedString);
|
String output = cipher.encode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Atbash(false, false, false);
|
cipher = new Atbash(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(decodedString);
|
String output = cipher.encode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Atbash(true, true, true);
|
cipher = new Atbash(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(encodedString);
|
String output = cipher.decode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Atbash(false, false, false);
|
cipher = new Atbash(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(encodedString);
|
String output = cipher.decode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +23,12 @@ public class AutokeyTest{
|
|||||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.Autokey")
|
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.Autokey")
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "MeSsage to^encode";
|
private static final String DECODED_STRING = "MeSsage to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "WiQooxh fs^wfcuhx";
|
private static final String ENCODED_STRING = "WiQooxh fs^wfcuhx";
|
||||||
private static final String encodedStringClean = "WIQOOXHFSWFCUHX";
|
private static final String ENCODED_STRING_CLEAN = "WIQOOXHFSWFCUHX";
|
||||||
private static final String keyword = "keyword";
|
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 ArrayList<Integer> OFFSET = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3, 12, 4, 18, 18, 0, 6, 4, 19));
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,11 +89,11 @@ public class AutokeyTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.encodeSet(keyword, decodedString);
|
cipher.encodeSet(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals((keyword + decodedString.replaceAll("\\s", "").replaceAll("[^a-zA-Z\\s]", "").substring(0, 8)).toUpperCase(), cipher.keyword);
|
assertEquals((KEYWORD + DECODED_STRING.replaceAll("\\s", "").replaceAll("[^a-zA-Z\\s]", "").substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(OFFSET, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Setting fields for encoding");
|
verify(logger, times(1)).debug("Setting fields for encoding");
|
||||||
verify(logger, times(1)).debug("Setting keyword");
|
verify(logger, times(1)).debug("Setting keyword");
|
||||||
verify(logger, times(1)).debug("Adding input to keyword");
|
verify(logger, times(1)).debug("Adding input to keyword");
|
||||||
@@ -110,10 +106,10 @@ public class AutokeyTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.decodeSet(keyword, decodedString);
|
cipher.decodeSet(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting fields for decoding");
|
verify(logger, times(1)).debug("Setting fields for decoding");
|
||||||
verify(logger, times(1)).debug("Setting keyword");
|
verify(logger, times(1)).debug("Setting keyword");
|
||||||
verify(logger, times(1)).debug("Setting input string");
|
verify(logger, times(1)).debug("Setting input string");
|
||||||
@@ -124,11 +120,11 @@ public class AutokeyTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.decodeSet(keyword, encodedString);
|
cipher.decodeSet(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(2)).debug("Appending partial output to keyword");
|
verify(logger, times(2)).debug("Appending partial output to keyword");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
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(13)).debug("Appending lowercase");
|
||||||
verify(logger, times(3)).debug("Wrapping around to z");
|
verify(logger, times(3)).debug("Wrapping around to z");
|
||||||
verify(logger, times(17)).debug(eq("Decoded letter {}"), anyChar());
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.offset.add(1);
|
cipher.offset.add(1);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
assertEquals(new ArrayList<>(List.of(1)), cipher.getOffsets());
|
assertEquals(new ArrayList<>(List.of(1)), cipher.getOffsets());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.offset.add(1);
|
cipher.offset.add(1);
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
@@ -172,47 +168,47 @@ public class AutokeyTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Autokey(true, true, true);
|
cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals((keyword + decodedStringClean.substring(0, 8)).toUpperCase(), cipher.keyword);
|
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Autokey(false, false, false);
|
cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals((keyword + decodedStringClean.substring(0, 8)).toUpperCase(), cipher.keyword);
|
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 8)).toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Autokey(true, true, true);
|
cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals((keyword + decodedStringClean.substring(0, 14)).toUpperCase(), cipher.keyword);
|
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testpracticalDecoding_clean(){
|
public void testpracticalDecoding_clean(){
|
||||||
cipher = new Autokey(false, false, false);
|
cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals((keyword + decodedStringClean.substring(0, 14)).toUpperCase(), cipher.keyword);
|
assertEquals((KEYWORD + DECODED_STRING_CLEAN.substring(0, 14)).toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,10 +23,10 @@ public class BaconianTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to-encode";
|
private static final String DECODED_STRING = "Message to-encode";
|
||||||
private static final String decodedStringClean = "Messagetoencode";
|
private static final String DECODED_STRING_CLEAN = "Messagetoencode";
|
||||||
private static final String decodedStringCleanLower = "messagetoencode";
|
private static final String DECODED_STRING_CLEAN_LOWER = "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 ENCODED_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -55,24 +51,24 @@ public class BaconianTest{
|
|||||||
public void testSetInputStringEncode(){
|
public void testSetInputStringEncode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
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
|
@Test
|
||||||
public void testSetInputStringEncode_noCapitals(){
|
public void testSetInputStringEncode_noCapitals(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringCleanLower, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
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
|
@Test
|
||||||
@@ -107,30 +103,30 @@ public class BaconianTest{
|
|||||||
public void testSetInputStringDecode(){
|
public void testSetInputStringDecode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
|
|
||||||
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 '{}'", encodedString);
|
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Ensuring all 'letters' contain 5 characters");
|
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(eq("Current 'letter' {}"), anyString());
|
||||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
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
|
@Test
|
||||||
public void testSetInputStringDecode_noCapitals(){
|
public void testSetInputStringDecode_noCapitals(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
cipher.setInputStringDecode(encodedString);
|
cipher.setInputStringDecode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
verify(logger, times(1)).debug("Setting input string for decoding '{}'", ENCODED_STRING);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Ensuring all 'letters' contain 5 characters");
|
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(eq("Current 'letter' {}"), anyString());
|
||||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
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
|
@Test
|
||||||
@@ -204,49 +200,49 @@ public class BaconianTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = decodedStringClean;
|
cipher.inputString = DECODED_STRING_CLEAN;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(15)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(15)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(15)).debug(eq("Output letter {}"), anyString());
|
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
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(15)).debug(eq("Working letter {}"), anyString());
|
verify(logger, times(15)).debug(eq("Working letter {}"), anyString());
|
||||||
verify(logger, times(15)).debug(eq("Location of letter {}"), anyInt());
|
verify(logger, times(15)).debug(eq("Location of letter {}"), anyInt());
|
||||||
verify(logger, times(1)).debug("Decoding uppercase");
|
verify(logger, times(1)).debug("Decoding uppercase");
|
||||||
verify(logger, times(14)).debug("Decoding lowercase");
|
verify(logger, times(14)).debug("Decoding lowercase");
|
||||||
verify(logger, times(15)).debug(eq("Decoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -259,65 +255,65 @@ public class BaconianTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
|
|
||||||
String output = cipher.encode(decodedString);
|
String output = cipher.encode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
String output = cipher.encode(decodedString);
|
String output = cipher.encode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringCleanLower, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.inputString);
|
||||||
assertEquals(encodedString.toLowerCase(), cipher.outputString);
|
assertEquals(ENCODED_STRING.toLowerCase(), cipher.outputString);
|
||||||
assertEquals(encodedString.toLowerCase(), output);
|
assertEquals(ENCODED_STRING.toLowerCase(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
|
|
||||||
String output = cipher.decode(encodedString);
|
String output = cipher.decode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
String output = cipher.decode(encodedString);
|
String output = cipher.decode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||||
assertEquals(decodedStringCleanLower, output);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_upper(){
|
public void testPracticalDecoding_upper(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
String output = cipher.decode(encodedString.toUpperCase());
|
String output = cipher.decode(ENCODED_STRING.toUpperCase());
|
||||||
|
|
||||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||||
assertEquals(decodedStringCleanLower, output);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_lower(){
|
public void testPracticalDecoding_lower(){
|
||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
|
|
||||||
String output = cipher.decode(encodedString.toLowerCase());
|
String output = cipher.decode(ENCODED_STRING.toLowerCase());
|
||||||
|
|
||||||
assertEquals(encodedString.toLowerCase(), cipher.inputString);
|
assertEquals(ENCODED_STRING.toLowerCase(), cipher.inputString);
|
||||||
assertEquals(decodedStringCleanLower, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN_LOWER, cipher.outputString);
|
||||||
assertEquals(decodedStringCleanLower, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -28,11 +24,11 @@ public class BaseXTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "A+B@C d\te\nf";
|
private static final String DECODED_STRING = "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 ENCODED_STRING_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 ENCODED_STRING_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 ENCODED_STRING_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 ENCODED_STRING_16 = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -55,10 +51,10 @@ public class BaseXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInputStringEncode(){
|
public void testSetInputStringEncode(){
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
verify(logger, times(1)).debug("Setting input string for encoding '{}'", DECODED_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,7 +74,7 @@ public class BaseXTest{
|
|||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
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(), anyString());
|
||||||
verify(logger, never()).debug(anyString());
|
verify(logger, never()).debug(anyString());
|
||||||
}
|
}
|
||||||
@@ -87,14 +83,14 @@ public class BaseXTest{
|
|||||||
public void testSetInputStringDecode(){
|
public void testSetInputStringDecode(){
|
||||||
cipher.base = 16;
|
cipher.base = 16;
|
||||||
|
|
||||||
cipher.setInputStringDecode(encodedString_16);
|
cipher.setInputStringDecode(ENCODED_STRING_16);
|
||||||
|
|
||||||
assertEquals(encodedString_16, cipher.inputString);
|
assertEquals(ENCODED_STRING_16, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString_16);
|
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(1)).debug("Creating string of valid 'numbers'");
|
||||||
verify(logger, times(16)).debug(eq("Current number {}, converted {}"), anyInt(), anyString());
|
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("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
|
@Test
|
||||||
@@ -176,29 +172,29 @@ public class BaseXTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.base = 16;
|
cipher.base = 16;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString_16, cipher.outputString);
|
assertEquals(ENCODED_STRING_16, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(11)).debug(eq("Working number {}"), anyChar());
|
verify(logger, times(11)).debug(eq("Working number {}"), anyChar());
|
||||||
verify(logger, times(11)).debug(eq("Converted number {}"), anyString());
|
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
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.base = 16;
|
cipher.base = 16;
|
||||||
cipher.inputString = encodedString_16;
|
cipher.inputString = ENCODED_STRING_16;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(11)).debug(eq("Current number {}"), anyString());
|
verify(logger, times(11)).debug(eq("Current number {}"), anyString());
|
||||||
verify(logger, times(11)).debug(eq("Decoded number {}"), anyInt());
|
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
|
@Test
|
||||||
@@ -218,19 +214,19 @@ public class BaseXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString_2;
|
cipher.outputString = ENCODED_STRING_2;
|
||||||
cipher.base = 8;
|
cipher.base = 8;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString_2, cipher.getOutputString());
|
assertEquals(ENCODED_STRING_2, cipher.getOutputString());
|
||||||
assertEquals(8, cipher.getBase());
|
assertEquals(8, cipher.getBase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString_2;
|
cipher.outputString = ENCODED_STRING_2;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -241,101 +237,101 @@ public class BaseXTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_2(){
|
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(2, cipher.base);
|
||||||
assertEquals(encodedString_2, cipher.outputString);
|
assertEquals(ENCODED_STRING_2, cipher.outputString);
|
||||||
assertEquals(encodedString_2, output);
|
assertEquals(ENCODED_STRING_2, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_8(){
|
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(8, cipher.base);
|
||||||
assertEquals(encodedString_8, cipher.outputString);
|
assertEquals(ENCODED_STRING_8, cipher.outputString);
|
||||||
assertEquals(encodedString_8, output);
|
assertEquals(ENCODED_STRING_8, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_10(){
|
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(10, cipher.base);
|
||||||
assertEquals(encodedString_10, cipher.outputString);
|
assertEquals(ENCODED_STRING_10, cipher.outputString);
|
||||||
assertEquals(encodedString_10, output);
|
assertEquals(ENCODED_STRING_10, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_16(){
|
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(16, cipher.base);
|
||||||
assertEquals(encodedString_16, cipher.outputString);
|
assertEquals(ENCODED_STRING_16, cipher.outputString);
|
||||||
assertEquals(encodedString_16, output);
|
assertEquals(ENCODED_STRING_16, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_inputOnly(){
|
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(2, cipher.base);
|
||||||
assertEquals(encodedString_2, cipher.outputString);
|
assertEquals(ENCODED_STRING_2, cipher.outputString);
|
||||||
assertEquals(encodedString_2, output);
|
assertEquals(ENCODED_STRING_2, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_2(){
|
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(2, cipher.base);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_8(){
|
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(8, cipher.base);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_10(){
|
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(10, cipher.base);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_16(){
|
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(16, cipher.base);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_inputOnly(){
|
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(2, cipher.base);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +23,12 @@ public class BeaufortTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Yageolz rq^ujmdag";
|
private static final String ENCODED_STRING = "Yageolz rq^ujmdag";
|
||||||
private static final String encodedStringClean = "YAGEOLZRQUJMDAG";
|
private static final String ENCODED_STRING_CLEAN = "YAGEOLZRQUJMDAG";
|
||||||
private static final String keyword = "Ke*y word";
|
private static final String KEYWORD = "Ke*y word";
|
||||||
private static final String keywordClean = "KEYWORD";
|
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,14 +121,14 @@ public class BeaufortTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -141,14 +137,14 @@ public class BeaufortTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -157,14 +153,14 @@ public class BeaufortTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -173,14 +169,14 @@ public class BeaufortTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -217,13 +213,13 @@ public class BeaufortTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.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 case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letters");
|
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
|
@Test
|
||||||
@@ -268,51 +264,51 @@ public class BeaufortTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher = new Beaufort(true, true, true);
|
cipher = new Beaufort(true, true, true);
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Encoding with Atbash");
|
verify(logger, times(1)).debug("Encoding with Atbash");
|
||||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
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
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher = new Beaufort(true, true, true);
|
cipher = new Beaufort(true, true, true);
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Encoding with Atbash");
|
verify(logger, times(1)).debug("Encoding with Atbash");
|
||||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -325,43 +321,43 @@ public class BeaufortTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Beaufort(true, true, true);
|
cipher = new Beaufort(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Beaufort(false, false, false);
|
cipher = new Beaufort(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Beaufort(true, true, true);
|
cipher = new Beaufort(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Beaufort(false, false, false);
|
cipher = new Beaufort(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,11 +22,11 @@ public class CaesarTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "The quick brown fox jumps over - the lAzy dog";
|
private static final String DECODED_STRING = "The quick brown fox jumps over - the lAzy dog";
|
||||||
private static final String decodedStringClean = "thequickbrownfoxjumpsoverthelazydog";
|
private static final String DECODED_STRING_CLEAN = "thequickbrownfoxjumpsoverthelazydog";
|
||||||
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
|
private static final String ENCODED_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
|
||||||
private static final String encodedStringClean = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
private static final String ENCODED_STRING_CLEAN = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
||||||
private static final int shift = 23;
|
private static final int SHIFT = 23;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,29 +79,29 @@ public class CaesarTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetShift(){
|
public void testSetShift(){
|
||||||
cipher.setShift(shift);
|
cipher.setShift(SHIFT);
|
||||||
|
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
verify(logger, times(1)).debug("Setting shift {}", shift);
|
verify(logger, times(1)).debug("Setting shift {}", SHIFT);
|
||||||
verify(logger, times(1)).debug("Cleaned shift {}", shift);
|
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetShift_large(){
|
public void testSetShift_large(){
|
||||||
cipher.setShift(shift + 26);
|
cipher.setShift(SHIFT + 26);
|
||||||
|
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
verify(logger, times(1)).debug("Setting shift {}", shift + 26);
|
verify(logger, times(1)).debug("Setting shift {}", SHIFT + 26);
|
||||||
verify(logger, times(1)).debug("Cleaned shift {}", shift);
|
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetShift_negative(){
|
public void testSetShift_negative(){
|
||||||
cipher.setShift(shift - 26);
|
cipher.setShift(SHIFT - 26);
|
||||||
|
|
||||||
assertEquals(shift - 26, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
verify(logger, times(1)).debug("Setting shift {}", shift - 26);
|
verify(logger, times(1)).debug("Setting shift {}", SHIFT - 26);
|
||||||
verify(logger, times(1)).debug("Cleaned shift {}", shift - 26);
|
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,14 +110,14 @@ public class CaesarTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -130,14 +126,14 @@ public class CaesarTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toLowerCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toLowerCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -146,14 +142,14 @@ public class CaesarTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -162,14 +158,14 @@ public class CaesarTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -210,12 +206,12 @@ public class CaesarTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.shift = shift;
|
cipher.shift = SHIFT;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Encoding uppercase");
|
verify(logger, times(2)).debug("Encoding uppercase");
|
||||||
@@ -225,17 +221,17 @@ public class CaesarTest{
|
|||||||
verify(logger, never()).debug("Wrapping around to z");
|
verify(logger, never()).debug("Wrapping around to z");
|
||||||
verify(logger, times(31)).debug("Wrapping around to a");
|
verify(logger, times(31)).debug("Wrapping around to a");
|
||||||
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testEncode_negative(){
|
public void testEncode_negative(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.shift = shift - 26;
|
cipher.shift = SHIFT - 26;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Encoding uppercase");
|
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, times(2)).debug("Wrapping around to z");
|
||||||
verify(logger, never()).debug("Wrapping around to a");
|
verify(logger, never()).debug("Wrapping around to a");
|
||||||
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.shift = shift;
|
cipher.shift = SHIFT;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Decoding uppercase");
|
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, times(31)).debug("Wrapping around to z");
|
||||||
verify(logger, never()).debug("Wrapping around to a");
|
verify(logger, never()).debug("Wrapping around to a");
|
||||||
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testDecode_negative(){
|
public void testDecode_negative(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.shift = shift - 26;
|
cipher.shift = SHIFT - 26;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Decoding uppercase");
|
verify(logger, times(2)).debug("Decoding uppercase");
|
||||||
@@ -285,25 +281,25 @@ public class CaesarTest{
|
|||||||
verify(logger, never()).debug("Wrapping around to z");
|
verify(logger, never()).debug("Wrapping around to z");
|
||||||
verify(logger, times(2)).debug("Wrapping around to a");
|
verify(logger, times(2)).debug("Wrapping around to a");
|
||||||
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.shift = shift;
|
cipher.shift = SHIFT;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(shift, cipher.getShift());
|
assertEquals(SHIFT, cipher.getShift());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.shift = shift;
|
cipher.shift = SHIFT;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -317,70 +313,70 @@ public class CaesarTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Caesar(true, true, true);
|
cipher = new Caesar(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(shift, decodedString);
|
String output = cipher.encode(SHIFT, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Caesar(false, false, false);
|
cipher = new Caesar(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(shift, decodedString);
|
String output = cipher.encode(SHIFT, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_negative(){
|
public void testPracticalEncoding_negative(){
|
||||||
cipher = new Caesar(true, true, true);
|
cipher = new Caesar(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(shift, decodedString);
|
String output = cipher.encode(-3, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Caesar(true, true, true);
|
cipher = new Caesar(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(shift, encodedString);
|
String output = cipher.decode(SHIFT, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Caesar(false, false, false);
|
cipher = new Caesar(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(shift, encodedString);
|
String output = cipher.decode(SHIFT, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(shift, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_negative(){
|
public void testPracticalDecoding_negative(){
|
||||||
cipher = new Caesar(true, true, true);
|
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(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(shift - 26, cipher.shift);
|
assertEquals(SHIFT, cipher.shift);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,12 +25,12 @@ public class OneTimePadTest{
|
|||||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.OneTimePad")
|
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.OneTimePad")
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Wiqooxh mv^egkgws";
|
private static final String ENCODED_STRING = "Wiqooxh mv^egkgws";
|
||||||
private static final String encodedStringClean = "WIQOOXHMVEGKGWS";
|
private static final String ENCODED_STRING_CLEAN = "WIQOOXHMVEGKGWS";
|
||||||
private static final String keyword = "keywordThatIsTotallyRandom";
|
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 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
|
@Test
|
||||||
@@ -95,13 +91,13 @@ public class OneTimePadTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(OFFSET, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +107,13 @@ public class OneTimePadTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(OFFSET, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +124,7 @@ public class OneTimePadTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
assertThrows(InvalidKeywordException.class, () -> {
|
assertThrows(InvalidKeywordException.class, () -> {
|
||||||
cipher.encode("keyword", decodedString);
|
cipher.encode("keyword", DECODED_STRING);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
assertEquals("", cipher.inputString);
|
||||||
@@ -144,13 +140,13 @@ public class OneTimePadTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(OFFSET, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,20 +156,20 @@ public class OneTimePadTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(OFFSET, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode_short(){
|
public void testDecode_short(){
|
||||||
assertThrows(InvalidKeywordException.class, () -> {
|
assertThrows(InvalidKeywordException.class, () -> {
|
||||||
cipher.decode("keyword", encodedString);
|
cipher.decode("keyword", ENCODED_STRING);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
assertEquals("", cipher.inputString);
|
||||||
@@ -187,47 +183,47 @@ public class OneTimePadTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new OneTimePad(true, true, true);
|
cipher = new OneTimePad(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new OneTimePad(false, false, false);
|
cipher = new OneTimePad(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new OneTimePad(true, true, true);
|
cipher = new OneTimePad(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new OneTimePad(false, false, false);
|
cipher = new OneTimePad(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +23,12 @@ public class PortaTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Rtghuos bm^qcwgrw";
|
private static final String ENCODED_STRING = "Rtghuos bm^qcwgrw";
|
||||||
private static final String encodedStringClean = "RTGHUOSBMQCWGRW";
|
private static final String ENCODED_STRING_CLEAN = "RTGHUOSBMQCWGRW";
|
||||||
private static final String keyword = "keyword";
|
private static final String KEYWORD = "keyword";
|
||||||
private static final String keywordDirty = "Ke yw*ord";
|
private static final String KEYWORD_DIRTY = "Ke yw*ord";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -85,24 +81,24 @@ public class PortaTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.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 case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letters");
|
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
|
@Test
|
||||||
public void testSetKeyword_dirty(){
|
public void testSetKeyword_dirty(){
|
||||||
cipher.setKeyword(keywordDirty);
|
cipher.setKeyword(KEYWORD_DIRTY);
|
||||||
|
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Original keyword '{}'", keywordDirty);
|
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD_DIRTY);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letters");
|
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
|
@Test
|
||||||
@@ -148,11 +144,11 @@ public class PortaTest{
|
|||||||
public void testSetKeyword_symbols(){
|
public void testSetKeyword_symbols(){
|
||||||
cipher.setKeyword("key*word^");
|
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("Original keyword '{}'", "key*word^");
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letters");
|
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
|
@Test
|
||||||
@@ -161,14 +157,14 @@ public class PortaTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -177,14 +173,14 @@ public class PortaTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -193,14 +189,14 @@ public class PortaTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -209,14 +205,14 @@ public class PortaTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -639,18 +635,18 @@ public class PortaTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keyword.toUpperCase();
|
cipher.keyword = KEYWORD.toUpperCase();
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(17)).debug(eq("Encoded letter {}"), anyChar());
|
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
|
@Test
|
||||||
@@ -658,36 +654,36 @@ public class PortaTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keyword.toUpperCase();
|
cipher.keyword = KEYWORD.toUpperCase();
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(17)).debug(eq("Encoded letter {}"), anyChar());
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRest(){
|
public void testRest(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -700,47 +696,47 @@ public class PortaTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Porta(true, true, true);
|
cipher = new Porta(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Porta(false, false, false);
|
cipher = new Porta(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Porta(true, true, true);
|
cipher = new Porta(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Porta(false, false, false);
|
cipher = new Porta(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,18 +23,18 @@ public class SubstitutionTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String decodedStringAlNum = "Message to^encode 123";
|
private static final String DECODED_STRING_AL_NUM = "Message to^encode 123";
|
||||||
private static final String decodedStringAlNumClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_AL_NUM_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Oguucig vq^gpeqfg";
|
private static final String ENCODED_STRING = "Oguucig vq^gpeqfg";
|
||||||
private static final String encodedStringClean = "OGUUCIGVQGPEQFG";
|
private static final String ENCODED_STRING_CLEAN = "OGUUCIGVQGPEQFG";
|
||||||
private static final String encodedStringAlNum = "Oguucig vq^gpeqfg 876";
|
private static final String ENCODED_STRING_AL_NUM = "Oguucig vq^gpeqfg 876";
|
||||||
private static final String encodedStringAlNumClean = "OGUUCIGVQGPEQFG";
|
private static final String ENCODED_STRING_AL_NUM_CLEAN = "OGUUCIGVQGPEQFG";
|
||||||
private static final String keyword = "cdefghijklmnopqrstuvwxyzab";
|
private static final String KEYWORD = "cdefghijklmnopqrstuvwxyzab";
|
||||||
private static final String keywordClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB";
|
private static final String KEYWORD_CLEAN = "CDEFGHIJKLMNOPQRSTUVWXYZAB";
|
||||||
private static final String keywordAlNum = "cdefghijklmnopqrstuvwxyzab9876543210";
|
private static final String KEYWORD_AL_NUM = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||||
private static final String keywordAlNumClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB9876543210";
|
private static final String KEYWORD_AL_NUM_CLEAN = "CDEFGHIJKLMNOPQRSTUVWXYZAB9876543210";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -91,28 +87,28 @@ public class SubstitutionTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Original key '{}'", keyword);
|
verify(logger, times(1)).debug("Original key '{}'", KEYWORD);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
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 no duplicate mappings");
|
||||||
verify(logger, times(1)).debug("Ensuring there are only letters in the key");
|
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, 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
|
@Test
|
||||||
public void testSetKeyword_alNum(){
|
public void testSetKeyword_alNum(){
|
||||||
cipher.setKeyword(keywordAlNum);
|
cipher.setKeyword(KEYWORD_AL_NUM);
|
||||||
|
|
||||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Original key '{}'", keywordAlNum);
|
verify(logger, times(1)).debug("Original key '{}'", KEYWORD_AL_NUM);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
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 no duplicate mappings");
|
||||||
verify(logger, never()).debug("Ensuring there are only letters in the key");
|
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("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
|
@Test
|
||||||
@@ -196,14 +192,14 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -212,14 +208,14 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -228,14 +224,14 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -244,14 +240,14 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -295,19 +291,19 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.inputString = decodedStringAlNum;
|
cipher.inputString = DECODED_STRING_AL_NUM;
|
||||||
cipher.keyword = keywordAlNumClean;
|
cipher.keyword = KEYWORD_AL_NUM_CLEAN;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedStringAlNum, cipher.outputString);
|
assertEquals(ENCODED_STRING_AL_NUM, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(3)).debug("Encoding digit");
|
verify(logger, times(3)).debug("Encoding digit");
|
||||||
verify(logger, times(3)).debug("Passing symbol through");
|
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
|
@Test
|
||||||
@@ -315,37 +311,37 @@ public class SubstitutionTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.inputString = encodedStringAlNum;
|
cipher.inputString = ENCODED_STRING_AL_NUM;
|
||||||
cipher.keyword = keywordAlNumClean;
|
cipher.keyword = KEYWORD_AL_NUM_CLEAN;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedStringAlNum, cipher.outputString);
|
assertEquals(DECODED_STRING_AL_NUM, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(21)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Encoding uppercase");
|
verify(logger, times(1)).debug("Encoding uppercase");
|
||||||
verify(logger, times(14)).debug("Encoding lowercase");
|
verify(logger, times(14)).debug("Encoding lowercase");
|
||||||
verify(logger, times(3)).debug("Encoding digit");
|
verify(logger, times(3)).debug("Encoding digit");
|
||||||
verify(logger, times(3)).debug("Passing symbol through");
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -359,119 +355,119 @@ public class SubstitutionTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Substitution(true, true, true);
|
cipher = new Substitution(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Substitution(false, false, false);
|
cipher = new Substitution(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_alNum(){
|
public void testPracticalEncoding_alNum(){
|
||||||
cipher = new Substitution(true, true, true);
|
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(DECODED_STRING_AL_NUM, cipher.inputString);
|
||||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringAlNum, cipher.outputString);
|
assertEquals(ENCODED_STRING_AL_NUM, cipher.outputString);
|
||||||
assertEquals(encodedStringAlNum, output);
|
assertEquals(ENCODED_STRING_AL_NUM, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_alNumClean(){
|
public void testPracticalEncoding_alNumClean(){
|
||||||
cipher = new Substitution(false, false, false);
|
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(DECODED_STRING_AL_NUM_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringAlNumClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_AL_NUM_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringAlNumClean, output);
|
assertEquals(ENCODED_STRING_AL_NUM_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrecticalEncoding_noAlNumKey(){
|
public void testPrecticalEncoding_noAlNumKey(){
|
||||||
cipher = new Substitution(true, true, true);
|
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(DECODED_STRING_AL_NUM, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString + " 123", cipher.outputString);
|
assertEquals(ENCODED_STRING + " 123", cipher.outputString);
|
||||||
assertEquals(encodedString + " 123", output);
|
assertEquals(ENCODED_STRING + " 123", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Substitution(true, true, true);
|
cipher = new Substitution(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Substitution(false, false, false);
|
cipher = new Substitution(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_alNum(){
|
public void testPracticalDecoding_alNum(){
|
||||||
cipher = new Substitution(true, true, true);
|
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(ENCODED_STRING_AL_NUM, cipher.inputString);
|
||||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringAlNum, cipher.outputString);
|
assertEquals(DECODED_STRING_AL_NUM, cipher.outputString);
|
||||||
assertEquals(decodedStringAlNum, output);
|
assertEquals(DECODED_STRING_AL_NUM, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_alNumClean(){
|
public void testPracticalDecoding_alNumClean(){
|
||||||
cipher = new Substitution(false, false, false);
|
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(ENCODED_STRING_AL_NUM_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
assertEquals(KEYWORD_AL_NUM_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringAlNumClean, cipher.outputString);
|
assertEquals(DECODED_STRING_AL_NUM_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringAlNumClean, output);
|
assertEquals(DECODED_STRING_AL_NUM_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_noAlNumKey(){
|
public void testPracticalDecoding_noAlNumKey(){
|
||||||
cipher = new Substitution(true, true, true);
|
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(ENCODED_STRING + " 123", cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString + " 123", cipher.outputString);
|
assertEquals(DECODED_STRING + " 123", cipher.outputString);
|
||||||
assertEquals(decodedString + " 123", output);
|
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;
|
package com.mattrixwv.cipherstream.monosubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -12,6 +8,7 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
@@ -30,13 +27,19 @@ public class VigenereTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String inputString = "MeSsage to^encode";
|
private static final String INPUT_STRING = "MeSsage to^encode";
|
||||||
private static final String inputStringClean = "MESSAGETOENCODE";
|
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String outputString = "WiQooxh ds^cjqfgo";
|
private static final String OUTPUT_STRING = "WiQooxh ds^cjqfgo";
|
||||||
private static final String outputStringClean = "WIQOOXHDSCJQFGO";
|
private static final String OUTPUT_STRING_CLEAN = "WIQOOXHDSCJQFGO";
|
||||||
private static final String keyword = "ke yw*ord";
|
private static final String KEYWORD = "ke yw*ord";
|
||||||
private static final String keywordClean = "KEYWORD";
|
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||||
private ArrayList<Integer> offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3));
|
private ArrayList<Integer> offset;
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup(){
|
||||||
|
offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,11 +96,11 @@ public class VigenereTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetOffset(){
|
public void testSetOffset(){
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.setOffset();
|
cipher.setOffset();
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(offset, cipher.offset);
|
||||||
verify(logger, times(1)).debug("Setting offset array from keyword");
|
verify(logger, times(1)).debug("Setting offset array from keyword");
|
||||||
verify(logger, times(1)).debug("Offset {}", offset);
|
verify(logger, times(1)).debug("Offset {}", offset);
|
||||||
@@ -108,17 +111,17 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString, cipher.inputString);
|
assertEquals(INPUT_STRING, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -126,17 +129,17 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
assertEquals(INPUT_STRING.toUpperCase(), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -144,17 +147,17 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(INPUT_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -162,17 +165,17 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -180,7 +183,7 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -200,7 +203,7 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -217,14 +220,14 @@ public class VigenereTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
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 case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
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
|
@Test
|
||||||
@@ -260,13 +263,13 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Encoding uppercase");
|
verify(logger, times(2)).debug("Encoding uppercase");
|
||||||
@@ -274,7 +277,7 @@ public class VigenereTest{
|
|||||||
verify(logger, times(13)).debug("Encoding lowercase");
|
verify(logger, times(13)).debug("Encoding lowercase");
|
||||||
verify(logger, times(5)).debug("Wrapping around to a");
|
verify(logger, times(5)).debug("Wrapping around to a");
|
||||||
verify(logger, times(17)).debug(eq("Encoded character {}"), anyChar());
|
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
|
@Test
|
||||||
@@ -282,13 +285,13 @@ public class VigenereTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.inputString = outputString;
|
cipher.inputString = OUTPUT_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(inputString, cipher.outputString);
|
assertEquals(INPUT_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(2)).debug("Decoding uppercase");
|
verify(logger, times(2)).debug("Decoding uppercase");
|
||||||
@@ -296,27 +299,27 @@ public class VigenereTest{
|
|||||||
verify(logger, times(13)).debug("Decoding lowercase");
|
verify(logger, times(13)).debug("Decoding lowercase");
|
||||||
verify(logger, times(5)).debug("Wrapping around to z");
|
verify(logger, times(5)).debug("Wrapping around to z");
|
||||||
verify(logger, times(17)).debug(eq("Decoded character {}"), anyChar());
|
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
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
assertEquals(inputString, cipher.getInputString());
|
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||||
assertEquals(outputString, cipher.getOutputString());
|
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
assertEquals(offset, cipher.getOffsets());
|
assertEquals(offset, cipher.getOffsets());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.offset = offset;
|
cipher.offset = offset;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
@@ -332,51 +335,51 @@ public class VigenereTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Vigenere(true, true, true);
|
cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString, cipher.inputString);
|
assertEquals(INPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(offset, cipher.offset);
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
assertEquals(outputString, output);
|
assertEquals(OUTPUT_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Vigenere(false, false, false);
|
cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputStringClean, cipher.inputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(offset, cipher.offset);
|
||||||
assertEquals(outputStringClean, cipher.outputString);
|
assertEquals(OUTPUT_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(outputStringClean, output);
|
assertEquals(OUTPUT_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Vigenere(true, true, true);
|
cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, outputString);
|
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputString, cipher.inputString);
|
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(offset, cipher.offset);
|
||||||
assertEquals(inputString, cipher.outputString);
|
assertEquals(INPUT_STRING, cipher.outputString);
|
||||||
assertEquals(inputString, output);
|
assertEquals(INPUT_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Vigenere(false, false, false);
|
cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, outputString);
|
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputStringClean, cipher.inputString);
|
assertEquals(OUTPUT_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(offset, cipher.offset);
|
assertEquals(offset, cipher.offset);
|
||||||
assertEquals(inputStringClean, cipher.outputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(inputStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +23,12 @@ public class BifidTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Test
|
//Test
|
||||||
private static final String inputString = "Message to^encode";
|
private static final String INPUT_STRING = "Message to^encode";
|
||||||
private static final String inputStringClean = "MESSAGETOENCODE";
|
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String outputString = "Mqaokne kc^vdodzd";
|
private static final String OUTPUT_STRING = "Mqaokne kc^vdodzd";
|
||||||
private static final String outputStringClean = "MQAOKNEKCVDODZD";
|
private static final String OUTPUT_STRING_CLEAN = "MQAOKNEKCVDODZD";
|
||||||
private static final String keyword = "keyword";
|
private static final String KEYWORD = "keyword";
|
||||||
private static final String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,10 +93,10 @@ public class BifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keyword, cipher.keyword);
|
assertEquals(KEYWORD, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Setting keyword '{}'", keyword);
|
verify(logger, times(1)).debug("Setting keyword '{}'", KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -118,14 +114,14 @@ public class BifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString, cipher.inputString);
|
assertEquals(INPUT_STRING, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -134,14 +130,14 @@ public class BifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
assertEquals(INPUT_STRING.toUpperCase(), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -150,14 +146,14 @@ public class BifidTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(INPUT_STRING.replaceAll("\\s", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -166,14 +162,14 @@ public class BifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(inputString);
|
cipher.setInputString(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(INPUT_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Original input string '{}'", inputString);
|
verify(logger, times(1)).debug("Original input string '{}'", INPUT_STRING);
|
||||||
verify(logger, never()).debug("Removing case");
|
verify(logger, never()).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -214,29 +210,29 @@ public class BifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatOutput(){
|
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(1)).debug("Formatting output");
|
||||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Altering uppercase");
|
verify(logger, times(1)).debug("Altering uppercase");
|
||||||
verify(logger, times(14)).debug("Altering lowercase");
|
verify(logger, times(14)).debug("Altering lowercase");
|
||||||
verify(logger, times(2)).debug("Adding symbol");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(inputString, cipher.inputString);
|
assertEquals(INPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Encoding Polybius");
|
verify(logger, times(1)).debug("Encoding Polybius");
|
||||||
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
||||||
@@ -246,14 +242,14 @@ public class BifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = outputString;
|
cipher.inputString = OUTPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(outputString, cipher.inputString);
|
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(inputString, cipher.outputString);
|
assertEquals(INPUT_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Encoding Polybius Square");
|
verify(logger, times(1)).debug("Encoding Polybius Square");
|
||||||
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
verify(logger, times(1)).debug("Splitting Polybius Square message");
|
||||||
@@ -263,20 +259,20 @@ public class BifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
|
|
||||||
assertEquals(inputString, cipher.getInputString());
|
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
assertEquals(outputString, cipher.getOutputString());
|
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -290,11 +286,11 @@ public class BifidTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Bifid(true, true, true);
|
cipher = new Bifid(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputString, cipher.inputString);
|
assertEquals(INPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
assertEquals(output, cipher.outputString);
|
assertEquals(output, cipher.outputString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,35 +298,35 @@ public class BifidTest{
|
|||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Bifid(false, false, false);
|
cipher = new Bifid(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
String output = cipher.encode(KEYWORD, INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputStringClean, cipher.inputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(outputStringClean, cipher.outputString);
|
assertEquals(OUTPUT_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(outputStringClean, output);
|
assertEquals(OUTPUT_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Bifid(true, true, true);
|
cipher = new Bifid(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, outputString);
|
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputString, cipher.inputString);
|
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(inputString, cipher.outputString);
|
assertEquals(INPUT_STRING, cipher.outputString);
|
||||||
assertEquals(inputString, output);
|
assertEquals(INPUT_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new Bifid(false, false, false);
|
cipher = new Bifid(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, outputString);
|
String output = cipher.decode(KEYWORD, OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputStringClean, cipher.inputString);
|
assertEquals(OUTPUT_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(inputStringClean, cipher.outputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(inputStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -31,16 +27,16 @@ public class ColumnarTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to*encode";
|
private static final String DECODED_STRING = "Message to*encode";
|
||||||
private static final String decodedStringPadded = "Message to*encodexxxxxx";
|
private static final String DECODED_STRING_PADDED = "Message to*encodexxxxxx";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODEXXXXXX";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODEXXXXXX";
|
||||||
private static final String encodedString = "Edeomte ac*gosnse";
|
private static final String ENCODED_STRING = "Edeomte ac*gosnse";
|
||||||
//TODO: This is a bug that needs fixed
|
//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 ENCODED_STRING_PADDING_ADDED = "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 ENCODED_STRING_PADDED = "Edxeoxm te*acxgoxsnxsex"; //When padding is left in outputString
|
||||||
private static final String encodedStringClean = "EDXEOXMTEACXGOXSNXSEX";
|
private static final String ENCODED_STRING_CLEAN = "EDXEOXMTEACXGOXSNXSEX";
|
||||||
private static final String keyword = "ke yw*ord";
|
private static final String KEYWORD = "ke yw*ord";
|
||||||
private static final String keywordClean = "KEYWORD";
|
private static final String KEYWORD_CLEAN = "KEYWORD";
|
||||||
private static final ArrayList<ArrayList<Character>> encodeGrid = new ArrayList<>(
|
private static final ArrayList<ArrayList<Character>> encodeGrid = new ArrayList<>(
|
||||||
List.of(
|
List.of(
|
||||||
new ArrayList<>(
|
new ArrayList<>(
|
||||||
@@ -237,17 +233,17 @@ public class ColumnarTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanInputString(){
|
public void testGetCleanInputString(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
String output = cipher.getCleanInputString();
|
String output = cipher.getCleanInputString();
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("[^A-Z]", ""), output);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^A-Z]", ""), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateGridEncode(){
|
public void testCreateGridEncode(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.createGridEncode();
|
cipher.createGridEncode();
|
||||||
|
|
||||||
@@ -257,8 +253,8 @@ public class ColumnarTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateGridDecode(){
|
public void testCreateGridDecode(){
|
||||||
cipher.inputString = encodedStringPadingAdded;
|
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.createGridDecode();
|
cipher.createGridDecode();
|
||||||
|
|
||||||
@@ -271,19 +267,19 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
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
|
@Test
|
||||||
@@ -291,19 +287,19 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'X';
|
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("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, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
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
|
@Test
|
||||||
@@ -311,19 +307,19 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
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
|
@Test
|
||||||
@@ -331,19 +327,19 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
verify(logger, times(1)).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Appending {} characters", 6);
|
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
|
@Test
|
||||||
@@ -351,7 +347,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -373,7 +369,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -395,7 +391,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -417,18 +413,18 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -436,7 +432,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.setInputStringDecode("Message to encod");
|
cipher.setInputStringDecode("Message to encod");
|
||||||
@@ -455,18 +451,18 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'X';
|
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("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, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -474,18 +470,18 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -493,18 +489,18 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -512,7 +508,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -533,7 +529,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -554,7 +550,7 @@ public class ColumnarTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -573,53 +569,53 @@ public class ColumnarTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateOutputStringFromColumns(){
|
public void testCreateOutputStringFromColumns(){
|
||||||
cipher.removePadding = true;
|
cipher.removePadding = true;
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = decodeGrid;
|
cipher.grid = decodeGrid;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.createOutputStringFromColumns();
|
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("Creating output string for encoding");
|
||||||
verify(logger, times(1)).debug("Getting added characters");
|
verify(logger, times(1)).debug("Getting added characters");
|
||||||
verify(logger, times(1)).debug("Turning grid into string");
|
verify(logger, times(1)).debug("Turning grid into string");
|
||||||
verify(logger, times(1)).debug("Formatting output 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
|
@Test
|
||||||
public void testCreateOutputStringFromColumns_padding(){
|
public void testCreateOutputStringFromColumns_padding(){
|
||||||
cipher.removePadding = false;
|
cipher.removePadding = false;
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = decodeGrid;
|
cipher.grid = decodeGrid;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.createOutputStringFromColumns();
|
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("Creating output string for encoding");
|
||||||
verify(logger, times(1)).debug("Getting added characters");
|
verify(logger, times(1)).debug("Getting added characters");
|
||||||
verify(logger, times(1)).debug("Turning grid into string");
|
verify(logger, times(1)).debug("Turning grid into string");
|
||||||
verify(logger, times(1)).debug("Formatting output 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
|
@Test
|
||||||
public void testCreateOutputStringFromRows(){
|
public void testCreateOutputStringFromRows(){
|
||||||
cipher.removePadding = false;
|
cipher.removePadding = false;
|
||||||
cipher.inputString = encodedStringPadded;
|
cipher.inputString = ENCODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = encodeGrid;
|
cipher.grid = encodeGrid;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.createOutputStringFromRows();
|
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("Creating output string for decoding");
|
||||||
verify(logger, times(1)).debug("Transforming grid to a string");
|
verify(logger, times(1)).debug("Transforming grid to a string");
|
||||||
verify(logger, times(1)).debug("Removing padding");
|
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(1)).debug("Adding upper case");
|
||||||
verify(logger, times(20)).debug("Adding lower case");
|
verify(logger, times(20)).debug("Adding lower case");
|
||||||
verify(logger, times(2)).debug("Adding symbol");
|
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
|
@Test
|
||||||
public void testCreateOuputStringFromRows_removePadding(){
|
public void testCreateOuputStringFromRows_removePadding(){
|
||||||
cipher.removePadding = true;
|
cipher.removePadding = true;
|
||||||
cipher.inputString = encodedStringPadingAdded;
|
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = encodeGrid;
|
cipher.grid = encodeGrid;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.createOutputStringFromRows();
|
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("Creating output string for decoding");
|
||||||
verify(logger, times(1)).debug("Transforming grid to a string");
|
verify(logger, times(1)).debug("Transforming grid to a string");
|
||||||
verify(logger, times(1)).debug("Removing padding");
|
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(1)).debug("Adding upper case");
|
||||||
verify(logger, times(14)).debug("Adding lower case");
|
verify(logger, times(14)).debug("Adding lower case");
|
||||||
verify(logger, times(2)).debug("Adding symbol");
|
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
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
verify(logger, times(1)).debug("Original keyword {}", KEYWORD);
|
||||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
verify(logger, times(1)).debug("Cleaned keyword {}", KEYWORD_CLEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -722,7 +718,7 @@ public class ColumnarTest{
|
|||||||
public void testGetKeywordAlphaLocations(){
|
public void testGetKeywordAlphaLocations(){
|
||||||
ArrayList<Integer> alphaLocations = new ArrayList<>(List.of(6, 1, 0, 4, 5, 3, 2));
|
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();
|
ArrayList<Integer> returnedLocations = cipher.getKeywordAlphaLocations();
|
||||||
|
|
||||||
@@ -735,7 +731,7 @@ public class ColumnarTest{
|
|||||||
public void testGetKeywordOriginalLocations(){
|
public void testGetKeywordOriginalLocations(){
|
||||||
ArrayList<Integer> orderedLocations = new ArrayList<>(List.of(2, 1, 6, 5, 3, 4, 0));
|
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();
|
ArrayList<Integer> returnedLocations = cipher.getKeywordOriginalLocations();
|
||||||
|
|
||||||
@@ -774,14 +770,14 @@ public class ColumnarTest{
|
|||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.removePadding = true;
|
cipher.removePadding = true;
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Creating grid for encoding");
|
verify(logger, times(1)).debug("Creating grid for encoding");
|
||||||
verify(logger, times(2)).debug("Creating an array of keyword letter locations");
|
verify(logger, times(2)).debug("Creating an array of keyword letter locations");
|
||||||
@@ -793,14 +789,14 @@ public class ColumnarTest{
|
|||||||
public void testEncode_padding(){
|
public void testEncode_padding(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.removePadding = false;
|
cipher.removePadding = false;
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedStringPadded, cipher.outputString);
|
assertEquals(ENCODED_STRING_PADDED, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Creating grid for encoding");
|
verify(logger, times(1)).debug("Creating grid for encoding");
|
||||||
verify(logger, times(1)).debug("Creating an array of keyword letter locations");
|
verify(logger, times(1)).debug("Creating an array of keyword letter locations");
|
||||||
@@ -812,14 +808,14 @@ public class ColumnarTest{
|
|||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.removePadding = true;
|
cipher.removePadding = true;
|
||||||
cipher.inputString = encodedStringPadingAdded;
|
cipher.inputString = ENCODED_STRING_PADDING_ADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Creating grid for decoding");
|
verify(logger, times(1)).debug("Creating grid for decoding");
|
||||||
verify(logger, times(2)).debug("Creating array of original keyword locations");
|
verify(logger, times(2)).debug("Creating array of original keyword locations");
|
||||||
@@ -831,14 +827,14 @@ public class ColumnarTest{
|
|||||||
public void testDecode_padding(){
|
public void testDecode_padding(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.removePadding = false;
|
cipher.removePadding = false;
|
||||||
cipher.inputString = encodedStringPadded;
|
cipher.inputString = ENCODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.charsAdded = 6;
|
cipher.charsAdded = 6;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Creating grid for decoding");
|
verify(logger, times(1)).debug("Creating grid for decoding");
|
||||||
verify(logger, times(1)).debug("Creating array of original keyword locations");
|
verify(logger, times(1)).debug("Creating array of original keyword locations");
|
||||||
@@ -848,20 +844,20 @@ public class ColumnarTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
assertEquals(KEYWORD, cipher.getKeyword());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.grid = encodeGrid;
|
cipher.grid = encodeGrid;
|
||||||
cipher.charsAdded = 5;
|
cipher.charsAdded = 5;
|
||||||
|
|
||||||
@@ -878,71 +874,71 @@ public class ColumnarTest{
|
|||||||
public void testPracticalEncode(){
|
public void testPracticalEncode(){
|
||||||
cipher = new Columnar(true, true, true, true);
|
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(DECODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_noPadding(){
|
public void testPracticalEncode_noPadding(){
|
||||||
cipher = new Columnar(true, true, true, false);
|
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(DECODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringPadded, cipher.outputString);
|
assertEquals(ENCODED_STRING_PADDED, cipher.outputString);
|
||||||
assertEquals(encodedStringPadded, output);
|
assertEquals(ENCODED_STRING_PADDED, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_clean(){
|
public void testPracticalEncode_clean(){
|
||||||
cipher = new Columnar(false, false, false, false);
|
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(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode(){
|
public void testPracticalDecode(){
|
||||||
cipher = new Columnar(true, true, true, true);
|
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(ENCODED_STRING_PADDING_ADDED, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_noPadding(){
|
public void testPracticalDecode_noPadding(){
|
||||||
cipher = new Columnar(true, true, true, false);
|
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(ENCODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
assertEquals(decodedStringPadded, output);
|
assertEquals(DECODED_STRING_PADDED, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_clean(){
|
public void testPracticalDecode_clean(){
|
||||||
cipher = new Columnar(false, false, false, false);
|
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(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -31,13 +27,13 @@ public class HillTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String decodedString = "Message to^encoded";
|
private static final String DECODED_STRING = "Message to^encoded";
|
||||||
private static final String decodedStringPadded = "Message to^encodedxx";
|
private static final String DECODED_STRING_PADDED = "Message to^encodedxx";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODEDXX";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODEDXX";
|
||||||
private static final String encodedString = "Mgkeqge ul^ikhisplrd";
|
private static final String ENCODED_STRING = "Mgkeqge ul^ikhisplrd";
|
||||||
private static final String encodedStringClean = "MGKEQGEULIKHISPLRD";
|
private static final String ENCODED_STRING_CLEAN = "MGKEQGEULIKHISPLRD";
|
||||||
private static final int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
private static final int[][] KEY_ARRAY = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||||
private static final ModMatrix key = new ModMatrix(keyArray, 26);
|
private static final ModMatrix KEY = new ModMatrix(KEY_ARRAY, 26);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,19 +129,19 @@ public class HillTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKey(){
|
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("Setting key");
|
||||||
verify(logger, times(1)).debug("Testing mod");
|
verify(logger, times(1)).debug("Testing mod");
|
||||||
verify(logger, times(1)).debug("Testing square");
|
verify(logger, times(1)).debug("Testing square");
|
||||||
verify(logger, times(1)).debug("Testing invertable");
|
verify(logger, times(1)).debug("Testing invertable");
|
||||||
verify(logger, times(1)).debug("key\n{}", key);
|
verify(logger, times(1)).debug("key\n{}", KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKey_invalidMod(){
|
public void testSetKey_invalidMod(){
|
||||||
ModMatrix matrix = new ModMatrix(keyArray, 30);
|
ModMatrix matrix = new ModMatrix(KEY_ARRAY, 30);
|
||||||
|
|
||||||
assertThrows(InvalidKeyException.class, () -> {
|
assertThrows(InvalidKeyException.class, () -> {
|
||||||
cipher.setKey(matrix);
|
cipher.setKey(matrix);
|
||||||
@@ -196,20 +192,20 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Checking length");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
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
|
@Test
|
||||||
@@ -217,20 +213,20 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'X';
|
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("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, times(1)).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Checking length");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
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
|
@Test
|
||||||
@@ -238,20 +234,20 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 capitals");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Checking length");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
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
|
@Test
|
||||||
@@ -259,20 +255,20 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
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("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 capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
verify(logger, times(1)).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Checking length");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
verify(logger, times(1)).debug("Adding {} characters", 2);
|
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
|
@Test
|
||||||
@@ -280,7 +276,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -303,7 +299,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -326,7 +322,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
cipher.characterToAdd = 'x';
|
cipher.characterToAdd = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
@@ -349,17 +345,17 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = 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("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 capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,17 +364,17 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = false;
|
cipher.preserveCapitals = false;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = 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("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, times(1)).debug("Removing capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,17 +383,17 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
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("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 capitals");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,17 +402,17 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
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("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 capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,19 +421,19 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
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("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 capitals");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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");
|
verify(logger, times(1)).debug("Checking length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +442,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputStringDecode("");
|
cipher.setInputStringDecode("");
|
||||||
@@ -467,7 +463,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputStringDecode("*^&");
|
cipher.setInputStringDecode("*^&");
|
||||||
@@ -488,7 +484,7 @@ public class HillTest{
|
|||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputStringDecode(null);
|
cipher.setInputStringDecode(null);
|
||||||
@@ -506,13 +502,13 @@ public class HillTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanInputString(){
|
public void testGetCleanInputString(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
|
|
||||||
String output = cipher.getCleanInputString();
|
String output = cipher.getCleanInputString();
|
||||||
|
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
verify(logger, times(1)).debug("Cleaning inputString");
|
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
|
@Test
|
||||||
@@ -555,18 +551,18 @@ public class HillTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPolishOutputString(){
|
public void testPolishOutputString(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.outputString = encodedStringClean;
|
cipher.outputString = ENCODED_STRING_CLEAN;
|
||||||
|
|
||||||
String output = cipher.polishOutputString();
|
String output = cipher.polishOutputString();
|
||||||
|
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
verify(logger, times(1)).debug("Polishing output string");
|
verify(logger, times(1)).debug("Polishing output string");
|
||||||
verify(logger, times(20)).debug(eq("Current char {}"), anyChar());
|
verify(logger, times(20)).debug(eq("Current char {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Uppercase");
|
verify(logger, times(1)).debug("Uppercase");
|
||||||
verify(logger, times(17)).debug("Lowercase");
|
verify(logger, times(17)).debug("Lowercase");
|
||||||
verify(logger, times(2)).debug("Symbol");
|
verify(logger, times(2)).debug("Symbol");
|
||||||
verify(logger, times(1)).debug("Polished string '{}'", encodedString);
|
verify(logger, times(1)).debug("Polished string '{}'", ENCODED_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -579,8 +575,8 @@ public class HillTest{
|
|||||||
expectedVectors.add(new ModMatrix(new int[][]{{14}, { 3}, { 4}}, 26));
|
expectedVectors.add(new ModMatrix(new int[][]{{14}, { 3}, { 4}}, 26));
|
||||||
expectedVectors.add(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26));
|
expectedVectors.add(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26));
|
||||||
|
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
ArrayList<ModMatrix> returnedVectors = cipher.getInputVectors();
|
ArrayList<ModMatrix> returnedVectors = cipher.getInputVectors();
|
||||||
|
|
||||||
@@ -593,29 +589,29 @@ public class HillTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testGetOutputFromVectors(){
|
public void testGetOutputFromVectors(){
|
||||||
ArrayList<ModMatrix> outputVectors = new ArrayList<>();
|
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[][]{{12}, { 4}, {18}}, 26)));
|
||||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{18}, { 0}, { 6}}, 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}, {19}, {14}}, 26)));
|
||||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{ 4}, {13}, { 2}}, 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[][]{{14}, { 3}, { 4}}, 26)));
|
||||||
outputVectors.add(key.multiply(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26)));
|
outputVectors.add(KEY.multiply(new ModMatrix(new int[][]{{ 3}, {23}, {23}}, 26)));
|
||||||
|
|
||||||
String returnedString = cipher.getOutputFromVectors(outputVectors);
|
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(1)).debug("Turning vectors into a string");
|
||||||
verify(logger, times(6)).debug(eq("Current vector {}"), any(ModMatrix.class));
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Multiplying vectors");
|
verify(logger, times(1)).debug("Multiplying vectors");
|
||||||
verify(logger, times(6)).debug(eq("Current input vector {}"), any(ModMatrix.class));
|
verify(logger, times(6)).debug(eq("Current input vector {}"), any(ModMatrix.class));
|
||||||
@@ -624,35 +620,35 @@ public class HillTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Getting inverse of key");
|
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("Current input vector {}"), any(ModMatrix.class));
|
||||||
verify(logger, times(6)).debug(eq("Multiplied vector {}"), any(ModMatrix.class));
|
verify(logger, times(6)).debug(eq("Multiplied vector {}"), any(ModMatrix.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(key, cipher.getKey());
|
assertEquals(KEY, cipher.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.key = key;
|
cipher.key = KEY;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -666,46 +662,46 @@ public class HillTest{
|
|||||||
public void testPracticalEncode(){
|
public void testPracticalEncode(){
|
||||||
cipher = new Hill(true, true, true);
|
cipher = new Hill(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(key, decodedString);
|
String output = cipher.encode(KEY, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringPadded, cipher.inputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_clean(){
|
public void testPracticalEncode_clean(){
|
||||||
cipher = new Hill(false, false, false);
|
cipher = new Hill(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(key, decodedString);
|
String output = cipher.encode(KEY, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_array(){
|
public void testPracticalEncode_array(){
|
||||||
cipher = new Hill(true, true, true);
|
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(DECODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_padding(){
|
public void testPracticalEncode_padding(){
|
||||||
cipher = new Hill(true, true, true, 'j');
|
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(DECODED_STRING + "jj", cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals("Mgkeqge ul^ikhispfzn", cipher.outputString);
|
assertEquals("Mgkeqge ul^ikhispfzn", cipher.outputString);
|
||||||
assertEquals("Mgkeqge ul^ikhispfzn", output);
|
assertEquals("Mgkeqge ul^ikhispfzn", output);
|
||||||
}
|
}
|
||||||
@@ -714,47 +710,47 @@ public class HillTest{
|
|||||||
public void testPracticalDecode(){
|
public void testPracticalDecode(){
|
||||||
cipher = new Hill(true, true, true);
|
cipher = new Hill(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(key, encodedString);
|
String output = cipher.decode(KEY, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
assertEquals(decodedStringPadded, output);
|
assertEquals(DECODED_STRING_PADDED, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_clean(){
|
public void testPracticalDecode_clean(){
|
||||||
cipher = new Hill(false, false, false);
|
cipher = new Hill(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(key, encodedString);
|
String output = cipher.decode(KEY, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_array(){
|
public void testPracticalDecode_array(){
|
||||||
cipher = new Hill(true, true, true);
|
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(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
assertEquals(decodedStringPadded, output);
|
assertEquals(DECODED_STRING_PADDED, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_padding(){
|
public void testPracticalDecode_padding(){
|
||||||
cipher = new Hill(true, true, true, 'j');
|
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("Mgkeqge ul^ikhispfzn", cipher.inputString);
|
||||||
assertEquals(key, cipher.key);
|
assertEquals(KEY, cipher.key);
|
||||||
assertEquals(decodedString + "jj", cipher.outputString);
|
assertEquals(DECODED_STRING + "jj", cipher.outputString);
|
||||||
assertEquals(decodedString + "jj", output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,14 +23,14 @@ public class LargePolybiusSquareTest{
|
|||||||
@Mock(name = "com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare")
|
@Mock(name = "com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare")
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Variables
|
//Variables
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "35124343222612 4415^123624152112";
|
private static final String ENCODED_STRING = "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 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 = "ke yw*ord";
|
||||||
private static final String keywordClean = "KEYWORDABCFGHIJLMNPQSTUVXZ0123456789";
|
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHIJLMNPQSTUVXZ0123456789";
|
||||||
private static final String keywordBlank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
private static final String KEYWORD_BLANK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
private static final char[][] grid = {
|
private static final char[][] GRID = {
|
||||||
{'K', 'E', 'Y', 'W', 'O', 'R'},
|
{'K', 'E', 'Y', 'W', 'O', 'R'},
|
||||||
{'D', 'A', 'B', 'C', 'F', 'G'},
|
{'D', 'A', 'B', 'C', 'F', 'G'},
|
||||||
{'H', 'I', 'J', 'L', 'M', 'N'},
|
{'H', 'I', 'J', 'L', 'M', 'N'},
|
||||||
@@ -42,7 +38,7 @@ public class LargePolybiusSquareTest{
|
|||||||
{'X', 'Z', '0', '1', '2', '3'},
|
{'X', 'Z', '0', '1', '2', '3'},
|
||||||
{'4', '5', '6', '7', '8', '9'}
|
{'4', '5', '6', '7', '8', '9'}
|
||||||
};
|
};
|
||||||
private static final char[][] gridClean = {
|
private static final char[][] GRID_CLEAN = {
|
||||||
{'A', 'B', 'C', 'D', 'E', 'F'},
|
{'A', 'B', 'C', 'D', 'E', 'F'},
|
||||||
{'G', 'H', 'I', 'J', 'K', 'L'},
|
{'G', 'H', 'I', 'J', 'K', 'L'},
|
||||||
{'M', 'N', 'O', 'P', 'Q', 'R'},
|
{'M', 'N', 'O', 'P', 'Q', 'R'},
|
||||||
@@ -90,11 +86,11 @@ public class LargePolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateGrid(){
|
public void testCreateGrid(){
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.createGrid();
|
cipher.createGrid();
|
||||||
|
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Creating grid");
|
verify(logger, times(1)).debug("Creating grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +99,13 @@ public class LargePolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -117,13 +113,13 @@ public class LargePolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("\\s", ""), 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 whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -131,13 +127,13 @@ public class LargePolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z0-9\\s]", ""), 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 whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -145,10 +141,10 @@ public class LargePolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = 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);
|
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 whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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");
|
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
|
@Test
|
||||||
public void testGetPreparedInputStringEncoding(){
|
public void testGetPreparedInputStringEncoding(){
|
||||||
cipher.inputString = decodedString.toUpperCase();
|
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||||
|
|
||||||
String preparedInputString = cipher.getPreparedInputStringEncode();
|
String preparedInputString = cipher.getPreparedInputStringEncode();
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""), preparedInputString);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", ""), preparedInputString);
|
||||||
verify(logger, times(1)).debug("Preparing input string for encoding");
|
verify(logger, times(1)).debug("Preparing input string for encoding");
|
||||||
verify(logger, times(1)).debug("Prepared input string '{}'", preparedInputString);
|
verify(logger, times(1)).debug("Prepared input string '{}'", preparedInputString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
verify(logger, times(1)).debug("Original keyword '{}'", KEYWORD);
|
||||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keywordClean);
|
verify(logger, times(1)).debug("Cleaned keyword '{}'", KEYWORD_CLEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword_blank(){
|
public void testSetKeyword_blank(){
|
||||||
cipher.setKeyword("");
|
cipher.setKeyword("");
|
||||||
|
|
||||||
assertEquals(keywordBlank, cipher.keyword);
|
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||||
assertArrayEquals(gridClean, cipher.grid);
|
assertArrayEquals(GRID_CLEAN, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Original keyword '{}'", "");
|
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
|
@Test
|
||||||
@@ -250,43 +246,43 @@ public class LargePolybiusSquareTest{
|
|||||||
public void testAddCharactersToCleanStringEncode(){
|
public void testAddCharactersToCleanStringEncode(){
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
cipher.inputString = decodedString.toUpperCase();
|
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(1)).debug("Formatting output string");
|
||||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Appending character");
|
verify(logger, times(15)).debug("Appending character");
|
||||||
verify(logger, times(2)).debug("Appending symbol");
|
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
|
@Test
|
||||||
public void testAddCharactersToCleanStringDecode(){
|
public void testAddCharactersToCleanStringDecode(){
|
||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
cipher.addCharactersToCleanStringDecode(decodedStringClean);
|
cipher.addCharactersToCleanStringDecode(DECODED_STRING_CLEAN);
|
||||||
|
|
||||||
verify(logger, times(1)).debug("Formatting output string");
|
verify(logger, times(1)).debug("Formatting output string");
|
||||||
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Current character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Appending character");
|
verify(logger, times(15)).debug("Appending character");
|
||||||
verify(logger, times(2)).debug("Appending symbol");
|
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
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -302,47 +298,47 @@ public class LargePolybiusSquareTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new LargePolybiusSquare(true, true);
|
cipher = new LargePolybiusSquare(true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new LargePolybiusSquare(false, false);
|
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("M E S S A G E T O E N C O D E", cipher.inputString);
|
||||||
assertEquals(keywordBlank, cipher.keyword);
|
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new LargePolybiusSquare(true, true);
|
cipher = new LargePolybiusSquare(true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||||
assertEquals(decodedString.toUpperCase(), output);
|
assertEquals(DECODED_STRING.toUpperCase(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean(){
|
public void testPracticalDecoding_clean(){
|
||||||
cipher = new LargePolybiusSquare(false, false);
|
cipher = new LargePolybiusSquare(false, false);
|
||||||
|
|
||||||
String output = cipher.decode(encodedStringClean);
|
String output = cipher.decode(ENCODED_STRING_CLEAN);
|
||||||
|
|
||||||
assertEquals(encodedStringClean.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN.replaceAll("\\s", ""), cipher.inputString);
|
||||||
assertEquals(keywordBlank, cipher.keyword);
|
assertEquals(KEYWORD_BLANK, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,9 +22,9 @@ public class MorseTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String inputString = "Message to^encode123";
|
private static final String INPUT_STRING = "Message to^encode123";
|
||||||
private static final String inputStringClean = "MESSAGETOENCODE123";
|
private static final String INPUT_STRING_CLEAN = "MESSAGETOENCODE123";
|
||||||
private static final String outputString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
private static final String OUTPUT_STRING = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -41,13 +37,13 @@ public class MorseTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInputStringEncode(){
|
public void testSetInputStringEncode(){
|
||||||
cipher.setInputStringEncode(inputString);
|
cipher.setInputStringEncode(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputStringClean, cipher.inputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace and symbols");
|
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
|
@Test
|
||||||
@@ -93,10 +89,10 @@ public class MorseTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInputStringDecode(){
|
public void testSetInputStringDecode(){
|
||||||
cipher.setInputStringDecode(outputString);
|
cipher.setInputStringDecode(OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputString, cipher.inputString);
|
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
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("Checking for invalid characters");
|
||||||
verify(logger, times(1)).debug("Saving");
|
verify(logger, times(1)).debug("Saving");
|
||||||
}
|
}
|
||||||
@@ -141,16 +137,16 @@ public class MorseTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = inputStringClean;
|
cipher.inputString = INPUT_STRING_CLEAN;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Appending letter");
|
verify(logger, times(15)).debug("Appending letter");
|
||||||
verify(logger, times(3)).debug("Appending number");
|
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
|
@Test
|
||||||
@@ -166,20 +162,20 @@ public class MorseTest{
|
|||||||
verify(logger, times(1)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(1)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, never()).debug("Appending letter");
|
verify(logger, never()).debug("Appending letter");
|
||||||
verify(logger, never()).debug("Appending number");
|
verify(logger, never()).debug("Appending number");
|
||||||
verify(logger, never()).debug("Saving encoded string '{}'", outputString);
|
verify(logger, never()).debug("Saving encoded string '{}'", OUTPUT_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = outputString;
|
cipher.inputString = OUTPUT_STRING;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(inputStringClean, cipher.outputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(18)).debug(eq("Working letter {}"), anyString());
|
verify(logger, times(18)).debug(eq("Working letter {}"), anyString());
|
||||||
verify(logger, times(18)).debug(eq("Decoded letter {}"), anyChar());
|
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
|
@Test
|
||||||
@@ -199,17 +195,17 @@ public class MorseTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
|
|
||||||
assertEquals(inputString, cipher.getInputString());
|
assertEquals(INPUT_STRING, cipher.getInputString());
|
||||||
assertEquals(outputString, cipher.getOutputString());
|
assertEquals(OUTPUT_STRING, cipher.getOutputString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = inputString;
|
cipher.inputString = INPUT_STRING;
|
||||||
cipher.outputString = outputString;
|
cipher.outputString = OUTPUT_STRING;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -220,19 +216,19 @@ public class MorseTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode(){
|
public void testPracticalEncode(){
|
||||||
String output = cipher.encode(inputString);
|
String output = cipher.encode(INPUT_STRING);
|
||||||
|
|
||||||
assertEquals(inputStringClean, cipher.inputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(outputString, cipher.outputString);
|
assertEquals(OUTPUT_STRING, cipher.outputString);
|
||||||
assertEquals(outputString, output);
|
assertEquals(OUTPUT_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode(){
|
public void testPracticalDecode(){
|
||||||
String output = cipher.decode(outputString);
|
String output = cipher.decode(OUTPUT_STRING);
|
||||||
|
|
||||||
assertEquals(outputString, cipher.inputString);
|
assertEquals(OUTPUT_STRING, cipher.inputString);
|
||||||
assertEquals(inputStringClean, cipher.outputString);
|
assertEquals(INPUT_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(inputStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,14 +25,14 @@ public class PlayfairTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String decodedString = "Hide the gold in - the@tree+stump";
|
private static final String DECODED_STRING = "Hide the gold in - the@tree+stump";
|
||||||
private static final String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
private static final String DECODED_STRING_PADDED = "Hide the gold in - the@trexe+stump";
|
||||||
private static final String decodedStringClean = "HIDETHEGOLDINTHETREXESTUMP";
|
private static final String DECODED_STRING_CLEAN = "HIDETHEGOLDINTHETREXESTUMP";
|
||||||
private static final String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
private static final String ENCODED_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||||
private static final String encodedStringClean = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
private static final String ENCODED_STRING_CLEAN = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||||
private static final String keyword = "Play-fair@Exam ple";
|
private static final String KEYWORD = "Play-fair@Exam ple";
|
||||||
private static final String keywordClean = "PLAYFIREXMBCDGHKNOQSTUVWZ";
|
private static final String KEYWORD_CLEAN = "PLAYFIREXMBCDGHKNOQSTUVWZ";
|
||||||
private static final char[][] grid = new char[][]{
|
private static final char[][] GRID = new char[][]{
|
||||||
{'P', 'L', 'A', 'Y', 'F'},
|
{'P', 'L', 'A', 'Y', 'F'},
|
||||||
{'I', 'R', 'E', 'X', 'M'},
|
{'I', 'R', 'E', 'X', 'M'},
|
||||||
{'B', 'C', 'D', 'G', 'H'},
|
{'B', 'C', 'D', 'G', 'H'},
|
||||||
@@ -394,11 +390,11 @@ public class PlayfairTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateGrid(){
|
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]";
|
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();
|
cipher.createGrid();
|
||||||
|
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
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(25)).debug(eq("Letter {} going to position [{}] [{}]"), anyChar(), anyInt(), anyInt());
|
||||||
verify(logger, times(1)).debug("Grid\n{}", expectedGridString);
|
verify(logger, times(1)).debug("Grid\n{}", expectedGridString);
|
||||||
@@ -411,11 +407,11 @@ public class PlayfairTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.doubled = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -428,11 +424,11 @@ public class PlayfairTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.doubled = 'X';
|
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("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, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -445,11 +441,11 @@ public class PlayfairTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.doubled = 'x';
|
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("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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -462,11 +458,11 @@ public class PlayfairTest{
|
|||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
cipher.doubled = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
verify(logger, times(1)).debug("Removing symbols");
|
||||||
@@ -498,15 +494,15 @@ public class PlayfairTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
cipher.doubled = 'x';
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -517,16 +513,16 @@ public class PlayfairTest{
|
|||||||
cipher.doubled = 'x';
|
cipher.doubled = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidCharacterException.class, () -> {
|
assertThrows(InvalidCharacterException.class, () -> {
|
||||||
cipher.setInputString(encodedString + cipher.replaced, false);
|
cipher.setInputString(ENCODED_STRING + cipher.replaced, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
assertEquals("", cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string");
|
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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, never()).debug("Clean input string '{}'", encodedString);
|
verify(logger, never()).debug("Clean input string '{}'", ENCODED_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -537,16 +533,16 @@ public class PlayfairTest{
|
|||||||
cipher.doubled = 'x';
|
cipher.doubled = 'x';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
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("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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -593,48 +589,48 @@ public class PlayfairTest{
|
|||||||
public void testSetInputStringEncode(){
|
public void testSetInputStringEncode(){
|
||||||
cipher.doubled = 'x';
|
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("Cleaning up input string for encoding");
|
||||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
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("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(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, times(1)).debug("Checking odd characters");
|
||||||
verify(logger, never()).debug("Adding final character to make even");
|
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
|
@Test
|
||||||
public void testSetInputStringEncode_odd(){
|
public void testSetInputStringEncode_odd(){
|
||||||
cipher.doubled = 'x';
|
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("Cleaning up input string for encoding");
|
||||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
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("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(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("Checking odd characters");
|
||||||
verify(logger, times(1)).debug("Adding final character to make even");
|
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
|
@Test
|
||||||
public void testSetInputString_oddEndSymbol(){
|
public void testSetInputString_oddEndSymbol(){
|
||||||
cipher.doubled = 'x';
|
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("Cleaning up input string for encoding");
|
||||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
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("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(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("Checking odd characters");
|
||||||
verify(logger, times(1)).debug("Adding final character to make even");
|
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
|
@Test
|
||||||
@@ -642,41 +638,41 @@ public class PlayfairTest{
|
|||||||
cipher.doubled = 'x';
|
cipher.doubled = 'x';
|
||||||
cipher.replacer = 'i';
|
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("Cleaning up input string for encoding");
|
||||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
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("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(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("Checking odd characters");
|
||||||
verify(logger, times(1)).debug("Adding final character to make even");
|
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
|
@Test
|
||||||
public void testGetPreparedInputString(){
|
public void testGetPreparedInputString(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
|
|
||||||
String output = cipher.getPreparedInputString();
|
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("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
|
@Test
|
||||||
public void testSetKeyword(){
|
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("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 case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
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("Appending the alphabet to the keyword");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||||
verify(logger, times(1)).debug("Removing duplicate characters");
|
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
|
@Test
|
||||||
@@ -698,7 +694,7 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar(){
|
public void testFindChar(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
CharLocation returnedLocation = cipher.findChar('E');
|
CharLocation returnedLocation = cipher.findChar('E');
|
||||||
|
|
||||||
@@ -710,7 +706,7 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar_invalid(){
|
public void testFindChar_invalid(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.findChar('J');
|
cipher.findChar('J');
|
||||||
@@ -722,61 +718,61 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGridChar(){
|
public void testGetGridChar(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
char output = cipher.getGridChar(1, 1);
|
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("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
|
@Test
|
||||||
public void testGetGridChar_large(){
|
public void testGetGridChar_large(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
char output = cipher.getGridChar(-4, -4);
|
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("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
|
@Test
|
||||||
public void testGetGridChar_negative(){
|
public void testGetGridChar_negative(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
char output = cipher.getGridChar(6, 6);
|
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("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
|
@Test
|
||||||
public void testAddCharactersToCleanString(){
|
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(1)).debug("Formatting output string");
|
||||||
verify(logger, times(34)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(34)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Appending uppercase");
|
verify(logger, times(1)).debug("Appending uppercase");
|
||||||
verify(logger, times(25)).debug("Appending lowercase");
|
verify(logger, times(25)).debug("Appending lowercase");
|
||||||
verify(logger, times(8)).debug("Appending symbol");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedStringPadded;
|
cipher.inputString = DECODED_STRING_PADDED;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||||
verify(logger, times(2)).debug("Row encoding");
|
verify(logger, times(2)).debug("Row encoding");
|
||||||
@@ -787,13 +783,13 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||||
verify(logger, times(2)).debug("Row decoding");
|
verify(logger, times(2)).debug("Row decoding");
|
||||||
@@ -804,10 +800,10 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -820,14 +816,14 @@ public class PlayfairTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keyword, cipher.getKeyword());
|
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("[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('J', cipher.getReplaced());
|
||||||
assertEquals('I', cipher.getReplacer());
|
assertEquals('I', cipher.getReplacer());
|
||||||
@@ -839,51 +835,51 @@ public class PlayfairTest{
|
|||||||
public void testPracticalEncode(){
|
public void testPracticalEncode(){
|
||||||
cipher = new Playfair(true, true, true);
|
cipher = new Playfair(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringPadded, cipher.inputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_clean(){
|
public void testPracticalEncode_clean(){
|
||||||
cipher = new Playfair(false, false, false);
|
cipher = new Playfair(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode(){
|
public void testPracticalDecode(){
|
||||||
cipher = new Playfair(true, true, true);
|
cipher = new Playfair(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringPadded, cipher.outputString);
|
assertEquals(DECODED_STRING_PADDED, cipher.outputString);
|
||||||
assertEquals(decodedStringPadded, output);
|
assertEquals(DECODED_STRING_PADDED, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_clean(){
|
public void testPracticalDecode_clean(){
|
||||||
cipher = new Playfair(false, false, false);
|
cipher = new Playfair(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,20 +25,20 @@ public class PolybiusSquareTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "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 DECODED_STRING_CLEAN = "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 ENCODED_STRING = "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 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 = "ke yw*ord";
|
||||||
private static final String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||||
private static final char[][] grid = new char[][]{
|
private static final char[][] GRID = new char[][]{
|
||||||
{'K', 'E', 'Y', 'W', 'O'},
|
{'K', 'E', 'Y', 'W', 'O'},
|
||||||
{'R', 'D', 'A', 'B', 'C'},
|
{'R', 'D', 'A', 'B', 'C'},
|
||||||
{'F', 'G', 'H', 'I', 'L'},
|
{'F', 'G', 'H', 'I', 'L'},
|
||||||
{'M', 'N', 'P', 'Q', 'S'},
|
{'M', 'N', 'P', 'Q', 'S'},
|
||||||
{'T', 'U', 'V', 'X', 'Z'}
|
{'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
|
@Test
|
||||||
@@ -121,7 +117,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('A', cipher.replaced);
|
assertEquals('A', cipher.replaced);
|
||||||
verify(logger, times(1)).debug("Setting 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("Checking replacer");
|
||||||
verify(logger, times(1)).debug("Cleaned character {}", 'A');
|
verify(logger, times(1)).debug("Cleaned character {}", 'A');
|
||||||
}
|
}
|
||||||
@@ -134,7 +130,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('J', cipher.replaced);
|
assertEquals('J', cipher.replaced);
|
||||||
verify(logger, times(1)).debug("Setting 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("Checking replacer");
|
||||||
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
||||||
}
|
}
|
||||||
@@ -147,7 +143,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('J', cipher.replaced);
|
assertEquals('J', cipher.replaced);
|
||||||
verify(logger, times(1)).debug("Setting 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, times(1)).debug("Checking replacer");
|
||||||
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
||||||
}
|
}
|
||||||
@@ -158,7 +154,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('A', cipher.replacer);
|
assertEquals('A', cipher.replacer);
|
||||||
verify(logger, times(1)).debug("Setting 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("Checking replaced");
|
||||||
verify(logger, times(1)).debug("Cleaned character {}", 'A');
|
verify(logger, times(1)).debug("Cleaned character {}", 'A');
|
||||||
}
|
}
|
||||||
@@ -171,7 +167,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('I', cipher.replacer);
|
assertEquals('I', cipher.replacer);
|
||||||
verify(logger, times(1)).debug("Setting 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("Checking replaced");
|
||||||
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
||||||
}
|
}
|
||||||
@@ -184,20 +180,20 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
assertEquals('I', cipher.replacer);
|
assertEquals('I', cipher.replacer);
|
||||||
verify(logger, times(1)).debug("Setting 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, times(1)).debug("Checking replaced");
|
||||||
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
verify(logger, never()).debug(eq("Cleaned character {}"), anyChar());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateGrid(){
|
public void testCreateGrid(){
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.createGrid();
|
cipher.createGrid();
|
||||||
|
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
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
|
@Test
|
||||||
@@ -207,16 +203,16 @@ public class PolybiusSquareTest{
|
|||||||
cipher.replaced = 'J';
|
cipher.replaced = 'J';
|
||||||
cipher.replacer = 'I';
|
cipher.replacer = 'I';
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
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("Checking for digits");
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
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
|
@Test
|
||||||
@@ -226,16 +222,16 @@ public class PolybiusSquareTest{
|
|||||||
cipher.replaced = 'J';
|
cipher.replaced = 'J';
|
||||||
cipher.replacer = 'I';
|
cipher.replacer = 'I';
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
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("Checking for digits");
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
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
|
@Test
|
||||||
@@ -245,16 +241,16 @@ public class PolybiusSquareTest{
|
|||||||
cipher.replaced = 'J';
|
cipher.replaced = 'J';
|
||||||
cipher.replacer = 'I';
|
cipher.replacer = 'I';
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
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("Checking for digits");
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
verify(logger, times(1)).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
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
|
@Test
|
||||||
@@ -264,16 +260,16 @@ public class PolybiusSquareTest{
|
|||||||
cipher.replaced = 'J';
|
cipher.replaced = 'J';
|
||||||
cipher.replacer = 'I';
|
cipher.replacer = 'I';
|
||||||
|
|
||||||
cipher.setInputStringEncode(decodedString);
|
cipher.setInputStringEncode(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
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("Checking for digits");
|
||||||
verify(logger, times(1)).debug("Removing case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
verify(logger, times(1)).debug("Removing symbols");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
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
|
@Test
|
||||||
@@ -365,14 +361,14 @@ public class PolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
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 '{}'", encodedString);
|
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("Checking for letters");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -380,14 +376,14 @@ public class PolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
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 '{}'", encodedString);
|
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("Checking for letters");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -395,14 +391,14 @@ public class PolybiusSquareTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputStringDecode(encodedString);
|
cipher.setInputStringDecode(ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
assertEquals(ENCODED_STRING.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
||||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
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("Checking for letters");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -411,11 +407,11 @@ public class PolybiusSquareTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputStringDecode(encodedString + "a");
|
cipher.setInputStringDecode(ENCODED_STRING + "a");
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
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, times(1)).debug("Checking for letters");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -428,11 +424,11 @@ public class PolybiusSquareTest{
|
|||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputStringDecode(encodedString + "0");
|
cipher.setInputStringDecode(ENCODED_STRING + "0");
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
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, times(1)).debug("Checking for letters");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -492,38 +488,38 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPreparedInputStringEncode(){
|
public void testGetPreparedInputStringEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
String output = cipher.getPreparedInputStringEncode();
|
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("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
|
@Test
|
||||||
public void testGetPreparedInputStringDecode(){
|
public void testGetPreparedInputStringDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
|
|
||||||
String output = cipher.getPreparedInputStringDecode();
|
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("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
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
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 case");
|
||||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
verify(logger, times(1)).debug("Removing all non-letter characters");
|
||||||
verify(logger, times(1)).debug("Appending entire alphabet");
|
verify(logger, times(1)).debug("Appending entire alphabet");
|
||||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
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
|
@Test
|
||||||
@@ -566,7 +562,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar(){
|
public void testFindChar(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
CharLocation returnedLocation = cipher.findChar('A');
|
CharLocation returnedLocation = cipher.findChar('A');
|
||||||
|
|
||||||
@@ -578,7 +574,7 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar_invalid(){
|
public void testFindChar_invalid(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.findChar(cipher.replaced);
|
cipher.findChar(cipher.replaced);
|
||||||
@@ -590,41 +586,41 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddCharactersToCleanStringEncode(){
|
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(1)).debug("Formatting output string for encoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Adding encoded characters");
|
verify(logger, times(15)).debug("Adding encoded characters");
|
||||||
verify(logger, times(2)).debug("Adding symbols");
|
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
|
@Test
|
||||||
public void testAddCharactersToCleanStringDecode(){
|
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(1)).debug("Formatting output string for decoding");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Adding decoded characters");
|
verify(logger, times(15)).debug("Adding decoded characters");
|
||||||
verify(logger, times(2)).debug("Adding symbols");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString.toUpperCase();
|
cipher.inputString = DECODED_STRING.toUpperCase();
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(15)).debug(eq("Current working character {}"), anyChar());
|
verify(logger, times(15)).debug(eq("Current working character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug(eq("Location {}, {}"), anyInt(), anyInt());
|
verify(logger, times(15)).debug(eq("Location {}, {}"), anyInt(), anyInt());
|
||||||
@@ -632,13 +628,13 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(15)).debug(eq("Digits to decode {} {}"), anyChar(), anyChar());
|
verify(logger, times(15)).debug(eq("Digits to decode {} {}"), anyChar(), anyChar());
|
||||||
verify(logger, times(15)).debug(eq("Decoded letter {}"), anyChar());
|
verify(logger, times(15)).debug(eq("Decoded letter {}"), anyChar());
|
||||||
@@ -646,14 +642,14 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(keywordClean, cipher.getKeyword());
|
assertEquals(KEYWORD_CLEAN, cipher.getKeyword());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
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("[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('J', cipher.getReplaced());
|
||||||
assertEquals('I', cipher.getReplacer());
|
assertEquals('I', cipher.getReplacer());
|
||||||
@@ -661,10 +657,10 @@ public class PolybiusSquareTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -680,51 +676,51 @@ public class PolybiusSquareTest{
|
|||||||
public void testPracticalEncode(){
|
public void testPracticalEncode(){
|
||||||
cipher = new PolybiusSquare(true, true);
|
cipher = new PolybiusSquare(true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncode_clean(){
|
public void testPracticalEncode_clean(){
|
||||||
cipher = new PolybiusSquare(false, false);
|
cipher = new PolybiusSquare(false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode(){
|
public void testPracticalDecode(){
|
||||||
cipher = new PolybiusSquare(true, true);
|
cipher = new PolybiusSquare(true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
assertEquals(DECODED_STRING.toUpperCase(), cipher.outputString);
|
||||||
assertEquals(decodedString.toUpperCase(), output);
|
assertEquals(DECODED_STRING.toUpperCase(), output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecode_clean(){
|
public void testPracticalDecode_clean(){
|
||||||
cipher = new PolybiusSquare(false, false);
|
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(ENCODED_STRING.replaceAll("\\s", "").replaceAll("[^0-9]", ""), cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN.replaceAll("\\s", ""), cipher.outputString);
|
||||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), output);
|
assertEquals(DECODED_STRING_CLEAN.replaceAll("\\s", ""), output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,18 +23,18 @@ public class RailFenceTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String decodedString = "Message to^encode";
|
private static final String DECODED_STRING = "Message to^encode";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
|
||||||
private static final String encodedString3 = "Maooesg te^cdsene";
|
private static final String ENCODED_STRING_3 = "Maooesg te^cdsene";
|
||||||
private static final String encodedString3Clean = "MAOOESGTECDSENE";
|
private static final String ENCODED_STRING_3_CLEAN = "MAOOESGTECDSENE";
|
||||||
private static final String encodedString5 = "Moetese ne^sgcdao";
|
private static final String ENCODED_STRING_5 = "Moetese ne^sgcdao";
|
||||||
private static final String encodedString5Clean = "MOETESENESGCDAO";
|
private static final String ENCODED_STRING_5_CLEAN = "MOETESENESGCDAO";
|
||||||
private static final StringBuilder[] fence3 = new StringBuilder[]{
|
private static final StringBuilder[] FENCE_3 = new StringBuilder[]{
|
||||||
new StringBuilder("Maoo"),
|
new StringBuilder("Maoo"),
|
||||||
new StringBuilder("esgtecd"),
|
new StringBuilder("esgtecd"),
|
||||||
new StringBuilder("sene")
|
new StringBuilder("sene")
|
||||||
};
|
};
|
||||||
private static final StringBuilder[] fence5 = new StringBuilder[]{
|
private static final StringBuilder[] FENCE_5 = new StringBuilder[]{
|
||||||
new StringBuilder("Mo"),
|
new StringBuilder("Mo"),
|
||||||
new StringBuilder("ete"),
|
new StringBuilder("ete"),
|
||||||
new StringBuilder("sene"),
|
new StringBuilder("sene"),
|
||||||
@@ -101,14 +97,14 @@ public class RailFenceTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -117,14 +113,14 @@ public class RailFenceTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -133,14 +129,14 @@ public class RailFenceTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -149,14 +145,14 @@ public class RailFenceTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -215,43 +211,43 @@ public class RailFenceTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanInputString(){
|
public void testGetCleanInputString(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
String output = cipher.getCleanInputString();
|
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");
|
verify(logger, times(1)).debug("Getting input string for encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatOutput(){
|
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(1)).debug("Formatting output string");
|
||||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Formatting uppercase");
|
verify(logger, times(1)).debug("Formatting uppercase");
|
||||||
verify(logger, times(14)).debug("Formatting lowercase");
|
verify(logger, times(14)).debug("Formatting lowercase");
|
||||||
verify(logger, times(2)).debug("Inserting symbol");
|
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
|
@Test
|
||||||
public void testGetDecodedStringFromFence(){
|
public void testGetDecodedStringFromFence(){
|
||||||
cipher.fence = fence3;
|
cipher.fence = FENCE_3;
|
||||||
|
|
||||||
String output = cipher.getDecodedStringFromFence();
|
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("Getting decoded string from the fence");
|
||||||
verify(logger, times(1)).debug(eq("Fence output '{}'"), any(StringBuilder.class));
|
verify(logger, times(1)).debug(eq("Fence output '{}'"), any(StringBuilder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.fence = new StringBuilder[]{
|
cipher.fence = new StringBuilder[]{
|
||||||
new StringBuilder(),
|
new StringBuilder(),
|
||||||
new StringBuilder(),
|
new StringBuilder(),
|
||||||
@@ -260,7 +256,7 @@ public class RailFenceTest{
|
|||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString3, cipher.outputString);
|
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(15)).debug(eq("Working character '{}'"), anyChar());
|
verify(logger, times(15)).debug(eq("Working character '{}'"), anyChar());
|
||||||
verify(logger, times(9)).debug("Moving up");
|
verify(logger, times(9)).debug("Moving up");
|
||||||
@@ -272,7 +268,7 @@ public class RailFenceTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.inputString = encodedString3;
|
cipher.inputString = ENCODED_STRING_3;
|
||||||
cipher.fence = new StringBuilder[]{
|
cipher.fence = new StringBuilder[]{
|
||||||
new StringBuilder(),
|
new StringBuilder(),
|
||||||
new StringBuilder(),
|
new StringBuilder(),
|
||||||
@@ -281,14 +277,14 @@ public class RailFenceTest{
|
|||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
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 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 middle rails {}", 8);
|
||||||
verify(logger, times(1)).debug("Number of characters in the bottom rail {}", 4);
|
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("Adding characters to the rails");
|
||||||
verify(logger, times(1)).debug("Appending the bottom rail");
|
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
|
@Test
|
||||||
@@ -314,20 +310,20 @@ public class RailFenceTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString3;
|
cipher.outputString = ENCODED_STRING_3;
|
||||||
cipher.fence = fence3;
|
cipher.fence = FENCE_3;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString3, cipher.getOutputString());
|
assertEquals(ENCODED_STRING_3, cipher.getOutputString());
|
||||||
assertEquals(fence3.length, cipher.getNumRails());
|
assertEquals(FENCE_3.length, cipher.getNumRails());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString3;
|
cipher.outputString = ENCODED_STRING_3;
|
||||||
cipher.fence = fence3;
|
cipher.fence = FENCE_3;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -340,127 +336,127 @@ public class RailFenceTest{
|
|||||||
public void testPracticalEncoding_3(){
|
public void testPracticalEncoding_3(){
|
||||||
cipher = new RailFence(true, true, true);
|
cipher = new RailFence(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(3, decodedString);
|
String output = cipher.encode(3, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(fence3.length, cipher.fence.length);
|
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
assertEquals(FENCE_3[0].toString(), cipher.fence[0].toString());
|
||||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
assertEquals(FENCE_3[1].toString(), cipher.fence[1].toString());
|
||||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
assertEquals(FENCE_3[2].toString(), cipher.fence[2].toString());
|
||||||
assertEquals(encodedString3, cipher.outputString);
|
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||||
assertEquals(encodedString3, output);
|
assertEquals(ENCODED_STRING_3, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_3Clean(){
|
public void testPracticalEncoding_3Clean(){
|
||||||
cipher = new RailFence(false, false, false);
|
cipher = new RailFence(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(3, decodedString);
|
String output = cipher.encode(3, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(fence3.length, cipher.fence.length);
|
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
assertEquals(FENCE_3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
assertEquals(FENCE_3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
assertEquals(FENCE_3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||||
assertEquals(encodedString3Clean, cipher.outputString);
|
assertEquals(ENCODED_STRING_3_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedString3Clean, output);
|
assertEquals(ENCODED_STRING_3_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_5(){
|
public void testPracticalEncoding_5(){
|
||||||
cipher = new RailFence(true, true, true);
|
cipher = new RailFence(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(5, decodedString);
|
String output = cipher.encode(5, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(fence5.length, cipher.fence.length);
|
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
assertEquals(FENCE_5[0].toString(), cipher.fence[0].toString());
|
||||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
assertEquals(FENCE_5[1].toString(), cipher.fence[1].toString());
|
||||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
assertEquals(FENCE_5[2].toString(), cipher.fence[2].toString());
|
||||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
assertEquals(FENCE_5[3].toString(), cipher.fence[3].toString());
|
||||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
assertEquals(FENCE_5[4].toString(), cipher.fence[4].toString());
|
||||||
assertEquals(encodedString5, cipher.outputString);
|
assertEquals(ENCODED_STRING_5, cipher.outputString);
|
||||||
assertEquals(encodedString5, output);
|
assertEquals(ENCODED_STRING_5, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_5Clean(){
|
public void testPracticalEncoding_5Clean(){
|
||||||
cipher = new RailFence(false, false, false);
|
cipher = new RailFence(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(5, decodedString);
|
String output = cipher.encode(5, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(fence5.length, cipher.fence.length);
|
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
assertEquals(FENCE_5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
assertEquals(FENCE_5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
assertEquals(FENCE_5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
assertEquals(FENCE_5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
assertEquals(FENCE_5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||||
assertEquals(encodedString5Clean, cipher.outputString);
|
assertEquals(ENCODED_STRING_5_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedString5Clean, output);
|
assertEquals(ENCODED_STRING_5_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_3(){
|
public void testPracticalDecoding_3(){
|
||||||
cipher = new RailFence(true, true, true);
|
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(ENCODED_STRING_3, cipher.inputString);
|
||||||
assertEquals(fence3.length, cipher.fence.length);
|
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
assertEquals(FENCE_3[0].toString(), cipher.fence[0].toString());
|
||||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
assertEquals(FENCE_3[1].toString(), cipher.fence[1].toString());
|
||||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
assertEquals(FENCE_3[2].toString(), cipher.fence[2].toString());
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_3Clean(){
|
public void testPracticalDecoding_3Clean(){
|
||||||
cipher = new RailFence(false, false, false);
|
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(ENCODED_STRING_3_CLEAN, cipher.inputString);
|
||||||
assertEquals(fence3.length, cipher.fence.length);
|
assertEquals(FENCE_3.length, cipher.fence.length);
|
||||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
assertEquals(FENCE_3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
assertEquals(FENCE_3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
assertEquals(FENCE_3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_5(){
|
public void testPracticalDecoding_5(){
|
||||||
cipher = new RailFence(true, true, true);
|
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(ENCODED_STRING_5, cipher.inputString);
|
||||||
assertEquals(fence5.length, cipher.fence.length);
|
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
assertEquals(FENCE_5[0].toString(), cipher.fence[0].toString());
|
||||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
assertEquals(FENCE_5[1].toString(), cipher.fence[1].toString());
|
||||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
assertEquals(FENCE_5[2].toString(), cipher.fence[2].toString());
|
||||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
assertEquals(FENCE_5[3].toString(), cipher.fence[3].toString());
|
||||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
assertEquals(FENCE_5[4].toString(), cipher.fence[4].toString());
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_5Clean(){
|
public void testPracticalDecoding_5Clean(){
|
||||||
cipher = new RailFence(false, false, false);
|
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(ENCODED_STRING_5_CLEAN, cipher.inputString);
|
||||||
assertEquals(fence5.length, cipher.fence.length);
|
assertEquals(FENCE_5.length, cipher.fence.length);
|
||||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
assertEquals(FENCE_5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
assertEquals(FENCE_5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
assertEquals(FENCE_5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
assertEquals(FENCE_5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
assertEquals(FENCE_5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
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;
|
package com.mattrixwv.cipherstream.polysubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -32,19 +28,19 @@ public class TrifidTest{
|
|||||||
@Mock
|
@Mock
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
//Fields
|
//Fields
|
||||||
private static final String decodedString = "Message to^encode+";
|
private static final String DECODED_STRING = "Message to^encode+";
|
||||||
private static final String decodedStringClean = "MESSAGETOENCODE+";
|
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE+";
|
||||||
private static final String decodedStringCleanAlt = "MESSAGETOENCODE";
|
private static final String DECODED_STRING_CLEAN_ALT = "MESSAGETOENCODE";
|
||||||
private static final String encodedString = "Gqdokxy eg^ranmoqr";
|
private static final String ENCODED_STRING = "Gqdokxy eg^ranmoqr";
|
||||||
private static final String encodedStringAlt = "Gqdokpd od^ljvflf+";
|
private static final String ENCODED_STRING_ALT = "Gqdokpd od^ljvflf+";
|
||||||
private static final String encodedString3 = "Gpjqdvd of^odlklf+";
|
private static final String ENCODED_STRING_3 = "Gpjqdvd of^odlklf+";
|
||||||
private static final String encodedStringClean = "GQDOKXYEGRANMOQR";
|
private static final String ENCODED_STRING_CLEAN = "GQDOKXYEGRANMOQR";
|
||||||
private static final String encodedStringCleanAlt = "GQDOKPDODLJVFLF";
|
private static final String ENCODED_STRING_CLEAN_ALT = "GQDOKPDODLJVFLF";
|
||||||
private static final String encodedStringClean3 = "GPJQDVDOFODLKLF+";
|
private static final String ENCODED_STRING_CLEAN_3 = "GPJQDVDOFODLKLF+";
|
||||||
private static final String keyword = "ke yw*ord";
|
private static final String KEYWORD = "ke yw*ord";
|
||||||
private static final String keywordClean = "KEYWORDABCFGHIJLMNPQSTUVXZ+";
|
private static final String KEYWORD_CLEAN = "KEYWORDABCFGHIJLMNPQSTUVXZ+";
|
||||||
private static final String keywordCleanAlt = "KEYWORDABCFGHIJLMNPQSTUVXZ=";
|
private static final String KEYWORD_CLEAN_ALT = "KEYWORDABCFGHIJLMNPQSTUVXZ=";
|
||||||
private static final char[][][] grid = new char[][][]{
|
private static final char[][][] GRID = new char[][][]{
|
||||||
{
|
{
|
||||||
{'K', 'E', 'Y'},
|
{'K', 'E', 'Y'},
|
||||||
{'W', 'O', 'R'},
|
{'W', 'O', 'R'},
|
||||||
@@ -61,8 +57,8 @@ public class TrifidTest{
|
|||||||
{'X', 'Z', '+'}
|
{'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 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[][][] gridAlt = new char[][][]{
|
private static final char[][][] GRID_ALT = new char[][][]{
|
||||||
{
|
{
|
||||||
{'K', 'E', 'Y'},
|
{'K', 'E', 'Y'},
|
||||||
{'W', 'O', 'R'},
|
{'W', 'O', 'R'},
|
||||||
@@ -226,16 +222,16 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetKeyword(){
|
public void testSetKeyword(){
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(KEYWORD);
|
||||||
|
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
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 case");
|
||||||
verify(logger, times(1)).debug("Removing all invalid characters");
|
verify(logger, times(1)).debug("Removing all invalid characters");
|
||||||
verify(logger, times(1)).debug("Appending entire alphabet to keyword");
|
verify(logger, times(1)).debug("Appending entire alphabet to keyword");
|
||||||
verify(logger, times(1)).debug("Removing duplicate characters");
|
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
|
@Test
|
||||||
@@ -287,13 +283,13 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setCreateGrid(){
|
public void setCreateGrid(){
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
|
|
||||||
cipher.createGrid();
|
cipher.createGrid();
|
||||||
|
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
verify(logger, times(1)).debug("Creating grid from keyword");
|
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
|
@Test
|
||||||
@@ -320,14 +316,14 @@ public class TrifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -336,14 +332,14 @@ public class TrifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
assertEquals(DECODED_STRING.toUpperCase(), 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 case");
|
verify(logger, times(1)).debug("Removing case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -352,14 +348,14 @@ public class TrifidTest{
|
|||||||
cipher.preserveWhitespace = false;
|
cipher.preserveWhitespace = false;
|
||||||
cipher.preserveSymbols = true;
|
cipher.preserveSymbols = true;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("\\s", ""), 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 case");
|
||||||
verify(logger, times(1)).debug("Removing whitespace");
|
verify(logger, times(1)).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -370,11 +366,11 @@ public class TrifidTest{
|
|||||||
cipher.fillIn = ' ';
|
cipher.fillIn = ' ';
|
||||||
|
|
||||||
assertThrows(InvalidInputException.class, () -> {
|
assertThrows(InvalidInputException.class, () -> {
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("", cipher.inputString);
|
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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, never()).debug("Removing symbols");
|
verify(logger, never()).debug("Removing symbols");
|
||||||
@@ -387,14 +383,14 @@ public class TrifidTest{
|
|||||||
cipher.preserveWhitespace = true;
|
cipher.preserveWhitespace = true;
|
||||||
cipher.preserveSymbols = false;
|
cipher.preserveSymbols = false;
|
||||||
|
|
||||||
cipher.setInputString(decodedString);
|
cipher.setInputString(DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s+]", ""), cipher.inputString);
|
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s+]", ""), 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 case");
|
||||||
verify(logger, never()).debug("Removing whitespace");
|
verify(logger, never()).debug("Removing whitespace");
|
||||||
verify(logger, times(1)).debug("Removing symbols");
|
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
|
@Test
|
||||||
@@ -435,17 +431,17 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanInputString(){
|
public void testGetCleanInputString(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
|
|
||||||
String returnedInput = cipher.getCleanInputString();
|
String returnedInput = cipher.getCleanInputString();
|
||||||
|
|
||||||
assertEquals(decodedStringClean, returnedInput);
|
assertEquals(DECODED_STRING_CLEAN, returnedInput);
|
||||||
verify(logger, times(1)).debug("Cleaning input string for encoding");
|
verify(logger, times(1)).debug("Cleaning input string for encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar(){
|
public void testFindChar(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
CharLocation returnedLocation = cipher.findChar('G');
|
CharLocation returnedLocation = cipher.findChar('G');
|
||||||
|
|
||||||
@@ -456,7 +452,7 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindChar_invalid(){
|
public void testFindChar_invalid(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertThrows(InvalidCharacterException.class, () -> {
|
assertThrows(InvalidCharacterException.class, () -> {
|
||||||
cipher.findChar('=');
|
cipher.findChar('=');
|
||||||
@@ -468,7 +464,7 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetChar(){
|
public void testGetChar(){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
char returnedChar = cipher.getChar(cipher.new CharLocation(0, 1, 2));
|
char returnedChar = cipher.getChar(cipher.new CharLocation(0, 1, 2));
|
||||||
|
|
||||||
@@ -483,7 +479,7 @@ public class TrifidTest{
|
|||||||
"0, 1, 3"
|
"0, 1, 3"
|
||||||
})
|
})
|
||||||
public void testGetChar_invalidLocation(int x, int y, int z){
|
public void testGetChar_invalidLocation(int x, int y, int z){
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
CharLocation location = cipher.new CharLocation(x, y, z);
|
CharLocation location = cipher.new CharLocation(x, y, z);
|
||||||
|
|
||||||
assertThrows(InvalidCharacterException.class, () -> {
|
assertThrows(InvalidCharacterException.class, () -> {
|
||||||
@@ -496,47 +492,47 @@ public class TrifidTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testFormatOutput(){
|
public void testFormatOutput(){
|
||||||
cipher.preserveCapitals = true;
|
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(1)).debug("Formatting output");
|
||||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(1)).debug("Formatting uppercase");
|
verify(logger, times(1)).debug("Formatting uppercase");
|
||||||
verify(logger, times(14)).debug("Formatting lowercase");
|
verify(logger, times(14)).debug("Formatting lowercase");
|
||||||
verify(logger, times(1)).debug("Adding fillIn");
|
verify(logger, times(1)).debug("Adding fillIn");
|
||||||
verify(logger, times(2)).debug("Appending symbol");
|
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
|
@Test
|
||||||
public void testFormatOutput_noCapitals(){
|
public void testFormatOutput_noCapitals(){
|
||||||
cipher.preserveCapitals = false;
|
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(1)).debug("Formatting output");
|
||||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||||
verify(logger, times(15)).debug("Formatting uppercase");
|
verify(logger, times(15)).debug("Formatting uppercase");
|
||||||
verify(logger, never()).debug("Formatting lowercase");
|
verify(logger, never()).debug("Formatting lowercase");
|
||||||
verify(logger, times(1)).debug("Adding fillIn");
|
verify(logger, times(1)).debug("Adding fillIn");
|
||||||
verify(logger, times(2)).debug("Appending symbol");
|
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
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||||
@@ -548,14 +544,14 @@ public class TrifidTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testEncode_3(){
|
public void testEncode_3(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
cipher.groupSize = 3;
|
cipher.groupSize = 3;
|
||||||
|
|
||||||
cipher.encode();
|
cipher.encode();
|
||||||
|
|
||||||
assertEquals(encodedString3, cipher.outputString);
|
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Encoding");
|
verify(logger, times(1)).debug("Encoding");
|
||||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||||
@@ -567,13 +563,13 @@ public class TrifidTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testDecode(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = encodedString;
|
cipher.inputString = ENCODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||||
@@ -585,14 +581,14 @@ public class TrifidTest{
|
|||||||
@Test
|
@Test
|
||||||
public void testDecode_3(){
|
public void testDecode_3(){
|
||||||
cipher.preserveCapitals = true;
|
cipher.preserveCapitals = true;
|
||||||
cipher.inputString = encodedString3;
|
cipher.inputString = ENCODED_STRING_3;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
cipher.groupSize = 3;
|
cipher.groupSize = 3;
|
||||||
|
|
||||||
cipher.decode();
|
cipher.decode();
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
verify(logger, times(1)).debug("Decoding");
|
verify(logger, times(1)).debug("Decoding");
|
||||||
verify(logger, times(1)).debug("Converting letters to coordinates");
|
verify(logger, times(1)).debug("Converting letters to coordinates");
|
||||||
verify(logger, times(1)).debug("Splitting locations into groups");
|
verify(logger, times(1)).debug("Splitting locations into groups");
|
||||||
@@ -603,28 +599,28 @@ public class TrifidTest{
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetters(){
|
public void testGetters(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keywordClean;
|
cipher.keyword = KEYWORD_CLEAN;
|
||||||
cipher.groupSize = 3;
|
cipher.groupSize = 3;
|
||||||
cipher.fillIn = '=';
|
cipher.fillIn = '=';
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.getInputString());
|
assertEquals(DECODED_STRING, cipher.getInputString());
|
||||||
assertEquals(encodedString, cipher.getOutputString());
|
assertEquals(ENCODED_STRING, cipher.getOutputString());
|
||||||
assertEquals(keywordClean, cipher.getKeyword());
|
assertEquals(KEYWORD_CLEAN, cipher.getKeyword());
|
||||||
assertEquals(3, cipher.getGroupSize());
|
assertEquals(3, cipher.getGroupSize());
|
||||||
assertEquals('=', cipher.getFillIn());
|
assertEquals('=', cipher.getFillIn());
|
||||||
assertEquals(gridString, cipher.getGrid());
|
assertEquals(GRID_STRING, cipher.getGrid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset(){
|
public void testReset(){
|
||||||
cipher.inputString = decodedString;
|
cipher.inputString = DECODED_STRING;
|
||||||
cipher.outputString = encodedString;
|
cipher.outputString = ENCODED_STRING;
|
||||||
cipher.keyword = keyword;
|
cipher.keyword = KEYWORD;
|
||||||
cipher.groupSize = 3;
|
cipher.groupSize = 3;
|
||||||
cipher.grid = grid;
|
cipher.grid = GRID;
|
||||||
|
|
||||||
cipher.reset();
|
cipher.reset();
|
||||||
|
|
||||||
@@ -639,155 +635,155 @@ public class TrifidTest{
|
|||||||
public void testPracticalEncoding(){
|
public void testPracticalEncoding(){
|
||||||
cipher = new Trifid(true, true, true);
|
cipher = new Trifid(true, true, true);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString, cipher.outputString);
|
assertEquals(ENCODED_STRING, cipher.outputString);
|
||||||
assertEquals(encodedString, output);
|
assertEquals(ENCODED_STRING, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_3(){
|
public void testPracticalEncoding_3(){
|
||||||
cipher = new Trifid(true, true, true);
|
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(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedString3, cipher.outputString);
|
assertEquals(ENCODED_STRING_3, cipher.outputString);
|
||||||
assertEquals(encodedString3, output);
|
assertEquals(ENCODED_STRING_3, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_fill(){
|
public void testPracticalEncoding_fill(){
|
||||||
cipher = new Trifid(true, true, true, '=');
|
cipher = new Trifid(true, true, true, '=');
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedString, cipher.inputString);
|
assertEquals(DECODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||||
assertEquals(encodedStringAlt, cipher.outputString);
|
assertEquals(ENCODED_STRING_ALT, cipher.outputString);
|
||||||
assertEquals(encodedStringAlt, output);
|
assertEquals(ENCODED_STRING_ALT, output);
|
||||||
assertArrayEquals(gridAlt, cipher.grid);
|
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean(){
|
public void testPracticalEncoding_clean(){
|
||||||
cipher = new Trifid(false, false, false);
|
cipher = new Trifid(false, false, false);
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringClean, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(encodedStringClean, output);
|
assertEquals(ENCODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_clean3(){
|
public void testPracticalEncoding_clean3(){
|
||||||
cipher = new Trifid(false, false, false);
|
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(DECODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(encodedStringClean3, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN_3, cipher.outputString);
|
||||||
assertEquals(encodedStringClean3, output);
|
assertEquals(ENCODED_STRING_CLEAN_3, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalEncoding_cleanFill(){
|
public void testPracticalEncoding_cleanFill(){
|
||||||
cipher = new Trifid(false, false, false, '=');
|
cipher = new Trifid(false, false, false, '=');
|
||||||
|
|
||||||
String output = cipher.encode(keyword, decodedString);
|
String output = cipher.encode(KEYWORD, DECODED_STRING);
|
||||||
|
|
||||||
assertEquals(decodedStringCleanAlt, cipher.inputString);
|
assertEquals(DECODED_STRING_CLEAN_ALT, cipher.inputString);
|
||||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||||
assertEquals(encodedStringCleanAlt, cipher.outputString);
|
assertEquals(ENCODED_STRING_CLEAN_ALT, cipher.outputString);
|
||||||
assertEquals(encodedStringCleanAlt, output);
|
assertEquals(ENCODED_STRING_CLEAN_ALT, output);
|
||||||
assertArrayEquals(gridAlt, cipher.grid);
|
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding(){
|
public void testPracticalDecoding(){
|
||||||
cipher = new Trifid(true, true, true);
|
cipher = new Trifid(true, true, true);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedString, cipher.inputString);
|
assertEquals(ENCODED_STRING, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_3(){
|
public void testPracticalDecoding_3(){
|
||||||
cipher = new Trifid(true, true, true);
|
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(ENCODED_STRING_3, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_fill(){
|
public void testPracticalDecoding_fill(){
|
||||||
cipher = new Trifid(true, true, true, '=');
|
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(ENCODED_STRING_ALT, cipher.inputString);
|
||||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||||
assertEquals(decodedString, cipher.outputString);
|
assertEquals(DECODED_STRING, cipher.outputString);
|
||||||
assertEquals(decodedString, output);
|
assertEquals(DECODED_STRING, output);
|
||||||
assertArrayEquals(gridAlt, cipher.grid);
|
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testpracticalDecoding_clean(){
|
public void testpracticalDecoding_clean(){
|
||||||
cipher = new Trifid(false, false, false);
|
cipher = new Trifid(false, false, false);
|
||||||
|
|
||||||
String output = cipher.decode(keyword, encodedString);
|
String output = cipher.decode(KEYWORD, ENCODED_STRING);
|
||||||
|
|
||||||
assertEquals(encodedStringClean, cipher.inputString);
|
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_clean3(){
|
public void testPracticalDecoding_clean3(){
|
||||||
cipher = new Trifid(false, false, false);
|
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(ENCODED_STRING_CLEAN_3, cipher.inputString);
|
||||||
assertEquals(keywordClean, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN, cipher.keyword);
|
||||||
assertEquals(decodedStringClean, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
|
||||||
assertEquals(decodedStringClean, output);
|
assertEquals(DECODED_STRING_CLEAN, output);
|
||||||
assertArrayEquals(grid, cipher.grid);
|
assertArrayEquals(GRID, cipher.grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPracticalDecoding_cleanFill(){
|
public void testPracticalDecoding_cleanFill(){
|
||||||
cipher = new Trifid(false, false, false, '=');
|
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(ENCODED_STRING_CLEAN_ALT, cipher.inputString);
|
||||||
assertEquals(keywordCleanAlt, cipher.keyword);
|
assertEquals(KEYWORD_CLEAN_ALT, cipher.keyword);
|
||||||
assertEquals(decodedStringCleanAlt, cipher.outputString);
|
assertEquals(DECODED_STRING_CLEAN_ALT, cipher.outputString);
|
||||||
assertEquals(decodedStringCleanAlt, output);
|
assertEquals(DECODED_STRING_CLEAN_ALT, output);
|
||||||
assertArrayEquals(gridAlt, cipher.grid);
|
assertArrayEquals(GRID_ALT, cipher.grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user