Skip to content

Instantly share code, notes, and snippets.

@irbull
Created June 8, 2016 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irbull/48b160ff10727644bd04bb98d2e7b2af to your computer and use it in GitHub Desktop.
Save irbull/48b160ff10727644bd04bb98d2e7b2af to your computer and use it in GitHub Desktop.
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)+ "%");
@PickertJoe
Copy link

Ian,

Thank you for writing that blog post describing your findings from this test. It directly addressed a frustratingly elusive bug that I'd been dealing with.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment