Version 5 of Password generator

Updated 2016-04-15 16:55:45 by bll

Should create a strong password:

variable _index [pid];

proc password {length} {
        global _index;
        variable _set {shW4UMe832TpaSylIdfzxbrNki9A7Q5PmZ0XDuYVg1KEGwLcJtjRCF6OqovBHn};
        variable _password {};

        for {set _char 1} {$_char <= $length} {incr _char} {
                incr _index [lindex [time {
                        while {$_index >= [string length $_set]} {
                                incr _index -[string length $_set];
                        }
                        
                        # Only usefull to increase entropy
                        
                        for {set _count $_index} {$_count <= [string length $_set]} {incr _count} {
                        
                                # Nothing to do

                        }
                        
                        set _password $_password[string index $_set $_index];
                }] 0]
        }

        return $_password;
}

Call password length inside the script.

AMG: My first instinct was to optimize this code since it is written in a seemingly wasteful way. However, there is a trick, a method to the madness. The time command is used as a random number generator, used to advance the index into the character set. So inefficient programming with somewhat unpredictable runtime is exactly the programmer's intent.

bll 2016-4-15:

See [L1 ]:

The output from "ent" for 80000 characters, password 8 called 10000 times. Not random at all (chi-square percentage less than 1%), and the serial correlation coefficient is quite high.

Entropy = 4.787082 bits per byte.

Optimum compression would reduce the size
of this 80000 byte file by 40 percent.

Chi square distribution for 80000 samples is 841393.86, and randomly
would exceed this value 0.01 percent of the times.

Arithmetic mean value of data bytes is 93.7709 (127.5 = random).
Monte Carlo value for Pi is 4.000000000 (error 27.32 percent).
Serial correlation coefficient is -0.204070 (totally uncorrelated = 0.0).

See Also


paskali - 2016-04-15 16:36:21

Thanks. I am crazy.