Caesar Cipher

  • + 0 comments

    My rust solution:

    fn caesarCipher(s: &str, k: u8) -> String {
        s.bytes()
            .map(|b| {
                if b.is_ascii_alphabetic() {
                    let first_letter = if b.is_ascii_lowercase() { b'a' } else { b'A' };
                    char::from((((b - first_letter) + k) % 26) + first_letter).to_string()
                } else {
                    char::from(b).to_string()
                }
            })
            .collect::<Vec<String>>()
            .join("")
    }