Created
March 10, 2022 18:58
-
-
Save derrickturk/36e072e2f9e1c7721af8cd3407aae5da to your computer and use it in GitHub Desktop.
rot13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{self, BufRead}; | |
fn rot13(s: &str) -> String { | |
s.chars().map(|c| { | |
if c.is_ascii_lowercase() { | |
((c as u8 - b'a' + 13) % 26 + b'a') as char | |
} else if c.is_ascii_uppercase() { | |
((c as u8 - b'A' + 13) % 26 + b'A') as char | |
} else { | |
c | |
} | |
}).collect() | |
} | |
fn main() { | |
let stdin = io::stdin(); | |
let stdin = stdin.lock(); | |
for line in stdin.lines() { | |
let line = line.unwrap(); | |
println!("{}", rot13(&line)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment