Sha256: 665f1a6244ecfdc17b977027be1272ed0302d028a147f49b337cd0e333c9f99e

Contents?: true

Size: 720 Bytes

Versions: 86

Compression:

Stored size: 720 Bytes

Contents

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

86 entries across 86 versions & 1 rubygems

Version Path
trackler-2.2.1.179 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.178 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.177 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.176 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.175 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.174 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.173 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.172 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.171 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.170 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.169 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.167 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.166 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.165 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.164 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.163 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.162 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.161 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.160 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.159 tracks/rust/exercises/atbash-cipher/example.rs