Skip to content

Instantly share code, notes, and snippets.

@mac01021
Created November 7, 2014 21:24
Show Gist options
  • Select an option

  • Save mac01021/65cbaf5cd1e8b029ca10 to your computer and use it in GitHub Desktop.

Select an option

Save mac01021/65cbaf5cd1e8b029ca10 to your computer and use it in GitHub Desktop.
def passwordFrom[template String] String {
map[template, passChar].scrambled
}
def passChar[c Rune] Rune {
if c = {
'a': lowercase[rand[0, 26]]
'A': uppercase[rand[0, 26]]
'0': digits[rand[0, 10]]
'.': punctation[rand[0, 14]]
} else {
panic!
}
}
def lowerCase = "abcdefghijklmnopqrstuvwxyz"
def uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def digits = "0123456789"
def puctuation = ",./\][=-{}()+_"
def [runes String] .scrambled String{
let scrambled = copy[runes]
forEach[range[runes.length - 1]] {[i]
scrambled.swap[i, rand[i+1, runes.length]]
}
scrambled
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment