Skip to content

Instantly share code, notes, and snippets.

@ufo22940268
Created August 5, 2021 10:04
Show Gist options
  • Save ufo22940268/1bc89a70079215b2d789bdf95337504c to your computer and use it in GitHub Desktop.
Save ufo22940268/1bc89a70079215b2d789bdf95337504c 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 < n; i++ {
if p[i] >= 65 && p[i] < (97+26) {
if p[i] < 97 {
p[i] = 65 + (p[i]-65+13)%26
} else {
p[i] = 97 + (p[i]-97+13)%26
}
}
}
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