Created
April 17, 2014 17:13
-
-
Save gbarrancos/10998867 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" | |
) | |
var rot13Map = []string { | |
"a", "n", | |
"n", "a", | |
"b", "o", | |
"o", "b", | |
"c", "p", | |
"p", "c", | |
"d", "q", | |
"q", "d", | |
"e", "r", | |
"r", "e", | |
"f", "s", | |
"s", "f", | |
"g", "t", | |
"t", "g", | |
"u", "h", | |
"h", "u", | |
"i", "v", | |
"v", "i", | |
"j", "w", | |
"w", "j", | |
"k", "x", | |
"x", "k", | |
"l", "y", | |
"y", "l", | |
"z", "m", | |
"m", "z", | |
} | |
type rot13Reader struct { | |
reader io.Reader | |
} | |
func (r *rot13Reader) Read(p []byte) (n int, err error) { | |
readbytes, err := r.reader.Read(p) | |
replacer := strings.NewReplacer(rot13Map...) | |
decodedString := replacer.Replace(string(p[:readbytes])) | |
copy(p, []byte(decodedString)) | |
return readbytes, 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