diff options
Diffstat (limited to 'index.html')
| -rw-r--r-- | index.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/index.html b/index.html new file mode 100644 index 0000000..eec7d54 --- /dev/null +++ b/index.html @@ -0,0 +1,113 @@ +<!doctype html> +<html class="no-js" lang="en" dir="ltr"> +<head> + <meta charset="utf-8" /> + <meta http-equiv="x-ua-compatible" content="ie=edge" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Too Many Requests</title> + <link rel="stylesheet" href="static/css/foundation.min.css" /> +</head> +<body> + <div class="grid-container"> + <div class="grid-x grid-padding-x"> + <div class="large-12 cell"> + <h1 id="hostname"></h1> + </div> + </div> + <div class="grid-x grid-padding-x"> + <div class="large-12 cell"> + <div class="callout"> + <h3>Too Many Requests</h3> + <p>We got exceptional traffic from your IP Address. You exceeded the daily limit of <em>0</em> requests per IP.</p> + <p>To continue to use this page you have to prove, that your requests are good faith!</p> + <hr /> + <div> + <form> + <label for="id_prime">Enter an 11 digit prime number to continue:</label> + <div class="input-group"> + <input class="input-group-field" id="id_prime" type="number" value="0" placeholder="Prove your good faith" readonly="" /> + <div class="input-group-button"> + <input type="button" class="button" value="+" onclick="document.getElementById('id_prime').stepUp()" /> + <input type="button" class="button" value="-" onclick="document.getElementById('id_prime').stepDown()" /> + </div> + </div> + <input type="submit" class="button" onclick="check()" value="Submit" /> + </form> + </div> + </div> + </div> + </div> + </div> + <script type="text/javascript"> + var startTime = new Date() + + document.getElementById("hostname").innerHTML = window.location.hostname; + document.title = window.location.hostname; + + function check() { + let numString = document.getElementById('id_prime').value; + let num = new Number(numString); + + if (numString.length != 11) { + alert("Number must be 11 digits. Try Again!"); + } + else if (num < 0 || !isPrime(num)) { + alert("Number is not prime. Try Again!"); + } + else { + let duration = Math.floor((new Date().getTime() - startTime.getTime()) / 1000); + + let durationHours = Math.floor(duration / (60 * 60)); + duration -= durationHours * 60 * 60; + + let durationMinutes = Math.floor(duration / 60); + duration -= durationMinutes * 60; + + let durationSeconds = duration; + + let s = "Congratiulations: You wasted "; + if (durationHours != 0) { + s += durationHours + " hours "; + } + if (durationMinutes != 0) { + s += durationMinutes + " minutes "; + } + if (durationMinutes != 0 || durationHours != 0) { + s += " and "; + } + s += durationSeconds + " seconds of your life!"; + + alert(s); + } + } + + function isPrime(n) { + if (n === 0 || n === 1) { return false; } + else if (n === 2 || n === 3) { return true; } + /* + * Every (integer) x > 4 can be represented as (6k + i), with k ∈ ℕ \ {0} + * and i ∈ { -1, 0, 1, 2, 3, 4 }. + * + * Numbers devideable by + * - (6k + 0), (6k + 2), (6k + 4) can also be devided by 2 + * - (6k + 3) can also be devided by 3 + * + * Left are (6k - 1) and (6k + 1). + * So we check if our number is devideable by 2 or 3, + * and after that only if it is devideable by eighter (6k - 1) or (6k + 1). + * + * All composite numbers n are devided by a number less or equal to sqrt(n). + */ + else if (n % 2 === 0 || n % 3 === 0) { return false; } + else { + for (let k = 1; (6 * k - 1) <= Math.sqrt(n); k++) { + if (n % (6 * k - 1) === 0 || n % (6 * k + 1) === 0) { + return false; + } + } + return true; + } + } + </script> +</body> +</html> |
