Skip to content
Myr

Init alphabet bruteforce implementation (#94)

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

authored by vasyan · committed by Andrey Sitnik · parent c922c45 · Browse files · 1 file+59 added−0 removed
This commit

State

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

Diff stats

1 file+59 added−0 removed

  • tests:+59 added−0 removed

1 file+59 added−0 removed

added:test/bruteforce+59 added
1#!/usr/bin/env node23var fs = require("fs");4var spawnSync = require("child_process").spawnSync;56var filePath = process.argv[2];7var bestResult = {8 value: "",9 size: Infinity10};11var lastString = "";1213function shuffle(a) {14 var j, x, i;15 for (i = a.length - 1; i > 0; i--) {16 j = Math.floor(Math.random() * (i + 1));17 x = a[i];18 a[i] = a[j];19 a[j] = x;20 }21 return a;22}2324function saveFirstString() {25 var data = fs.readFileSync(filePath, "utf8")26 data.replace(/[A-Za-z0-9~_]{58}/g, function(match) {27 lastString = match28 });29}3031function shuffleStringInFile() {32 var data = fs.readFileSync(filePath, "utf8")3334 var result = data.replace(/[A-Za-z0-9~_]{64}/g, function(match) {35 lastString = shuffle(match.split("")).join("");36 return lastString;37 });3839 fs.writeFileSync(filePath + "", result, "utf8")40}4142function checkSize() {43 var output = spawnSync("npx", ["size-limit", filePath]).output44 var size = output.toString("utf8").match(/Package size: ([0-9]+)/);45 if (size && size[1] != 0 && size[1] < bestResult.size) {46 bestResult.value = lastString;47 bestResult.size = size[1];4849 console.log('New best string has been founded: ' + bestResult.value + ' | size: ' + bestResult.size);50 }51}5253saveFirstString()54checkSize()5556while (true) {57 shuffleStringInFile()58 checkSize()59}