Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rot13Reader
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (rot *rot13Reader) Read(buf []byte) (n int, e error) {
n, e = rot.r.Read(buf)
for i:= 0; i < len(buf); i++ {
c := buf[i]
if (c >= 'A' && c <= 'N') || (c >= 'a' && c < 'n') {
buf[i] += 13
} else if (c >= 'M' && c <= 'Z') || (c >= 'm' && c <= 'z') {
buf[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