forked from nijynot/shamir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
38 lines (30 loc) · 1.54 KB
/
form.js
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
function recombineShares() {
const shares = JSON.parse(document.getElementById('shares').value);
const prime = document.getElementById('prime').value;
const prime3217 = Decimal('2').pow(prime).sub(1);
const recombinedsecret = combine(shares, prime3217).toHex();
document.getElementById('recombined').value = recombinedsecret;
// Compare the input secret and the recombined secret
const secret = document.getElementById('secret').value;
const comparisonElement = document.getElementById('comparison');
if (secret === recombinedsecret) {
comparisonElement.textContent = 'The input secret and the recombined secret are the same.';
comparisonElement.style.color = 'green';
} else {
comparisonElement.textContent = 'The input secret and the recombined secret are not the same.';
comparisonElement.style.color = 'red';
}
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('shamirForm').addEventListener('submit', function(event) {
event.preventDefault();
const secret = document.getElementById('secret').value;
const n = document.getElementById('n').value;
const k = document.getElementById('k').value;
const prime = document.getElementById('prime').value;
const prime3217 = Decimal('2').pow(prime).sub(1);
const shares = split(secret, n, k, prime3217);
console.log(shares);
document.getElementById('shares').value = JSON.stringify(shares, null, 2);
});
});