Skip to content

Instantly share code, notes, and snippets.

@cgwalters
Created July 6, 2015 21:51
Show Gist options
  • Save cgwalters/c70586719578375acd6b to your computer and use it in GitHub Desktop.
Save cgwalters/c70586719578375acd6b to your computer and use it in GitHub Desktop.
package main
import (
"io"
"os"
"fmt"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (self rot13Reader) Read(b []byte) (int, error) {
r, err := self.Read(b)
if err != nil {
return 0, err
}
for i := 0; i < r; i++ {
orig := b[i]
fmt.Println("Processing ", orig)
break
var base byte
if orig >= 'A' && orig <= 'Z' {
base = 'A'
} else if orig >= 'a' && orig <= 'a' {
base = 'a'
} else {
continue
}
off := (orig - base)
newoff := (off + 13) % 26
b[i] = base + newoff
}
return r, nil
}
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