|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<style> |
|
html{margin:0;padding:0;height:100%}body{margin:0;padding:0;height:100%;color:#3B3B3B;background:#EEEEEE}#page{max-width:800px;background:white;margin:0 auto;padding:0;min-height:100%}.bannerbox{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;font-weight:600;background:rgba(87,117,128,0.8);font-size:180%;letter-spacing:2px;padding:.8em;color:white;text-transform:uppercase}@media screen and (min-width: 600px){#topbanner{position:absolute;top:10%;left:0}}@media screen and (max-width: 600px){#topbanner{position:relative}}#content{width:90%;margin:1em auto;line-height:140%;font-family:"Calendas Plus","Crimson Text","Hoefler Text","Georgia",serif}h1{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;margin-top:1em;margin-bottom:.8em;line-height:110%}h2{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;margin-top:1.8em;margin-bottom:.5em}h3{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;margin-bottom:0em}p{margin-top:.5em}a{color:#8AB9D1;text-decoration:none}.dateLabel{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;color:#D9D9D9;text-transform:uppercase;font-weight:700;font-size:70%;padding-left:1em;float:right}ul{list-style-type:square}ul,ol{padding-left:2em}li{padding:.3em 0}.tbl{display:table}.tbl>div{display:table-row}.tbl>div>div{display:table-cell;padding:.3em}pre,code{border:1px solid #e8e8e8;background-color:#FCFCFF}code{padding:1px 5px}pre{padding:8px 12px}pre>code{border:0;padding-right:0;padding-left:0}.commaseplist{padding:0px;display:inline;list-style:none}.commaseplist li{display:inline}.commaseplist li:after{content:", "}.commaseplist li:last-child:after{content:""}blockquote{background:#F0F0F0;padding:.2em 1.5em;border-left:.5em solid #8AB9D1}.figureText{margin:0px auto;width:70%;font-size:80%;color:grey;text-align:center;font-style:italic}dt{font-family:"Source Sans Pro","Open Sans","Helvetica Neue","Arial",sans-serif;font-weight:bold}.highlight{background:#fff}.highlight .c{color:#998;font-style:italic}.highlight .err{color:#a61717;background-color:#e3d2d2}.highlight .k{font-weight:bold}.highlight .o{font-weight:bold}.highlight .cm{color:#998;font-style:italic}.highlight .cp{color:#999;font-weight:bold}.highlight .c1{color:#998;font-style:italic}.highlight .cs{color:#999;font-weight:bold;font-style:italic}.highlight .gd{color:#000;background-color:#fdd}.highlight .gd .x{color:#000;background-color:#faa}.highlight .ge{font-style:italic}.highlight .gr{color:#a00}.highlight .gh{color:#999}.highlight .gi{color:#000;background-color:#dfd}.highlight .gi .x{color:#000;background-color:#afa}.highlight .go{color:#888}.highlight .gp{color:#555}.highlight .gs{font-weight:bold}.highlight .gu{color:#aaa}.highlight .gt{color:#a00}.highlight .kc{font-weight:bold}.highlight .kd{font-weight:bold}.highlight .kp{font-weight:bold}.highlight .kr{font-weight:bold}.highlight .kt{color:#458;font-weight:bold}.highlight .m{color:#099}.highlight .s{color:#d14}.highlight .na{color:teal}.highlight .nb{color:#0086B3}.highlight .nc{color:#458;font-weight:bold}.highlight .no{color:teal}.highlight .ni{color:purple}.highlight .ne{color:#900;font-weight:bold}.highlight .nf{color:#900;font-weight:bold}.highlight .nn{color:#555}.highlight .nt{color:navy}.highlight .nv{color:teal}.highlight .ow{font-weight:bold}.highlight .w{color:#bbb}.highlight .mf{color:#099}.highlight .mh{color:#099}.highlight .mi{color:#099}.highlight .mo{color:#099}.highlight .sb{color:#d14}.highlight .sc{color:#d14}.highlight .sd{color:#d14}.highlight .s2{color:#d14}.highlight .se{color:#d14}.highlight .sh{color:#d14}.highlight .si{color:#d14}.highlight .sx{color:#d14}.highlight .sr{color:#009926}.highlight .s1{color:#d14}.highlight .ss{color:#990073}.highlight .bp{color:#999}.highlight .vc{color:teal}.highlight .vg{color:teal}.highlight .vi{color:teal}.highlight .il{color:#099} |
|
</style> |
|
<meta charset="utf-8"> |
|
<meta content="IE=edge" http-equiv="X-UA-Compatible"> |
|
<meta content="width=device-width, initial-scale=1" name="viewport"> |
|
<title> |
|
Password Constraint Puzzler |
|
</title> |
|
<meta content="I was creating a Java snippet for password generation for programming.guide and stumbled across a fun puzzler. Suppose you have the following scenario:" name="description"> |
|
|
|
<meta content="AymqwRC7u88Y4JPvfIF2F37QKylC04248hLCdJAsh8xgOfe/dVJPV3XS3wLFca1ZMVOtnBfVjaCMTVudWM//5g4AAAB7eyJvcmlnaW4iOiJodHRwczovL3d3dy5nb29nbGV0YWdtYW5hZ2VyLmNvbTo0NDMiLCJmZWF0dXJlIjoiUHJpdmFjeVNhbmRib3hBZHNBUElzIiwiZXhwaXJ5IjoxNjk1MTY3OTk5LCJpc1RoaXJkUGFydHkiOnRydWV9" http-equiv="origin-trial"> |
|
</head> |
|
<body> |
|
<div id="page"> |
|
<div style="position: relative;"> |
|
<div class="bannerbox" id="topbanner"> |
|
Andreas Lundblad |
|
</div> |
|
<img src="rick.jpg" style="width: 100%; display: block;"> |
|
</div> |
|
<div id="content"> |
|
<div class="post"> |
|
<header class="post-header"> |
|
<div class="dateLabel"> |
|
Dec 11, 2016 |
|
</div> |
|
<h1 class="post-title"> |
|
Password Constraint Puzzler |
|
</h1> |
|
</header> |
|
<article> |
|
<p> |
|
I was creating a Java snippet for password generation for |
|
<a> |
|
programming.guide |
|
</a> |
|
and stumbled across a fun puzzler. Suppose you have the following scenario: |
|
</p> |
|
<blockquote> |
|
<p> |
|
You’re a user trying to register a new account. The site says that the password must be at least 8 characters, so you enter |
|
<code class="language-plaintext highlighter-rouge"> |
|
"qurcoehx" |
|
</code> |
|
. The site responds with |
|
</p> |
|
<p> |
|
|
|
<em> |
|
<font style="color: red"> |
|
Password must contain at least 1 digit |
|
</font> |
|
</em> |
|
</p> |
|
<p> |
|
You’re lazy and don’t want to type more characters than necessary, so you stick to 8 characters and replace the |
|
<code class="language-plaintext highlighter-rouge"> |
|
c |
|
</code> |
|
with a |
|
<code class="language-plaintext highlighter-rouge"> |
|
7 |
|
</code> |
|
: |
|
<code class="language-plaintext highlighter-rouge"> |
|
"qur7oehx" |
|
</code> |
|
. The site accepts the password. |
|
</p> |
|
</blockquote> |
|
<p> |
|
<strong> |
|
The puzzler |
|
</strong> |
|
: Is the second version “safer” than the first version? Or, put differently: Are there more 8 character passwords with exactly 1 digit, than there are 8 character passwords with only letters? |
|
</p> |
|
<p> |
|
On one hand you can reason… |
|
</p> |
|
<p> |
|
|
|
<em> |
|
a mix of characters and digits must be better than just characters |
|
</em> |
|
</p> |
|
<p> |
|
…but on the other hand… |
|
</p> |
|
<p> |
|
|
|
<em> |
|
being forced to ‘downgrade’ a letter to a digit must surely be bad. |
|
</em> |
|
</p> |
|
<p> |
|
So which one is it? |
|
</p> |
|
<p> |
|
Let’s first focus on lower case character. Without a digit, there are 26 |
|
<sup> |
|
8 |
|
</sup> |
|
8 character passwords. When forced to include a digit, we have: |
|
</p> |
|
<ul> |
|
<li> |
|
a 7 letter password (26 |
|
<sup> |
|
7 |
|
</sup> |
|
choices), |
|
</li> |
|
<li> |
|
1 digit (10 choices), and |
|
</li> |
|
<li> |
|
a digit position (8 choices) |
|
</li> |
|
</ul> |
|
<p> |
|
We see that 26 |
|
<sup> |
|
7 |
|
</sup> |
|
×10×8 is greater than 26 |
|
<sup> |
|
8 |
|
</sup> |
|
, so replacing a character with a digit actually helps. What “saves” us here, intuitively, is the fact that the digit has many possible positions. |
|
</p> |
|
<p> |
|
If we simplify the inequality by dividing both sides with 26 |
|
<sup> |
|
7 |
|
</sup> |
|
, we get |
|
</p> |
|
<p> |
|
10×8 > 26 |
|
</p> |
|
<p> |
|
In other words, inserting a digit is better as long as |
|
</p> |
|
<p> |
|
10×[number of digit positions] > [number of letters]. |
|
</p> |
|
<p> |
|
Even with just 2 characters we’re better off “downgrading” one of them from a letter to a digit. |
|
</p> |
|
<p> |
|
If we on the other hand consider upper case letters as well, i.e. 52 alternatives, we need more than ⌊52/10⌋ = 5 characters for the downgrade to make sense. |
|
</p> |
|
<p> |
|
<strong> |
|
Conclusion |
|
</strong> |
|
: The tongue in cheek security analysis here is, as long as you have a reasonable long password, it’s an improvement to replace a letter with a digit. |
|
</p> |
|
</article> |
|
</div> |
|
</div> |
|
|
|
|
|
</div> |
|
</body> |
|
</html> |
|
|