/* Split number into the shares */
function split(number, number_of_shares, needed) {
/* Split number into the shares */
function split(number, number_of_shares, needed) {
- for (var coef_index =0; coef_index<needed; coef_index++){
- sum += coef[coef_index]*Math.pow(share_number,coef_index);
- }
-
+ for (var coef_index =0; coef_index<needed; coef_index++) sum += coef[coef_index]*Math.pow(share_number,coef_index);
for (var div_index=0; div_index<divs.length; div_index++){
var div=divs[div_index];
var inputs = div.getElementsByTagName('input');
for (var div_index=0; div_index<divs.length; div_index++){
var div=divs[div_index];
var inputs = div.getElementsByTagName('input');
+ return result;
+}
+
+/* fetches values from the input fields, decomposes each input string into several shares and reconstructs the original code/char for each position */
+function decode(){
+ var shares_list=collect(); // fetch shares
+ var ascii=getElement('ascii');
+ var result=getElement('result');
- for (var share_index=0; share_index<shares_list.length; share_index++){
- var share_number = shares_list[share_index].share_number;
- var share = shares_list[share_index].parts[codeIndex];
- shares_for_code[share_index] = { share_number, share };
- }
+
+ shares_list.forEach(function(share_set){
+ var share_number = share_set.share_number;
+ var share = share_set.parts[codeIndex];
+ shares_for_code.push({ share_number, share });
+ });
var code = join(shares_for_code);
ascii.innerHTML += code+' ';
result.innerHTML+= String.fromCharCode(code);
var code = join(shares_for_code);
ascii.innerHTML += code+' ';
result.innerHTML+= String.fromCharCode(code);
function secret2numbers(string){
var string_pos,share_number,coef,char_code,x,sum;
var number_of_shares = valueOfField('shares');
function secret2numbers(string){
var string_pos,share_number,coef,char_code,x,sum;
var number_of_shares = valueOfField('shares');