Skip to content

Instantly share code, notes, and snippets.

@ysmolski
Created June 26, 2015 10:54
Show Gist options
  • Save ysmolski/7375c87a511ef99d8382 to your computer and use it in GitHub Desktop.
Save ysmolski/7375c87a511ef99d8382 to your computer and use it in GitHub Desktop.
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (r13 rot13Reader) Read(b []byte) (int, error) {
n, e := r13.r.Read(b)
for i := 0; i < n; i++ {
if 'A' <= b[i] && b[i] <= 'Z' {
b[i] = (b[i] - 'A' + 13) % 26 + 'A'
}
if 'a' <= b[i] && b[i] <= 'z' {
b[i] = (b[i] - 'a' + 13) % 26 + 'a'
}
}
return n, 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