Created
December 30, 2013 00:23
-
-
Save tarsisazevedo/8176359 to your computer and use it in GitHub Desktop.
This file contains 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 (rot13 rot13Reader) Read(p []byte) (n int, err error) { | |
n,err = rot13.r.Read(p) | |
for i := 0; i < len(p); i++ { | |
if (p[i] >= 'A' && p[i] < 'N') || (p[i] >='a' && p[i] < 'n') { | |
p[i] += 13 | |
} else if (p[i] > 'M' && p[i] <= 'Z') || (p[i] > 'm' && p[i] <= 'z'){ | |
p[i] -= 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