Created
March 28, 2020 03:25
-
-
Save heathhenley/fbd48f4d09339d5c76c1971a75031c4e 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(b []byte) (int, error) { | |
n, error := r.r.Read(b) | |
for i := 0; i < n; i++ { | |
if (b[i] >= 'A') && (b[i] <= 'Z') { | |
b[i] += 13 | |
if b[i] > 'Z' { | |
b[i] = 'A' + (b[i] - 'Z') - 1 | |
} | |
} else if (b[i] >= 'a') && (b[i] <= 'z') { | |
b[i] += 13 | |
if b[i] > 'z' { | |
b[i] = 'a' + (b[i] - 'z') - 1 | |
} | |
} | |
} | |
return n, error | |
} | |
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