happy-cracking 0.5.0

A fast, comprehensive CTF toolkit for cryptographic encoding/decoding, classic ciphers, hash operations, and analysis tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Shared utility functions used by multiple cipher modules.

// Compute column ordering from a keyword for columnar transposition.
// Returns a vector where order[i] is the rank of column i.
pub fn column_order(key: &str) -> Vec<usize> {
    let key_upper: Vec<char> = key.to_uppercase().chars().collect();
    let mut indices: Vec<usize> = (0..key_upper.len()).collect();
    indices.sort_by(|&a, &b| key_upper[a].cmp(&key_upper[b]).then(a.cmp(&b)));

    let mut order = vec![0; key_upper.len()];
    for (rank, &idx) in indices.iter().enumerate() {
        order[idx] = rank;
    }
    order
}