Skip to content

Instantly share code, notes, and snippets.

@heathhenley
Created March 28, 2020 03:25
Show Gist options
  • Save heathhenley/fbd48f4d09339d5c76c1971a75031c4e to your computer and use it in GitHub Desktop.
Save heathhenley/fbd48f4d09339d5c76c1971a75031c4e 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(b []byte) (int, error) {
n, error := r.r.Read(b)
for i := 0; i < n; i++ {
if (b[i] >= 'A') && (b[i] <= 'Z') {
b[i] += 13
if b[i] > 'Z' {
b[i] = 'A' + (b[i] - 'Z') - 1
}
} else if (b[i] >= 'a') && (b[i] <= 'z') {
b[i] += 13
if b[i] > 'z' {
b[i] = 'a' + (b[i] - 'z') - 1
}
}
}
return n, error
}
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