Created
December 18, 2017 09:10
-
-
Save kidinamoto01/5f9a374d8ec9fdf471bc38b78a2eefee 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 | |
} | |
var rot13_upper = []byte("NOPQRSTUVWXYZABCDEFGHIJKLM") | |
var rot13_lower = []byte("nopqrstuvwxyzabcdefghijklm") | |
func (rot *rot13Reader) Read(b []byte) (int, error) { | |
n, err := rot.r.Read(b) | |
if err != nil { | |
return 0, err | |
} | |
for i := range b { | |
if 'a' <= b[i] && b[i] <= 'z' { | |
b[i] = rot13_lower[b[i]-'a'] | |
} else if 'A' <= b[i] && b[i] <= 'Z' { | |
b[i] = rot13_upper[b[i]-'A'] | |
} | |
} | |
return n, 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