Page MenuHomec4science

encBackground.html
No OneTemporary

File Metadata

Created
Thu, Oct 31, 18:01

encBackground.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="javascripts/cryptolib.js"></script>
<script type="text/javascript" src="javascripts/encryptStr.js"></script>
<title>Encypt/Decrypt in background</title>
<script>
var counter = 0;
setInterval(function() {
counter += 1;
document.querySelector("#mydiv").innerHTML = counter;
}, 100);
var pk=null,sk;
var cipher, plain;
var K, S;
function genkey(){
[sk, pk] = GenKey()
// alert("Secret key: " + sk + "\nPrivate key: " + pk)
}
function encrypt(){
cipher = EncryptStr(pk, "9999")
// alert("Cipher: " + cipher)
}
function decrypt() {
plain = DecryptStr(cipher, sk);
alert("Plaintext: " + plain)
}
function light_encrypt_init(){
if (pk==null){
alert("generate the keys before")
}
[K, S] = LightEncryptStr_init(pk)
}
function light_encrypt(){
cipher = LightEncryptStr(9999, K, S)
}
// encrypt a list of numbers (strings)
function enc10(){
genkey();
light_encrypt_init();
var start = Date.now()
var plains = ["13", "66", "23444", "-124523632", "151", "5552", "352", "-12426324634", "235423", "62235", "-633455"];
for(var i=0; i < plains.length; i++){
// start worker
var w = new Worker(URL.createObjectURL(new Blob(["("+worker_function.toString()+")()"], {type: 'text/javascript'})));
// pass parameters
w.postMessage([i]);
// // register event for the result
w.onmessage = function(event) {
document.getElementById("encrypted").innerHTML += event.data + "<br>";
}
}
alert((Date.now()-start)/1000 + " seconds to encrypt " + plains.length + " integers")
}
</script>
</head>
<body>
<div>Now the page does not freeze</div>
<div id="mydiv"></div>
<!--<input type="button" onclick="genkey()" value="gen key">-->
<!--<input type="button" onclick="encrypt()" value="encryp">-->
<!--<input type="button" onclick="decrypt()" value="decrypt">-->
<!---->
<!--<input type="button" onclick="genkey();encrypt();decrypt()" value="all">-->
<!--&lt;!&ndash;<input type="button" onclick="MyPrint()" value="print">&ndash;&gt;-->
<!--<br>-->
<!--<input type="button" onclick="light_encrypt_init()" value="light enc init">-->
<!--<input type="button" onclick="light_encrypt()" value="light enc">-->
<!---->
<!--<br>-->
<input type="button" onclick="enc10()" value="light enc 10 numbers">
<div id="encrypted"></div>
</body>
</html>

Event Timeline