Created
February 15, 2022 14:06
-
-
Save Maximilan4/780d6c44abc460bf435f07668aedbe13 to your computer and use it in GitHub Desktop.
rot13 implementation
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" | |
"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