Pass-word mixer

Sarnold 2007-11-04 Here's a small proc called mix-word which mixes a word in a way it is not recognizable. I often use mixed-words in which letters are replaced by digits, as passwords, and mix-word quite produce interesting passwords.

 #Usage : mix-word word ?digit-proba? ?uppercase-proba?

 # word : the word to mix
 # proba : a probability between 0.0 and 1.0

 proc mix-word {word {digit 0.3} {upper 0.5}} {
   foreach letter [split [string tolower $word] ""] {
     append mixed [letter-case [random-match $letter $digit] $upper]
   set mixed

 proc random-match {char proba} {
   if {rand()<$proba} {return [make-match $char]} {return $char}

 proc letter-case {char upper} {
   if {rand()<$upper} {return [string toupper $char]}
   set char

 proc make-match char {
   array set matches [matches]
   if {[info exists matches($char)]} {return $matches($char)}
   return $char

 proc matches {} {split a4b3c0d2e9f7g6h4i1j1k3l1m8o0q9r2s5t4v0x8y9z7 ""}

See also Password Gorilla for a password manager application.