-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (61 loc) · 2.48 KB
/
index.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
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="Website for error detection with Cyclic Redundancy Checks">
<meta name="keywords" content="crc,cyclic,redundancy,check,error,detection,correction,code,network,algorithm,website">
<meta name="author" content="Scriptim">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CRC Calculator</title>
<link rel="stylesheet" href="./index.css">
<script src="./crc.js"></script>
</head>
<body>
<main>
<h1>CRC Calculator</h1>
<form>
<input name="data" type="text" pattern="^[01]+$" placeholder="data (binary)" autocomplete="off" required>
<br>
<input name="codeword" type="text" pattern="^[01]+$" placeholder="codeword (binary)" autocomplete="off" required>
<br>
<input name="generator" type="text" pattern="^1[01]*$" placeholder="generator polynomial (binary)" autocomplete="off" required>
<br>
<button type="submit">Submit</button>
</form>
<pre id="divisionSteps"></pre>
<br>
<pre id="result"></pre>
</main>
<script>
const dataIn = document.getElementsByName('data')[0]
const codewordIn = document.getElementsByName('codeword')[0]
const generatorIn = document.getElementsByName('generator')[0]
const divisionStepsOut = document.getElementById('divisionSteps')
const resultOut = document.getElementById('result')
dataIn.oninput = dataIn.onchange = _ => {
const hasData = dataIn.value !== ''
codewordIn.disabled = hasData
codewordIn.required = !hasData
}
codewordIn.oninput = codewordIn.onchange = _ => {
const hasCodeword = codewordIn.value !== ''
dataIn.disabled = hasCodeword
dataIn.required = !hasCodeword
}
const urlParams = new URLSearchParams(window.location.search)
const data = urlParams.get('data')
const codeword = urlParams.get('codeword')
const generator = urlParams.get('generator')
if (data !== null && generator !== null) {
const result = crc(data, generator, false)
divisionStepsOut.innerHTML = result.divisionSteps.join('\n')
resultOut.innerHTML = result.codeword
} else if (codeword !== null && generator !== null) {
const result = crc(codeword, generator, true)
divisionStepsOut.innerHTML = result.divisionSteps.join('\n')
resultOut.innerHTML = result.error ? 'Error' : 'No Error'
}
</script>
</body>
</html>