Created
August 5, 2021 10:04
-
-
Save ufo22940268/1bc89a70079215b2d789bdf95337504c 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 (r *rot13Reader) Read(p []byte) (n int, err error) { | |
n, err = r.r.Read(p) | |
for i := 0; i < n; i++ { | |
if p[i] >= 65 && p[i] < (97+26) { | |
if p[i] < 97 { | |
p[i] = 65 + (p[i]-65+13)%26 | |
} else { | |
p[i] = 97 + (p[i]-97+13)%26 | |
} | |
} | |
} | |
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