Skip to content

Instantly share code, notes, and snippets.

@victorhsieh
Created October 2, 2018 03:10
Show Gist options
  • Save victorhsieh/818e73de1af78ffcf3f0575f1f9542f1 to your computer and use it in GitHub Desktop.
Save victorhsieh/818e73de1af78ffcf3f0575f1f9542f1 to your computer and use it in GitHub Desktop.
brute force attempt
chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,./<>?`~!@#$'.split('')
var re1 = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$");
function p(prefix, depth) { if (depth == 0) { cb(prefix); return; } for (var i = 0 ; i < chars.length; i++) { p(prefix + chars[i], depth - 1); } }
function cb(dec_pwd) {
var cipher_bytes = aesjs.utils.hex.toBytes(params["cipher_hex"]);
var iv_bytes = aesjs.utils.hex.toBytes(params["iv_hex"]);
var dec_key = hash256(aesjs.utils.utf8.toBytes(dec_pwd) + iv_bytes);
var aesCbc = new aesjs.ModeOfOperation.cbc(dec_key, iv_bytes);
var decrypted_bytes = aesCbc.decrypt(cipher_bytes);
var plain_text = block_dec(decrypted_bytes);
if (plain_text.match(re1) != null && utf8ByteCount(plain_text) != null && plain_text.length > 3) { console.log('!!! ' + dec_pwd + ' -> ' + plain_text); }
}
function utf8Len(codePoint) {
if(codePoint >= 0xD800 && codePoint <= 0xDFFF)
return null;
if(codePoint < 0) return null;
if(codePoint <= 0x7F) return 1;
if(codePoint <= 0x7FF) return 2;
if(codePoint <= 0xFFFF) return 3;
if(codePoint <= 0x1FFFFF) return 4;
if(codePoint <= 0x3FFFFFF) return 5;
if(codePoint <= 0x7FFFFFFF) return 6;
return null;
}
function isHighSurrogate(codeUnit) {
return codeUnit >= 0xD800 && codeUnit <= 0xDBFF;
}
function isLowSurrogate(codeUnit) {
return codeUnit >= 0xDC00 && codeUnit <= 0xDFFF;
}
/**
* Transforms UTF-16 surrogate pairs to a code point.
* See RFC2781
*/
function toCodepoint(highCodeUnit, lowCodeUnit) {
if(!isHighSurrogate(highCodeUnit)) return null;
if(!isLowSurrogate(lowCodeUnit)) return null;
highCodeUnit = (0x3FF & highCodeUnit) << 10;
var u = highCodeUnit | (0x3FF & lowCodeUnit);
return u + 0x10000;
}
/**
* Counts the length in bytes of a string when encoded as UTF-8.
* str - a string
* return - the length as an integer
*/
function utf8ByteCount(str) {
var count = 0;
for(var i=0; i<str.length; i++) {
var ch = str.charCodeAt(i);
h=isHighSurrogate(ch); if(h==null) return null; if (h) {
var high = ch;
var low = str.charCodeAt(++i);
l = utf8Len(toCodepoint(high, low)); if (l==null) return null; count += l;
} else {
l = utf8Len(ch); if (l==null) return null; count += l;
}
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment