UNPKG

2.19 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2var time_estimates;
3
4time_estimates = {
5 estimate_attack_times: function(guesses) {
6 var crack_times_display, crack_times_seconds, scenario, seconds;
7 crack_times_seconds = {
8 online_throttling_100_per_hour: guesses / (100 / 3600),
9 online_no_throttling_10_per_second: guesses / 1e2,
10 offline_slow_hashing_1e4_per_second: guesses / 1e4,
11 offline_fast_hashing_1e10_per_second: guesses / 1e10
12 };
13 crack_times_display = {};
14 for (scenario in crack_times_seconds) {
15 seconds = crack_times_seconds[scenario];
16 crack_times_display[scenario] = this.display_time(seconds);
17 }
18 return {
19 crack_times_seconds: crack_times_seconds,
20 crack_times_display: crack_times_display,
21 score: this.guesses_to_score(guesses)
22 };
23 },
24 guesses_to_score: function(guesses) {
25 var DELTA;
26 DELTA = 5;
27 if (guesses < 1e3 + DELTA) {
28 return 0;
29 } else if (guesses < 1e6 + DELTA) {
30 return 1;
31 } else if (guesses < 1e8 + DELTA) {
32 return 2;
33 } else if (guesses < 1e10 + DELTA) {
34 return 3;
35 } else {
36 return 4;
37 }
38 },
39 display_time: function(seconds) {
40 var base, century, day, display_num, display_str, hour, minute, month, ref, year;
41 minute = 60;
42 hour = minute * 60;
43 day = hour * 24;
44 month = day * 31;
45 year = month * 12;
46 century = year * 100;
47 ref = seconds < 1 ? [null, 'less than a second'] : seconds < minute ? (base = Math.round(seconds), [base, base + " second"]) : seconds < hour ? (base = Math.round(seconds / minute), [base, base + " minute"]) : seconds < day ? (base = Math.round(seconds / hour), [base, base + " hour"]) : seconds < month ? (base = Math.round(seconds / day), [base, base + " day"]) : seconds < year ? (base = Math.round(seconds / month), [base, base + " month"]) : seconds < century ? (base = Math.round(seconds / year), [base, base + " year"]) : [null, 'centuries'], display_num = ref[0], display_str = ref[1];
48 if ((display_num != null) && display_num !== 1) {
49 display_str += 's';
50 }
51 return display_str;
52 }
53};
54
55module.exports = time_estimates;
56
57//# sourceMappingURL=time_estimates.js.map