Last active
January 2, 2016 16:49
-
-
Save hakobe/8332885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"os" | |
"strings" | |
) | |
type rot13Reader struct { | |
r io.Reader | |
} | |
func (r13 rot13Reader) Read(p []byte) (n int, e error) { | |
n, e = r13.r.Read(p) | |
if e != nil { | |
return | |
} | |
for i, v := range p { | |
if 'A' <= v && v <= 'Z' { | |
p[i] = ((v - 'A' + 13) % 26) + 'A' | |
} else if 'a' <= v && v <= 'z' { | |
p[i] = ((v - 'a' + 13) % 26) + 'a' | |
} | |
} | |
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