Skip to content

Instantly share code, notes, and snippets.

@poppen
Last active June 15, 2016 08:40
Show Gist options
  • Save poppen/f6200450d68038537c3e26efef3c4826 to your computer and use it in GitHub Desktop.
Save poppen/f6200450d68038537c3e26efef3c4826 to your computer and use it in GitHub Desktop.
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