Last active
October 2, 2020 04:26
-
-
Save relaxnow/3eba99573c2c01bb22db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Bit of code you can run in your developer toolbar or on https://jsfiddle.net . | |
* | |
* Fill in the characteristics of your own 'public file' solution and acceptance criteria. | |
*/ | |
(function(){ | |
'use strict'; | |
// dec=10,hex=16,[A-Z0-9]=36, etc. | |
var CHARACTER_COMBINATIONS = 16, | |
NUMBER_OF_CHARACTERS= 6, | |
TOTAL_COMBINATIONS = Math.pow(CHARACTER_COMBINATIONS, NUMBER_OF_CHARACTERS), | |
// How many files do you expect to host? | |
EXPECTED_NUMBER_OF_FILES=1, | |
// At what percentage does it become unacceptable. | |
MINIMUM_PERCENTAGE=50, | |
// How many tries per second could an attacker get away with? | |
TRIES_PER_SECOND=700, | |
// A years worth of seconds | |
MAX_SECONDS = 60 * 60 * 24 * 365; | |
var minSeconds = 0, | |
maxSeconds = MAX_SECONDS, | |
currentSeconds, | |
currentPercentage, | |
triesAtThisTime; | |
// Do binary search in the given range. | |
while (minSeconds <= maxSeconds) { | |
currentSeconds = (minSeconds + maxSeconds) / 2 | 0; | |
triesAtThisTime = TRIES_PER_SECOND * currentSeconds; | |
if ((TOTAL_COMBINATIONS - triesAtThisTime) <= EXPECTED_NUMBER_OF_FILES) { | |
currentPercentage = 100; | |
} | |
else { | |
currentPercentage = EXPECTED_NUMBER_OF_FILES / (TOTAL_COMBINATIONS - triesAtThisTime) * 100; | |
} | |
if (currentPercentage < MINIMUM_PERCENTAGE) { | |
minSeconds = currentSeconds + 1; | |
} | |
else if (currentPercentage > MINIMUM_PERCENTAGE) { | |
maxSeconds = currentSeconds - 1; | |
} | |
} | |
if (currentSeconds >= MAX_SECONDS) { | |
console.log('Above acceptance criteria'); | |
} | |
else { | |
console.log('Unacceptable. A brute force attack achieves ' + MINIMUM_PERCENTAGE + '% chance of a hit in ' + currentSeconds + ' seconds'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment