From 1114d336b152fb6b2f58f5a8bf0132346d17ad5c Mon Sep 17 00:00:00 2001 From: 0xprincedev Date: Wed, 5 Nov 2025 21:27:59 -0500 Subject: [PATCH 1/3] Fixed typos in src/ciphers/kernighan.rs and mod.rs --- src/ciphers/kernighan.rs | 24 ++++++++++++++++++++++++ src/ciphers/kerninghan.rs | 23 ----------------------- src/ciphers/mod.rs | 4 ++-- 3 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 src/ciphers/kernighan.rs delete mode 100644 src/ciphers/kerninghan.rs diff --git a/src/ciphers/kernighan.rs b/src/ciphers/kernighan.rs new file mode 100644 index 00000000000..399c76e8f27 --- /dev/null +++ b/src/ciphers/kernighan.rs @@ -0,0 +1,24 @@ +pub fn kernighan(n: u32) -> i32 { + let mut count = 0; + let mut n = n; + + while n > 0 { + n = n & (n - 1); + count += 1; + } + + count +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn count_set_bits() { + assert_eq!(kernighan(0b0000_0000_0000_0000_0000_0000_0000_1011), 3); + assert_eq!(kernighan(0b0000_0000_0000_0000_0000_0000_1000_0000), 1); + assert_eq!(kernighan(0b1111_1111_1111_1111_1111_1111_1111_1101), 31); + } +} + diff --git a/src/ciphers/kerninghan.rs b/src/ciphers/kerninghan.rs deleted file mode 100644 index 4263850ff3f..00000000000 --- a/src/ciphers/kerninghan.rs +++ /dev/null @@ -1,23 +0,0 @@ -pub fn kerninghan(n: u32) -> i32 { - let mut count = 0; - let mut n = n; - - while n > 0 { - n = n & (n - 1); - count += 1; - } - - count -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn count_set_bits() { - assert_eq!(kerninghan(0b0000_0000_0000_0000_0000_0000_0000_1011), 3); - assert_eq!(kerninghan(0b0000_0000_0000_0000_0000_0000_1000_0000), 1); - assert_eq!(kerninghan(0b1111_1111_1111_1111_1111_1111_1111_1101), 31); - } -} diff --git a/src/ciphers/mod.rs b/src/ciphers/mod.rs index f7a55b0014d..1c5af11ea37 100644 --- a/src/ciphers/mod.rs +++ b/src/ciphers/mod.rs @@ -7,7 +7,7 @@ mod caesar; mod chacha; mod diffie_hellman; mod hashing_traits; -mod kerninghan; +mod kernighan; mod morse_code; mod polybius; mod rail_fence; @@ -30,7 +30,7 @@ pub use self::chacha::chacha20; pub use self::diffie_hellman::DiffieHellman; pub use self::hashing_traits::Hasher; pub use self::hashing_traits::HMAC; -pub use self::kerninghan::kerninghan; +pub use self::kernighan::kernighan; pub use self::morse_code::{decode, encode}; pub use self::polybius::{decode_ascii, encode_ascii}; pub use self::rail_fence::{rail_fence_decrypt, rail_fence_encrypt}; From 43a7d85e55f2a118e95894f2784f766d118dc8a6 Mon Sep 17 00:00:00 2001 From: 0xprincedev Date: Wed, 5 Nov 2025 21:34:33 -0500 Subject: [PATCH 2/3] fixed typos in DICTIONARY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 46bb2a3af9f..37794c2ec3c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -31,7 +31,7 @@ * [Chacha](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/chacha.rs) * [Diffie Hellman](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/diffie_hellman.rs) * [Hashing Traits](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/hashing_traits.rs) - * [Kerninghan](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/kerninghan.rs) + * [Kernighan](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/kernighan.rs) * [Morse Code](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/morse_code.rs) * [Polybius](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/polybius.rs) * [Rail Fence](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/rail_fence.rs) From 3d0c625536a3a241e46757726dc5b238e9bb180f Mon Sep 17 00:00:00 2001 From: 0xprincedev Date: Wed, 5 Nov 2025 21:42:48 -0500 Subject: [PATCH 3/3] . --- src/ciphers/kernighan.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ciphers/kernighan.rs b/src/ciphers/kernighan.rs index 399c76e8f27..c8144990fa2 100644 --- a/src/ciphers/kernighan.rs +++ b/src/ciphers/kernighan.rs @@ -21,4 +21,3 @@ mod tests { assert_eq!(kernighan(0b1111_1111_1111_1111_1111_1111_1111_1101), 31); } } -