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

Version Path
trackler-2.2.1.91 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.90 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.89 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.88 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.87 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.86 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.85 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.84 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.83 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.82 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.81 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.80 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.79 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.78 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.77 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.76 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.75 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.74 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.73 tracks/rust/exercises/atbash-cipher/example.rs
trackler-2.2.1.72 tracks/rust/exercises/atbash-cipher/example.rs