One might wonder, how often does the redo get excuted? Well, we're doing a redo if the generated password doesn't contain a lowercase letter, or it doesn't contain an uppercase letter, or it doesn't contain a digit.

The chance of not containing a lowercase letter is the same as the chance the password only contains uppercase letters or digits, which is (36/62)^8. The chance of not containing an uppercase letter is of course the same. Similary, the chance of not containing a digit is (52/62)^8.

Now, the chance of doing a redo is sligthly less than the sum of these three chances, because than you would count the chance of the password containing only lowercase letters, only uppercase letters, or only digits twice. The chance of containing only lowercase letters, or only uppercase letters is (26/62)^8. The chance of containing only digits is (10/62)^8.

Hence the chance of doing a redo is

(36/62)^8+(36/62)^8+(52/62)^8-(26/62)^8-(26/62)^8-(10/62)^8
which, according to bc, is roughly
.2687742319
or just over one in four.

So, what is the expected number of iterations you have to do to calculate a password? Let p be the chance of having to do a redo. Then the number of iterations is

(1 - p) + 2 (1 - p) p + 3 (1 - p) p^2 + 4 (1 - p) p^3 + ... = (1 - p) (1 + 2 p + 3 p^2 + 4 p^3 + ...) = 1 - p ----- (p + 2 p^2 + 3 p^3 + 4 p^4 + ...) = p 1 - p p 1 ----- ------ 2 = ----- p (1 - p) 1 - p
which is roughly
1.3675666854
Tests suggests the calculated number might be correct.

Abigail


In reply to Re: Passwords by Abigail-II
in thread Passwords by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.