From bbebf73cbae52b0ecd643dd193ec0236849ee9ca Mon Sep 17 00:00:00 2001 From: ScriptAndCompile Date: Tue, 11 Jun 2024 11:29:34 -0700 Subject: [PATCH 1/2] Added documentation to xor.rs --- src/ciphers/xor.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ciphers/xor.rs b/src/ciphers/xor.rs index 0f4233a..915b859 100644 --- a/src/ciphers/xor.rs +++ b/src/ciphers/xor.rs @@ -1,3 +1,23 @@ +/// 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 +32,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)); - } } From a613251f7331cd7be82c5817f0578bd49904224e Mon Sep 17 00:00:00 2001 From: Alexander Gonzalez Date: Tue, 11 Jun 2024 20:45:22 +0200 Subject: [PATCH 2/2] ref: add blank line between header & code block --- src/ciphers/xor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ciphers/xor.rs b/src/ciphers/xor.rs index 915b859..6284263 100644 --- a/src/ciphers/xor.rs +++ b/src/ciphers/xor.rs @@ -10,6 +10,7 @@ /// * A String that holds the ciphered text. /// /// # Example +/// /// ```rust /// use rust_algorithms::ciphers::xor; ///