Neuimplementierung in Javascript gestartet. Basierend auf https://en.wikipedia.org...
authorStephan Richter <github@keawe.de>
Tue, 12 Sep 2017 23:34:15 +0000 (01:34 +0200)
committerStephan Richter <github@keawe.de>
Tue, 12 Sep 2017 23:34:15 +0000 (01:34 +0200)
src/secret.html [new file with mode: 0644]

diff --git a/src/secret.html b/src/secret.html
new file mode 100644 (file)
index 0000000..f678a58
--- /dev/null
@@ -0,0 +1,53 @@
+<html>
+<head>
+<script type="text/javascript">
+var prime=257;
+function e(e,t){return '<'+e+'>'+t+'</'+e+'>';} // html element with content t
+function v(i){return document.getElementById(i).value;} // value of element with id
+function h(i,t){document.getElementById(i).innerHTML=t};
+
+function s2n(s){
+       var i,j,coef,n,x,sum;
+       var shares = v('shares');
+       var treshold = v('treshold');
+       var results = [];
+       var th=e('th','char');;
+       var ns=e('th','ascii');;
+       
+       for (i=0; i<s.length;i++) {
+               n=s.charCodeAt(i);
+               th+=e('td',s[i]);
+               ns+=e('td',n);
+               
+               coef=[n];
+               for (j=1; j<treshold;j++) coef[j]=Math.floor(Math.random()*prime);
+               
+               results[i]=[];
+               
+               for (sum=0,x=0; x<shares; x++){                         
+                       for (j in coef) sum+=coef[j]*Math.pow(x+1,j);
+                       results[i][x]=sum%prime;                                        
+               }
+       }       
+       
+       var code=e('tr',th)+e('tr',ns);
+       for (j=0;j<shares;j++){
+               var line=e('th','share '+(j+1));
+               for (i=0;i<s.length;i++){
+                       line+=e('td',results[i][j]);
+               }
+               code+=e('tr',line);
+       }
+       h('tab',code);
+       return n;
+}
+</script>
+</head>
+<body>
+Shares: <input id="shares" value="5"></br>
+Min: <input id="treshold" value="3"></br>
+Secret: <input name="secret" onkeyup="s2n(this.value);">
+<table id="tab">
+</table>
+</body>
+</html>
\ No newline at end of file