Created
December 31, 2019 04:58
-
-
Save siisee11/bf57a6f447d90d07f31268b0fe554f19 to your computer and use it in GitHub Desktop.
rot13Reader
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 (rot *rot13Reader) Read(buf []byte) (n int, e error) { | |
n, e = rot.r.Read(buf) | |
for i:= 0; i < len(buf); i++ { | |
c := buf[i] | |
if (c >= 'A' && c <= 'N') || (c >= 'a' && c < 'n') { | |
buf[i] += 13 | |
} else if (c >= 'M' && c <= 'Z') || (c >= 'm' && c <= 'z') { | |
buf[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