Skip to content

Instantly share code, notes, and snippets.

@Xjs
Last active December 20, 2019 11:45
Show Gist options
  • Save Xjs/7f178d5278580a0c4dfdc224edf2af69 to your computer and use it in GitHub Desktop.
Save Xjs/7f178d5278580a0c4dfdc224edf2af69 to your computer and use it in GitHub Desktop.
BauCH :o)
package main
import (
"fmt"
"math/rand"
"os"
"strings"
"time"
"unicode"
)
const maxLen = 4
func main() {
rand.Seed(int64(time.Now().Nanosecond()))
if len(os.Args) < 2 {
fmt.Println("uSAgE: bauch Nachricht in Nicht-Bauch-Format")
os.Exit(2)
}
input := strings.Join(os.Args[1:], " ")
output := make([]rune, len(input))
nUpper := 0
i := -1
for _, c := range input {
i++
if !unicode.IsLetter(c) {
output[i] = c
continue
}
if rand.Intn(2*maxLen) > maxLen+nUpper {
output[i] = unicode.ToUpper(c)
if nUpper >= 0 {
nUpper++
} else {
nUpper = 0
}
} else {
output[i] = unicode.ToLower(c)
if nUpper <= 0 {
nUpper--
} else {
nUpper = 0
}
}
}
output = output[:i+1]
fmt.Println(string(output), ":o)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment