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