Skip to content
Myr

Speed up bruteforce

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent 90a7549 · Browse files · 3 files+48 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+48 added−32 removed

  • tests:+44 added−30 removed
  • other:+4 added−2 removed

3 files+48 added−32 removed

modified:test/bruteforce+44 added-30 removed
1#!/usr/bin/env node23var sizeLimit = require('size-limit')3var UglifyJS = require('uglify-js')4var gzipSize = require('gzip-size')5var chalk = require('chalk')6var path = require('path')7var fs = require('fs')89var filePath = path.join(process.cwd(), process.argv[2])10var file11var used = { }1213function shuffle (str) {14 var array = str.split('')15 var j, x, i13 for (i = str.length - 1; i > 0; i--) {16 for (i = array.length - 1; i > 0; i--) {17 j = Math.floor(Math.random() * (i + 1))15 x = str[i]16 str[i] = str[j]17 str[j] = x18 x = array[i]19 array[i] = array[j]20 array[j] = x21 }19 return str22 return array.join('')23}2425function shuffleUnique (str) {26 var mixed
24 unmodified lines
51var prevPercent = 052var maxSteps = factorial(64)5354function findInitialString () {52 var data = fs.readFileSync(filePath, 'utf8')53 data.replace(/[A-Za-z0-9~_]{64}/, function (match) {54 lastString = match55 })55 file = fs.readFileSync(filePath, 'utf8')56 file = UglifyJS.minify(file).code.replace('module.', 'e.')57 file = '!function(e){var t={};function r(n){if(t[n])return t[n].exports;' +58 'var o=t[n]={i:n,l:!1,exports:{}};return ' +59 'e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}' +60 'r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||' +61 'Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){' +62 '"undefined"!=typeof Symbol&&Symbol.toStringTag&&' +63 'Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),' +64 'Object.defineProperty(e,"__esModule",{value:!0})},' +65 'r.t=function(e,t){if(1&t&&(e=r(e)),8&t)' +66 'return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;' +67 'var n=Object.create(null);if(r.r(n),Object.defineProperty(' +68 'n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)' +69 'for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));' +70 'return n},r.n=function(e){var t=e&&e.__esModule?function(){' +71 'return e.default}:function(){return e};return r.d(t,"a",t),t}' +72 ',r.o=function(e,t){return Object.prototype.hasOwnProperty' +73 '.call(e,t)},r.p="",r(r.s=0)}([function(e,t){' + file + '}]);'74 var match = file.match(/[A-Za-z0-9~_]{64}/)75 if (!match) {76 process.stderr.write(chalk.red('Alphabet was not found') + '\n')77 process.exit(1)78 }79 lastString = match[0]80}8158function shuffleStringInFile () {59 var data = fs.readFileSync(filePath, 'utf8')6061 var result = data.replace(/[A-Za-z0-9~_]{64}/, function (match) {62 lastString = shuffleUnique(match.split('')).join('')63 return lastString64 })6566 fs.writeFileSync(filePath + '', result, 'utf8')82function shuffleString () {83 lastString = shuffleUnique(lastString)84 file = file.replace(/[A-Za-z0-9~_]{64}/, lastString)85}8687function checkSize () {88 step += 171 sizeLimit(filePath).then(function (size) {72 if (size.gzip < best.size) {89 gzipSize(file).then(function (size) {90 size = size - 46191 if (size < best.size) {92 best.value = lastString74 best.size = size.gzip93 best.size = size94 process.stdout.write(95 chalk.green.bold(best.size + 'B') + ' ' + best.value + '\n')96 } else {78 var percent = Math.floor(100 * step / maxSteps)97 var percent = Math.floor(10000 * step / maxSteps)98 if (percent > prevPercent) {99 prevPercent = percent81 process.stdout.write(chalk.gray(percent + '%') + '\n')100 process.stdout.write(chalk.gray((percent / 10000.0) + '%') + '\n')101 }102 }103 if (step === maxSteps) {104 process.exit(0)105 } else {87 shuffleStringInFile()106 shuffleString()107 checkSize()108 }109 })110}111112findInitialString()94if (typeof lastString === 'undefined') {95 process.stderr.write(chalk.red('Alphabet was not found') + '\n')96 process.exit(1)97}98113checkSize()
modified:package.json+2 added
modified:yarn.lock+2 added-2 removed
6438 unmodified lines
6439 version "0.1.1"6440 resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce"6441 integrity sha512-PmGOd02bM9YO5ifxpw36nrNMBTptEtfRl4qUYl9SndkolplkrZZOW7PGHjrZL53QvMVj9nQ+TKqUnRsw4tJa4g==64426443size-limit@^0.20.1:6443size-limit@^0.20.0:6444 version "0.20.1"6445 resolved "https://registry.yarnpkg.com/size-limit/-/size-limit-0.20.1.tgz#327436ea50dbda8df24689a56b71d42993ef5d17"6446 integrity sha512-n6ECm/MV2dNe1ukEu6k1IjedVVd0U8fSW+C2FdnWQl+SqYSvDLTflM9rZJlczovW7jh/3TZFXv+2jZMYTuysDg==6447 dependencies:
652 unmodified lines
7100 dependencies:7101 commander "~2.13.0"7102 source-map "~0.6.1"71037104uglify-js@3.4.x, uglify-js@^3.1.4:7104uglify-js@3.4.x, uglify-js@^3.1.4, uglify-js@^3.4.9:7105 version "3.4.9"7106 resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"7107 integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==7108 dependencies:
664 unmodified lines