Class XORCipher
- java.lang.Object
-
- com.github.alex1304.jdash.util.robtopsweakcrypto.XORCipher
-
public class XORCipher extends Object
Implementation of the XOR Cipher algorithm. It's done by performing cyclically a XOR operation on the ASCII code of each character between the message and a key. See https://en.wikipedia.org/wiki/XOR_cipher
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
cipher(String message)
Ciphers the message using the key provided on the object instanciation.static String
findKey(String messagePlain, String messageCipher)
Retrieves the key by performing a XOR cipher between the plaintext message and the ciphered message.
-
-
-
Constructor Detail
-
XORCipher
public XORCipher(String key)
Constructs a new XORCipher with a provided key- Parameters:
key
- - the key- Throws:
IllegalArgumentException
- if the key is an empty string or null
-
-
Method Detail
-
cipher
public String cipher(String message)
Ciphers the message using the key provided on the object instanciation.- Parameters:
message
- - the message to cipher- Returns:
- the ciphered message as String
-
findKey
public static String findKey(String messagePlain, String messageCipher)
Retrieves the key by performing a XOR cipher between the plaintext message and the ciphered message. It's strongly recommended to ensure that both parameters have the same length, or else the key might not be the one expected.- Parameters:
messagePlain
- - the plaintext messagemessageCipher
- - the ciphered message- Returns:
- the shortest possible key as String
- Throws:
IllegalArgumentException
- if one of the parameters are empty strings or null
-
-