Last active
June 15, 2016 08:40
-
-
Save poppen/f6200450d68038537c3e26efef3c4826 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"io" | |
"os" | |
"strings" | |
) | |
type rot13Reader struct { | |
r io.Reader | |
} | |
func (r *rot13Reader) Read(b []byte) (int, error) { | |
l, e := r.r.Read(b) | |
for i, c := range b { | |
if c == ' ' || c == '!' { | |
continue | |
} | |
if ('a' <= c && c <= 'm') || ('A' <= c && c <= 'M') { | |
b[i] = c + 13 | |
} else { | |
b[i] = c - 13 | |
} | |
} | |
return l, e | |
} | |
func main() { | |
s := strings.NewReader("Lbh penpxrq gur pbqr!") | |
r := rot13Reader{s} | |
io.Copy(os.Stdout, &r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment