1
0

Solved rot13 exercise

This commit is contained in:
Stephen M. McQuay 2012-09-03 07:52:35 -06:00
parent 26d12054a1
commit a3f6157543

View File

@ -11,13 +11,21 @@ type rot13Reader struct {
}
func (r rot13Reader) Read(p []byte) (n int, err error) {
if len(p) == 0 {
return 0, nil
n, err = r.r.Read(p)
for i := range p[:n] {
p[i] = rot13(p[i])
}
return
}
func rot13(b byte) byte {
var a, z, A, Z byte = 'a', 'z', 'A', 'Z'
if a < b && b < z {
b = a + ((b - a + 13) % 26)
} else if A < b && b < Z {
b = A + ((b - A + 13) % 26)
}
if r.i >= len(r.s) {
return 0, io.EOF
}
return
return b
}
func main() {