Created
June 8, 2016 04:02
Star
You must be signed in to star a gist
Demonstrates what is returned from Cyrpto-JS when random keys / cyphers are used.
This file contains 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