Skip to content

Instantly share code, notes, and snippets.

@Maximilan4
Created February 15, 2022 14:06
Show Gist options
  • Save Maximilan4/780d6c44abc460bf435f07668aedbe13 to your computer and use it in GitHub Desktop.
Save Maximilan4/780d6c44abc460bf435f07668aedbe13 to your computer and use it in GitHub Desktop.
rot13 implementation
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func (reader rot13Reader) Read(p []byte) (int, error) {
n, err := reader.r.Read(p)
if err != nil {
return n, err
}
for index := 0; index <= n-1; index++ {
value := p[index]
if value < 65 || value > 122 {
continue
}
if (value > 77 && value < 90) || value > 109 {
p[index] -= 13
} else {
p[index] += 13
}
}
return n, err
}
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