diff --git a/src/ciphers/xor.rs b/src/ciphers/xor.rs index 0f4233a..6284263 100644 --- a/src/ciphers/xor.rs +++ b/src/ciphers/xor.rs @@ -1,3 +1,24 @@ +/// XOR cipher +/// +/// # Arguments +/// +/// * `text` - A string slice that holds the text to be ciphered. +/// * `key` - A u8 that holds the key to be used for ciphering. +/// +/// # Returns +/// +/// * A String that holds the ciphered text. +/// +/// # Example +/// +/// ```rust +/// use rust_algorithms::ciphers::xor; +/// +/// let test_string = "The quick brown fox jumps over the lazy dog"; +/// let ciphered_text = xor(test_string, 64); +/// +/// assert_eq!(test_string, xor(&ciphered_text, 64)); +/// ``` pub fn xor(text: &str, key: u8) -> String { text.chars().map(|c| ((c as u8) ^ key) as char).collect() } @@ -12,11 +33,4 @@ mod tests { let ciphered_text = xor(test_string, 32); assert_eq!(test_string, xor(&ciphered_text, 32)); } - - #[test] - fn test_every_alphabet_with_space() { - let test_string = "The quick brown fox jumps over the lazy dog"; - let ciphered_text = xor(test_string, 64); - assert_eq!(test_string, xor(&ciphered_text, 64)); - } }