Skip to content

Instantly share code, notes, and snippets.

@jhackz
Last active May 1, 2020 03:55
Show Gist options
  • Save jhackz/0f111036f02e3919f65cf324fc609bd2 to your computer and use it in GitHub Desktop.
Save jhackz/0f111036f02e3919f65cf324fc609bd2 to your computer and use it in GitHub Desktop.
package main
import (
//"fmt"
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (r *rot13Reader) Read(b []byte) (n int, err error) {
n, err = r.r.Read(b)
for i := range b[:n] {
//fmt.Printf("b = %v\n", b)
if b[i] == 32 {
} else if b[i] < 78 || b[i] < 110 {
b[i] = b[i] + 13
} else if b[i] > 78 || b[i] > 110 {
b[i] = b[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