Golang Rot13Reader Exercise
This exercise covers Golang reader interfaces using ROT-13 as an example.
package main import ( "io" "os" "strings" ) //This exercise covers: "rot13Reader" type rot13Reader struct { r io.Reader } func (r rot13Reader) Read(b []byte) (n int, err error) { count, err := r.r.Read(b) for i, x := range b { if (x > 'a' && x < 'z') { tmp := (x - 'a' + 13) % 26 b[i] = tmp + 'a' } else if (x > 'A' && x < 'Z') { tmp := (x - 'A' + 13) % 26 b[i] = tmp + 'A' } } return count, err } func main() { s := strings.NewReader("Lbh penpxrq gur pbqr!") r := rot13Reader{s} io.Copy(os.Stdout, &r) }

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here