Created
July 6, 2015 21:51
-
-
Save cgwalters/c70586719578375acd6b 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" | |
"fmt" | |
"strings" | |
) | |
type rot13Reader struct { | |
r io.Reader | |
} | |
func (self rot13Reader) Read(b []byte) (int, error) { | |
r, err := self.Read(b) | |
if err != nil { | |
return 0, err | |
} | |
for i := 0; i < r; i++ { | |
orig := b[i] | |
fmt.Println("Processing ", orig) | |
break | |
var base byte | |
if orig >= 'A' && orig <= 'Z' { | |
base = 'A' | |
} else if orig >= 'a' && orig <= 'a' { | |
base = 'a' | |
} else { | |
continue | |
} | |
off := (orig - base) | |
newoff := (off + 13) % 26 | |
b[i] = base + newoff | |
} | |
return r, nil | |
} | |
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