Updated reader and problem fix

This commit is contained in:
Alex D. 2021-05-01 10:21:04 +00:00
parent a39eb56303
commit bb8314994b
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 7 additions and 18 deletions

View File

@ -4,40 +4,29 @@ 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)
func (rot13 *rot13Reader) Read(b []byte) (int, error) {
n, err := rot13.r.Read(b)
if err != nil {
return n, err
}
for i, e := range tmp {
for i, e := range b {
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)
switch {
case (b >= 'A' && b <= 'M') || (b >= 'a' && b <= 'm'): b += 13
case (b >= 'N' && b <= 'Z') || (b >= 'n' && b <= 'z'): b -= 13
}
return 0
return b
}
func main() {