Skip to content

Instantly share code, notes, and snippets.

@siisee11
Created December 31, 2019 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siisee11/bf57a6f447d90d07f31268b0fe554f19 to your computer and use it in GitHub Desktop.
Save siisee11/bf57a6f447d90d07f31268b0fe554f19 to your computer and use it in GitHub Desktop.
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