mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 09:45:04 +08:00
Add XOR Cipher (#5490)
This commit is contained in:
34
src/test/java/com/thealgorithms/ciphers/XORCipherTest.java
Normal file
34
src/test/java/com/thealgorithms/ciphers/XORCipherTest.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.thealgorithms.ciphers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class XORCipherTest {
|
||||
|
||||
@Test
|
||||
void xorEncryptTest() {
|
||||
// given
|
||||
String plaintext = "My t&xt th@t will be ençrypted...";
|
||||
String key = "My ç&cret key!";
|
||||
|
||||
// when
|
||||
String cipherText = XORCipher.encrypt(plaintext, key);
|
||||
|
||||
// then
|
||||
assertEquals("000000b7815e1752111c601f450e48211500a1c206061ca6d35212150d4429570eed", cipherText);
|
||||
}
|
||||
|
||||
@Test
|
||||
void xorDecryptTest() {
|
||||
// given
|
||||
String cipherText = "000000b7815e1752111c601f450e48211500a1c206061ca6d35212150d4429570eed";
|
||||
String key = "My ç&cret key!";
|
||||
|
||||
// when
|
||||
String plainText = XORCipher.decrypt(cipherText, key);
|
||||
|
||||
// then
|
||||
assertEquals("My t&xt th@t will be ençrypted...", plainText);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user