Skip to content

Instantly share code, notes, and snippets.

@poppen
Last active June 15, 2016 08:40
Show Gist options
  • Save poppen/f6200450d68038537c3e26efef3c4826 to your computer and use it in GitHub Desktop.
Save poppen/f6200450d68038537c3e26efef3c4826 to your computer and use it in GitHub Desktop.

Revisions

  1. poppen revised this gist Jun 15, 2016. No changes.
  2. poppen renamed this gist Jun 15, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. poppen created this gist Jun 15, 2016.
    33 changes: 33 additions & 0 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    package main

    import (
    "io"
    "os"
    "strings"
    )

    type rot13Reader struct {
    r io.Reader
    }

    func (r *rot13Reader) Read(b []byte) (int, error) {
    l, e := r.r.Read(b)
    for i, c := range b {
    if c == ' ' || c == '!' {
    continue
    }

    if ('a' <= c && c <= 'm') || ('A' <= c && c <= 'M') {
    b[i] = c + 13
    } else {
    b[i] = c - 13
    }
    }
    return l, e
    }

    func main() {
    s := strings.NewReader("Lbh penpxrq gur pbqr!")
    r := rot13Reader{s}
    io.Copy(os.Stdout, &r)
    }