f678a58507118a6edec2dd41b842a0e33fa1e30b
[shamirs_secret_web_implementation.git] / src / secret.html
1 <html>
2 <head>
3 <script type="text/javascript">
4 var prime=257;
5 function e(e,t){return '<'+e+'>'+t+'</'+e+'>';} // html element with content t
6 function v(i){return document.getElementById(i).value;} // value of element with id
7 function h(i,t){document.getElementById(i).innerHTML=t};
8
9 function s2n(s){
10         var i,j,coef,n,x,sum;
11         var shares = v('shares');
12         var treshold = v('treshold');
13         var results = [];
14         var th=e('th','char');;
15         var ns=e('th','ascii');;
16         
17         for (i=0; i<s.length;i++) {
18                 n=s.charCodeAt(i);
19                 th+=e('td',s[i]);
20                 ns+=e('td',n);
21                 
22                 coef=[n];
23                 for (j=1; j<treshold;j++) coef[j]=Math.floor(Math.random()*prime);
24                 
25                 results[i]=[];
26                 
27                 for (sum=0,x=0; x<shares; x++){                         
28                         for (j in coef) sum+=coef[j]*Math.pow(x+1,j);
29                         results[i][x]=sum%prime;                                        
30                 }
31         }       
32         
33         var code=e('tr',th)+e('tr',ns);
34         for (j=0;j<shares;j++){
35                 var line=e('th','share '+(j+1));
36                 for (i=0;i<s.length;i++){
37                         line+=e('td',results[i][j]);
38                 }
39                 code+=e('tr',line);
40         }
41         h('tab',code);
42         return n;
43 }
44 </script>
45 </head>
46 <body>
47 Shares: <input id="shares" value="5"></br>
48 Min: <input id="treshold" value="3"></br>
49 Secret: <input name="secret" onkeyup="s2n(this.value);">
50 <table id="tab">
51 </table>
52 </body>
53 </html>