Efficient password cracking algorithm usable for brute force attacks written in D

To compile the example below type:
gdc -time -O pwd_cracker.d -o pwd_cracker; time ./pwd_cracker
/*
Copyright 2008 Alexander Orlov. All rights reserved.
Redistribution is allowed according to the MIT License/X11 license.
*/


import std.stdio : writefln;

/**
*
* Generates char combinations orderly
*
* EXAMPLE: charCombinationGenerator(0, 3, 'a', 'z')
*
* @param charNum
* @param from
* @param chrPos
* @param to
*/
void charCombinationGenerator(byte chrPos, byte charNum, char from, char to) {

char[] chrCombination = new char[charNum];
byte chrPosTmp;
int chrCombinationNumber = 1; // uncomment for void method type

while (chrPos < charNum) { // all chars = fromAscii chrPosTmp = -1; bit incUntilChrPos = false; do { // all chrPosTmp prev chars = fromAsciiff for (byte toFromAsciiPointer = chrPos; toFromAsciiPointer > chrPosTmp; toFromAsciiPointer--) {
chrCombination[toFromAsciiPointer] = from;
}

// fromAscii to toAscii output
for (char chrCode = from; chrCode <= to; chrCode++) { chrCombination[chrPos] = chrCode; // creates chrComb char[] chrComb; for (byte chrPosWithValue = 0; chrPosWithValue <= chrPos; chrPosWithValue++) { char chr = chrCombination[chrPosWithValue]; chrComb ~= chr; } writefln(chrComb); // char combination which cann be passed as parameter to another function } // check if all chrs = toAscii (=> next for loop)
incUntilChrPos = false;
for (chrPosTmp = 0; chrPosTmp < chrPos; chrPosTmp++) { if (chrCombination[chrPosTmp] != to) { incUntilChrPos = true; break; } } // dec chrPos while != toAscii chrPosTmp = chrPos; while (chrCombination[chrPosTmp] == to && chrPosTmp > 0) {
chrPosTmp--;
}
chrCombination[chrPosTmp]++;
} while (incUntilChrPos);

chrPos++;
}
}


void main() {
charCombinationGenerator(0, 3, 'a', 'z');
}

Comments

Popular posts from this blog

Tuning ext4 for performance with emphasis on SSD usage

NetBeans 6.1: Working with Google´s Android SDK, Groovy and Grails