Created
June 8, 2016 04:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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!