Created
April 11, 2017 02:40
-
-
Save zainfathoni/161ec3364b6ebe28f85e67b57db22286 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 Rot13(b byte) byte { | |
if (b >= 'A' && b <= 'M') || (b >= 'a' && b <= 'm') { | |
b += 13 | |
} else if (b >= 'N' && b <= 'Z') || (b >= 'n' && b <= 'z') { | |
b -= 13 | |
} | |
return b | |
} | |
func (rot rot13Reader) Read(b []byte) (n int, err error) { | |
n, err = rot.r.Read(b) | |
for i, val := range b { | |
b[i] = Rot13(val) | |
} | |
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