Sha256: 897583634fd288d7094f49f99f935c07e58eb185a31cb7148b0173b07729bd8d
Contents?: true
Size: 747 Bytes
Versions: 306
Compression:
Stored size: 747 Bytes
Contents
use std::ascii::AsciiExt; fn ascii(ch: char) -> u8 { ch as u8 } fn get_transpose(ch: char) -> char { if ch.is_digit(10) { ch } else { (ascii('z') - ascii(ch) + ascii('a')) as char } } pub fn encode(plaintext: &str) -> String { plaintext .to_lowercase() .chars() .filter(|&ch| ch.is_ascii()) .filter(|&ch| ch.is_alphanumeric()) .map(|ch| get_transpose(ch)) .collect::<Vec<char>>() .chunks(5) .map(|slice| slice.iter().cloned().collect::<String>()) .collect::<Vec<String>>() .join(" ") } pub fn decode(ciphertext: &str) -> String { ciphertext .split::<char>(' ') .collect::<String>() .chars() .map(|ch| get_transpose(ch)) .collect::<String>() }
Version data entries
306 entries across 306 versions & 1 rubygems