Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created June 5, 2019 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakrit/f4cbf53801d31ee61a836bf414a3f340 to your computer and use it in GitHub Desktop.
Save chakrit/f4cbf53801d31ee61a836bf414a3f340 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"os"
)
const Shift = 254
type set struct {
from byte
to byte
}
var sets = []set{
{from: 'a', to: 'z'},
{from: 'A', to: 'Z'},
{from: '0', to: '9'},
}
func main() {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
outbuf := make([]byte, len(buf), len(buf))
copy(outbuf, buf)
for _, bound := range sets {
from, to := bound.from, bound.to
for i, b := range buf {
sb := byte(b + Shift)
if from <= sb && sb <= to {
outbuf[i] = sb
}
}
}
fmt.Println(string(outbuf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment