summaryrefslogtreecommitdiffstats
path: root/index.html
blob: eec7d54c2ed82d9e0d09141aa07a7bc810ce548a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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>