Skip to content

Instantly share code, notes, and snippets.

@evandertino
Created April 4, 2015 17:08
Show Gist options
  • Select an option

  • Save evandertino/037cd27095d12d06a222 to your computer and use it in GitHub Desktop.

Select an option

Save evandertino/037cd27095d12d06a222 to your computer and use it in GitHub Desktop.
GO Exercise: rot13Reader - http://tour.golang.org/methods/12
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (this *rot13Reader) Read(bytes []byte) (num int, err error) {
num, err = this.r.Read(bytes)
for index := range bytes {
if (bytes[index] >= 'A' && bytes[index] <= 'M') || (bytes[index] >='a' && bytes[index] <= 'm') {
bytes[index] += 13
} else if (bytes[index] >= 'N' && bytes[index] <= 'Z') || (bytes[index] >= 'n' && bytes[index] <= 'z'){
bytes[index] -= 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