Skip to content

Instantly share code, notes, and snippets.

@irbull
Created June 8, 2016 04:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save irbull/9d7c4ee6efc671233c99f16387690c5b to your computer and use it in GitHub Desktop.
Demonstrates what is returned from Cyrpto-JS when random keys / cyphers are used.
var CryptoJS = require('crypto-js');
var total = 100000;
var counter = 0;
var empty = 0;
var other = 0;
function makeString(len)
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ;+=";
for( var i=0; i < len; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
for ( var i = 0; i < total; i++) {
var cypher = makeString(10);
var key = makeString(15);
var bytes = CryptoJS.AES.decrypt(cypher,key);
try {
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
if ( plaintext === '' ) {
empty++;
} else {
other++;
}
} catch(e) {
counter ++;
}
}
console.log("total caught: " + counter + " " + ((counter / total)*100) + "%");
console.log("total empty: " + empty + " " + ((empty / total)*100)+ "%");
console.log("total other: " + other + " " + ((other / total)*100)+ "%");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment