// performs rail fence cipher encryption, keeping spaces pub fn encrypt(input: &str, key: i32) -> String { let vec_len = input.len() / key as usize + 1; let mut fence: Vec> = vec![vec![' '; vec_len]; key as usize]; let mut rail: i32 = 0; let mut dir: i32 = 1; for c in input.chars() { let column_index = fence[rail as usize].iter().position(|&x| x == ' ').unwrap(); println!("fernce: {:?}", fence); fence[rail as usize][column_index] = c; rail += dir; if rail == 0 || rail == key as i32 - 1 { dir = -dir; } } let mut result = String::new(); for rail in fence { for c in rail { if c != ' ' { result.push(c); } } } result }