Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90343397
encBackground.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 31, 18:01
Size
2 KB
Mime Type
text/html
Expires
Sat, Nov 2, 18:01 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22057635
Attached To
R4897 i2b2-webclient
encBackground.html
View Options
<!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">-->
<!--<!–<input type="button" onclick="MyPrint()" value="print">–>-->
<!--<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
Log In to Comment