Created
November 7, 2014 21:24
-
-
Save mac01021/65cbaf5cd1e8b029ca10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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