style: format code (#4212)

close #4204
This commit is contained in:
acbin
2023-06-09 18:52:05 +08:00
committed by GitHub
parent ad03086f54
commit 00282efd8b
521 changed files with 5233 additions and 7309 deletions

View File

@ -10,29 +10,29 @@ class BlowfishTest {
@Test
void testEncrypt() {
//given
// given
String plainText = "123456abcd132536";
String key = "aabb09182736ccdd";
String expectedOutput = "d748ec383d3405f7";
//when
// when
String cipherText = blowfish.encrypt(plainText, key);
//then
// then
assertEquals(expectedOutput, cipherText);
}
@Test
void testDecrypt() {
//given
// given
String cipherText = "d748ec383d3405f7";
String key = "aabb09182736ccdd";
String expectedOutput = "123456abcd132536";
//when
// when
String plainText = blowfish.decrypt(cipherText, key);
//then
// then
assertEquals(expectedOutput, plainText);
}
}

View File

@ -1,9 +1,9 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CaesarTest {
Caesar caesar = new Caesar();
@ -43,5 +43,4 @@ class CaesarTest {
assertEquals(27, allPossibleAnswers.length);
assertEquals("Encrypt this text", allPossibleAnswers[5]);
}
}

View File

@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
//Test example taken from https://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm
// Test example taken from https://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm
public class DESTest {
DES des;
@ -17,35 +17,40 @@ public class DESTest {
@Test
void testEncrypt() {
//given
// given
String plainText = "Your lips are smoother than vaseline\r\n";
//This is equal to c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in hexadecimal
String expectedOutput = "11000000100110011001111111011101111000110111100011010111111" +
"011010111001001111101101000000000101111001010010110101000010011101110010001111111001" +
"001101001101001001101011001000011100000011001000011011001110101010010111101111000111" +
"101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
// This is equal to
// c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in
// hexadecimal
String expectedOutput = "11000000100110011001111111011101111000110111100011010111111"
+ "011010111001001111101101000000000101111001010010110101000010011101110010001111111001"
+ "001101001101001001101011001000011100000011001000011011001110101010010111101111000111"
+ "101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
//when
// when
String cipherText = des.encrypt(plainText);
//then
// then
assertEquals(expectedOutput, cipherText);
}
@Test
void testDecrypt() {
//given
//This is equal to c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in hexadecimal
String cipherText = "11000000100110011001111111011101111000110111100011010111111" +
"011010111001001111101101000000000101111001010010110101000010011101110010001111111001" +
"001101001101001001101011001000011100000011001000011011001110101010010111101111000111" +
"101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
String expectedOutput = "Your lips are smoother than vaseline\r\n";;
// given
// This is equal to
// c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in
// hexadecimal
String cipherText = "11000000100110011001111111011101111000110111100011010111111"
+ "011010111001001111101101000000000101111001010010110101000010011101110010001111111001"
+ "001101001101001001101011001000011100000011001000011011001110101010010111101111000111"
+ "101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
String expectedOutput = "Your lips are smoother than vaseline\r\n";
;
//when
// when
String plainText = des.decrypt(cipherText);
//then
// then
assertEquals(expectedOutput, plainText);
}
}

View File

@ -1,9 +1,9 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class RSATest {
RSA rsa = new RSA(1024);
@ -20,5 +20,4 @@ class RSATest {
// then
assertEquals("Such secure", decryptedText);
}
}

View File

@ -1,9 +1,9 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class SimpleSubCipherTest {
SimpleSubCipher simpleSubCipher = new SimpleSubCipher();
@ -33,5 +33,4 @@ class SimpleSubCipherTest {
// then
assertEquals("defend the east wall of the castle", decryptedText);
}
}

View File

@ -1,9 +1,9 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class SimpleSubstitutionCipherTest {
@Test

View File

@ -1,9 +1,9 @@
package com.thealgorithms.ciphers;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class VigenereTest {
Vigenere vigenere = new Vigenere();
@ -33,5 +33,4 @@ class VigenereTest {
// then
assertEquals("Hello World!", decryptedText);
}
}

View File

@ -23,7 +23,7 @@ class LFSRTest {
};
// Represents 11 1010 1011 0011 1100 1011
byte[] frameCounterBytes = { (byte) 203, (byte) 179, 58 };
byte[] frameCounterBytes = {(byte) 203, (byte) 179, 58};
@Test
void initialize() {
@ -46,7 +46,7 @@ class LFSRTest {
expected.set(16);
expected.set(17);
LFSR lfsr0 = new LFSR(19, 8, new int[] { 13, 16, 17, 18 });
LFSR lfsr0 = new LFSR(19, 8, new int[] {13, 16, 17, 18});
lfsr0.initialize(sessionKey, frameCounter);
assertEquals(expected.toString(), lfsr0.toString());
}
@ -56,7 +56,7 @@ class LFSRTest {
BitSet sessionKey = BitSet.valueOf(sessionKeyBytes);
BitSet frameCounter = BitSet.valueOf(frameCounterBytes);
LFSR lfsr0 = new LFSR(19, 8, new int[] { 13, 16, 17, 18 });
LFSR lfsr0 = new LFSR(19, 8, new int[] {13, 16, 17, 18});
lfsr0.initialize(sessionKey, frameCounter);
BitSet expected = new BitSet(19);
@ -85,7 +85,7 @@ class LFSRTest {
BitSet sessionKey = BitSet.valueOf(sessionKeyBytes);
BitSet frameCounter = BitSet.valueOf(frameCounterBytes);
LFSR lfsr0 = new LFSR(19, 8, new int[] { 13, 16, 17, 18 });
LFSR lfsr0 = new LFSR(19, 8, new int[] {13, 16, 17, 18});
assertFalse(lfsr0.getClockBit());