Skip to content

Instantly share code, notes, and snippets.

@septor
Last active August 16, 2024 19:38
Show Gist options
  • Save septor/62ebdec14f221e787a068374822ca5cf to your computer and use it in GitHub Desktop.
Save septor/62ebdec14f221e787a068374822ca5cf to your computer and use it in GitHub Desktop.
Cherrytree Vault Code Generator
const fs = require('fs');
const digits = "45689".split("");
const length = 7;
function generateCombinations(digits, length, filePath) {
const combinations = [];
const recursiveGenerate = (prefix, remainingLength, usedDigits) => {
if (remainingLength === 0) {
if (usedDigits.size === digits.length) {
combinations.push(prefix.trim());
}
return;
}
for (let digit of digits) {
let newPrefix;
if (remainingLength > 1) {
newPrefix = prefix + digit + " ";
} else {
newPrefix = prefix + digit;
}
let newUsedDigits = new Set(usedDigits);
newUsedDigits.add(digit);
recursiveGenerate(newPrefix, remainingLength - 1, newUsedDigits);
}
};
recursiveGenerate("", length, new Set());
fs.writeFile(filePath, combinations.join('\n'), (err) => {
if (err) {
console.error('Error writing to file:', err);
} else {
console.log('Combinations have been written to', filePath);
}
});
}
const filePath = "combinations.txt";
generateCombinations(digits, length, filePath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment