Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created February 25, 2014 14:24
Show Gist options
  • Save bgnori/9209758 to your computer and use it in GitHub Desktop.
Save bgnori/9209758 to your computer and use it in GitHub Desktop.
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (self *rot13Reader)Read(b []byte)(n int, err error) {
n, err = self.r.Read(b)
for i, c := range b {
switch {
case c < 'A':
case c < 'N':
b[i] = c+13
case c <= 'Z':
b[i] = c-13
case c < 'a':
case c < 'n':
b[i] = c+13
case c <= 'z':
b[i] = c-13
default:
}
}
return n, err
}
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