Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created March 10, 2022 18:58
Show Gist options
  • Save derrickturk/36e072e2f9e1c7721af8cd3407aae5da to your computer and use it in GitHub Desktop.
Save derrickturk/36e072e2f9e1c7721af8cd3407aae5da to your computer and use it in GitHub Desktop.
rot13
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