Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ciphers/hashing_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<const KEY_BYTES: usize, const DIGEST_BYTES: usize, H: Hasher<DIGEST_BYTES>>

#[cfg(test)]
mod tests {
use super::super::sha256::get_hash_string;
use super::super::sha256::tests::get_hash_string;
use super::super::SHA256;
use super::HMAC;

Expand Down
5 changes: 2 additions & 3 deletions src/ciphers/salsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ macro_rules! quarter_round {
};
}

#[allow(dead_code)]
pub const C: [u32; 4] = [0x65787061, 0x6e642033, 0x322d6279, 0x7465206b];

/**
* `salsa20` function takes as input an array of 16 32-bit integers (512 bits)
* of which 128 bits is the constant 'expand 32-byte k', 256 bits is the key,
Expand Down Expand Up @@ -86,6 +83,8 @@ mod tests {
use super::*;
use std::fmt::Write;

const C: [u32; 4] = [0x65787061, 0x6e642033, 0x322d6279, 0x7465206b];

fn output_hex(inp: &[u32; 16]) -> String {
let mut res = String::new();
res.reserve(512 / 4);
Expand Down
26 changes: 12 additions & 14 deletions src/ciphers/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* integer multiple of 8
*/

use std::fmt::Write;

// The constants are tested to make sure they are correct
pub const H0: [u32; 8] = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
Expand Down Expand Up @@ -100,17 +98,6 @@ fn process_block(h: &mut [u32; 8], w: &mut [u32; 64], round: &mut [u32; 8], buf:
}
}

#[allow(dead_code)]
// Let's keep this utility function
pub fn get_hash_string(hash: &[u8; 32]) -> String {
let mut result = String::new();
result.reserve(64);
for &ch in hash {
write!(&mut result, "{ch:02x}").unwrap();
}
result
}

impl SHA256 {
pub fn new_default() -> Self {
SHA256 {
Expand Down Expand Up @@ -219,9 +206,20 @@ impl super::Hasher<32> for SHA256 {
}

#[cfg(test)]
mod tests {
pub mod tests {
use super::*;
use crate::math::LinearSieve;
use std::fmt::Write;

// Let's keep this utility function
pub fn get_hash_string(hash: &[u8; 32]) -> String {
let mut result = String::new();
result.reserve(64);
for &ch in hash {
write!(&mut result, "{ch:02x}").unwrap();
}
result
}

#[test]
fn test_constants() {
Expand Down
50 changes: 0 additions & 50 deletions src/general/nqueens.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
#[allow(unused_imports)]
use std::env::args;

#[allow(dead_code)]
fn main() {
let mut board_width = 0;

for arg in args() {
board_width = match arg.parse() {
Ok(x) => x,
_ => 0,
};

if board_width != 0 {
break;
}
}

if board_width < 4 {
println!(
"Running algorithm with 8 as a default. Specify an alternative Chess board size for \
N-Queens as a command line argument.\n"
);
board_width = 8;
}

let board = match nqueens(board_width) {
Ok(success) => success,
Err(err) => panic!("{}", err),
};

println!("N-Queens {} by {} board result:", board_width, board_width);
print_board(&board);
}

/*
The n-Queens search is a backtracking algorithm. Each row of the Chess board where a Queen is
placed is dependent on all earlier rows. As only one Queen can fit per row, a one-dimensional
Expand Down Expand Up @@ -94,21 +59,6 @@ pub fn nqueens(board_width: i64) -> Result<Vec<i64>, &'static str> {
Ok(board_rows)
}

fn print_board(board: &[i64]) {
for row in 0..board.len() {
print!("{}\t", board[row as usize]);

for column in 0..board.len() as i64 {
if board[row as usize] == column {
print!("Q");
} else {
print!(".");
}
}
println!();
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down