Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Last active August 29, 2015 14:04
Show Gist options
  • Save ksomemo/3c6d5402f71ad7131425 to your computer and use it in GitHub Desktop.
Save ksomemo/3c6d5402f71ad7131425 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(p []byte) (n int, err error) {
n, err = r.r.Read(p)
for i := 0; i < len(p); i++ {
t := p[i]
if p[i] >= 'a' {
t = t - 'a'
} else {
t = t - 'A'
}
if t < 13 {
p[i] += 13
} else {
p[i] -= 13
}
}
return
}
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