Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shows what cyrpto-js returns when random cyphers / keys are used when calling decrypt
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