Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "io"
- "os"
- "strings"
- "fmt"
- )
- type rot13Reader struct {
- r io.Reader
- }
- func (reader *rot13Reader) Read(b []byte) (int, error) {
- rot13 := func(r rune) rune {
- switch {
- case r >= 'A' && r <= 'Z':
- return 'A' + (r-'A'+13)%26
- case r >= 'a' && r <= 'z':
- return 'a' + (r-'a'+13)%26
- }
- return r
- }
- n, err := reader.r.Read(b)
- result := []byte(strings.Map(rot13, string(b)))
- b = []byte(result)
- fmt.Println(string(b))
- return n, err
- }
- func main() {
- s := strings.NewReader("Lbh penpxrq gur pbqr!")
- r := rot13Reader{s}
- io.Copy(os.Stdout, &r)
- }
- You cracked the code!
- Lbh penpxrq gur pbqr!You cracked the code!
- Lbh penpxrq gur pbqr!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement