Find the duration of a worst-case brute-force attack
Given the following information about a 7-bit ASCII-encoded password and the computer that will crack it with a brute-force attack:
- Length of the password in characters
- Charset size (i.e total count of the possible characters one character in the password can be)
- Number of passwords the computer can test in one
second millisecond (rounded down)
Write the shortest program that finds out how long the attack will take in the worst-case scenario where the computer tries all possible passwords.
- The output is the duration in this format:
years months days hours minutes seconds milliseconds
- One "month" is 30 days long.
- Fractions of milliseconds are rounded up.
- You can assume that the cracking finishes immediately if it takes less than 50 milliseconds, and make the program print out
Instant
in such cases. - Similarly, the cracking can be considered
Neverending
if it takes more than 292 billion years.
- The program can output using any method, from merely printing to STDOUT to causing a kernel panic/bluescreen with the duration as the error message.
- The input method to get the info about the password/the machine can be anything, as well. Don't use standard loopholes though.
- It's not enforced, but strongly encouraged to write a standalone program.
Here's how to calculate the charset size:
- Start with 0.
- If there's a digit (in the password), add 10.
- If there's a lowercase letter, add 26.
- If there's an uppercase letter, add another 26.
- If there's punctuation, add 32 (7-bit ASCII has this many punctuation characters).
- If there's a whitespace character, add 2. Whitespace characters are horizontal tab (0x09) and space (0x20).
- Any other character counts as non-printable (including backspace (0x08),
DEL
(0x7F), line feed (0x0A) and carriage return (0x0D)). Add 29 if there's any of them.
Count of all possible passwords is (charset size)password length.
Here are some applicable-in-real-life cases you can test your program with (let's assume the computer that will crack them can test 1 billion passwords per second, which equals to 1,000,000 passwords/millisecond):
- 4 characters, charset size 10 (PIN) - 10,000 passwords, output is
0 0 0 0 0 0 1
or Instant
- 8 characters, charset size 94 (at least one uppercase letter, one lowercase letter, one digit and one punctuation) - 6,095,689,385,410,816 passwords, output is
0 2 10 13 14 49 386
- 10 characters, charset size 2 (weakest valid Discourse password, contains whitespace only) - 1024 passwords, output is
0 0 0 0 0 0 1
or Instant
- 25 characters, charset size 26 (correcthorsebatterystaple) - 236,773,830,007,967,588,876,795,164,938,469,376 passwords, output is
7612327353651221350 2 14 0 26 4 939
or Neverending
- 127 characters, charset size 96 (strongest password on newer Windows releases) - written below
- 1024 characters, charset size 36 (4096-bit PGP key represented as a hexadecimal number) - written below
These are the stats of the maximum-strength Windows password:
Passwords: 560,333,510,486,846,899,384,847,242,571,130,277,659,458,884,466,874,695,582,912,274,460,529,559,443,783,341,570,989,525,270,653,136,186,432,110,439,597,936,820,880,106,519,625,601,191,574,799,863,912,148,304,962,133,852,037,202,160,056,511,510,962,873,278,300,126,526,144,267,006,137,180,032,492,751,016,171,207,701,495,935,943,049,216
Output: 18014837657113133339276210216407223432981574217685014647084370963880194169360318337544673523362047845500003550655797865897637169483847774934889398916928636347805229296463546812516445182705545212838429981490065783731353925307067135133992 5 15 19 58 55 944
Alternate output: Neverending
And these are the stats of the PGP key:
Passwords: 4,505,684,579,918,576,285,346,738,866,335,056,898,110,301,685,668,199,078,230,938,179,212,682,315,156,231,410,185,391,761,603,272,976,014,035,539,665,517,248,679,228,261,440,294,129,198,036,262,705,242,310,399,830,546,082,361,923,420,737,260,766,677,891,361,176,003,624,143,368,380,527,062,643,297,677,246,518,686,688,642,023,537,863,317,793,178,302,508,440,097,154,593,959,832,175,055,427,351,149,410,096,495,695,380,712,810,868,774,475,142,767,054,868,274,802,269,522,299,482,066,464,842,097,715,922,988,138,315,118,067,288,670,934,735,264,524,936,706,249,961,394,413,647,964,221,767,703,673,264,468,419,121,528,644,906,680,808,060,759,817,669,970,046,776,525,266,199,099,671,937,918,801,013,826,958,891,378,841,908,663,991,372,649,027,188,879,525,186,690,599,345,723,173,064,252,017,258,129,131,786,488,462,307,158,861,824,049,980,863,991,149,295,162,169,512,952,373,415,599,734,988,691,348,925,488,351,712,593,858,837,027,205,238,618,188,975,201,320,681,214,515,875,812,195,250,605,867,622,987,451,763,883,339,709,733,502,125,838,221,788,546,339,051,347,360,900,518,381,976,167,289,930,943,228,024,924,785,158,428,496,314,937,921,503,359,298,542,415,845,218,449,360,806,235,379,253,546,728,753,218,950,843,742,471,105,739,555,344,908,900,309,982,913,223,331,321,839,212,821,903,239,320,600,564,890,951,140,667,647,680,682,245,252,370,183,758,578,065,733,075,207,856,432,661,797,090,351,101,165,469,273,829,754,476,555,209,675,613,232,875,323,406,611,257,057,059,099,019,633,298,079,410,970,345,108,939,943,042,100,267,260,413,671,556,828,411,902,575,269,208,445,279,433,655,878,082,023,068,697,154,581,711,817,787,688,949,105,583,339,471,599,190,831,084,304,744,483,799,555,478,063,729,574,297,623,870,804,763,558,027,580,772,927,971,329,879,231,979,556,301,616,929,595,576,646,883,067,201,999,872,899,862,889,211,861,332,535,050,455,387,251,034,043,732,447,006,164,551,883,918,733,705,027,099,846,583,024,013,092,062,384,703,436,459,115,108,358,829,136,251,317,699,709,899,140,949,893,425,335,769,021,022,912,434,045,643,544,474,460,899,799,213,759,568,795,794,758,914,390,056,283,305,470,380,859,003,818,724,678,434,816
Output: 144858686339974803412639495445442930108998896787172038266169565946909796654971431654622934722327449074525319562291578211137739886840732034401886018044055761311424449664413690224320369299057721231224396352345948448015131278860508182828147139982752631922511354755096078964028889980704480936709984283352948061204198196785328857204061945957268141550998891534834171375541476907019128991072373909056348731183618329634024763694746476776233417623704464804027405450152026906721990999895827471385353870130056140660354679074035526421905828555132520211676677361401337091034117370453939870215183392876069255694823382473711006907851853458746913295694931911314073828877816349504523255816791677974298928074750103049081088894521647398444396729546431174466495229648516324713327536964168664025148591452750098101445502202880078966283755495859954505040675103796820824907455740718188735077328268047865426806174561044520100917915500979652319301547868727504821981520811835192875926630119576922600465887060849654310721522802609638109522185755307201898676461606130734024600227278608209698963323356340446015796148617903068964091403666193996894642822309315198786075754477250953946657292049336910661279747924178751224344877465829301109562043071275369906871767991229129085786546569052197642684662087651029574035646976531236521763373563846425925268656816387911380422031991615290633773786744123323731112880994579065426763237282889858685438654794679302568796507941872848896038602862540480809810919146613018187362072374644736799940064590439265446053422181856817801562474722208358918298576208528044087753034364036 10 24 22 32 4 679
Alternate output: Neverending
code-golfcryptographydate