Add unfinished reader

This commit is contained in:
Alex D. 2021-04-30 19:18:17 +00:00
parent 41e6d5faa4
commit a39eb56303
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 47 additions and 0 deletions

47
rot13reader.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"io"
"os"
"strings"
"fmt"
)
// TODO: Finish this
type rot13Reader struct {
r io.Reader
}
func (r rot13Reader) Read(b []byte) (int, error) {
tmp := make([]byte, 8)
n, err := r.Read(tmp)
fmt.Println(tmp)
if err != nil {
return n, err
}
for i, e := range tmp {
b[i] = rot13shift(e)
}
fmt.Println(b)
return n, nil
}
func rot13shift(b byte) byte {
if b >= 'N' && b <= 'Z' {
return 'A' + ('N' - b)
} else if b >= 'n' && b <= 'z' {
return 'a' + ('n' - b)
} else if b >= 'A' && b <= 'M' {
return 'N' + ('A' - b)
} else if b >= 'a' && b <= 'm' {
return 'n' + ('a' - b)
}
return 0
}
func main() {
s := strings.NewReader("Lbh penpxrq gur pbqr!")
r := rot13Reader{s}
io.Copy(os.Stdout, &r)
}