-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypt.html
63 lines (59 loc) · 1.67 KB
/
crypt.html
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
<!DOCTYPE html>
<head>
<title>Simple Shift Cipher</title>
<style>
body {
padding: 12px;
background: #f5f5f5;
color: #1e1e1e;
font-family: Helvetica, sans-serif;
}
p label {
display: inline-block;
width: 180px;
}
</style>
</head>
<html lang="de">
<body>
<header>
<h2>Simple Shift Cipher</h2>
</header>
<p>
<label for="textInput">Input text</label>
<input type="text" id="textInput" value="HWEOLRLLOD-" size="70" />
</p>
<p>
<label for="skipInput">Use every X character</label>
<input type="number" id="skipInput" value="2" min="1" max="999" />
</p>
<p>
<label for="turnInput">Make Y turns</label>
<input type="number" id="turnInput" value="11" min="1" max="999" />
</p>
<p>
<!-- <button>Encrypt</button>-->
<button onclick="decrypt()">Decrypt</button>
</p>
<p id="output"></p>
<script>
function decrypt() {
const input = document.getElementById("textInput").value;
const skip = +document.getElementById("skipInput").value;
const turns = +document.getElementById("turnInput").value;
const inputAsCharArray = [...input];
let result = "";
if (turns > 0 && turns < 1000 && skip > 0 && skip < 1000 && input) {
for (let i = 0; i < turns * skip; i = i + skip) {
result += findValue(inputAsCharArray, i);
document.getElementById("output").innerHTML = result;
}
}
}
function findValue(array, index) {
console.log(index);
return index < 0 ? array[0] : array[index % array.length];
}
</script>
</body>
</html>