Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created Jun 5, 2019
Embed
What would you like to do?
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