Exemple #1
0
//****************************************************************************
ErrorCode MD5UtilCore::processCollide (const CommandLineOptions& options, std::string& output) {

	static const std::string& NO_COLLISION_FOUND = "No collision found for current hash with given settings.";

	if (options.getHelpMode ()) {

		std::cout << MSG_COLLIDE_HELP << std::endl;
		return ErrorCode::NONE;

	}

	if (options.getInputText ().length () == 0 || options.getAlphabet ().length () == 0) {

		return ErrorCode::COLLIDE_USAGE_ERROR;

	}

	if (findCollision (options, output)) {

		if (options.getOutputFilename ().length () != 0) {

			if (!saveToFile (options.getOutputFilename (), output)) {

				return ErrorCode::FILE_WRITE_ERROR;

			}

		}

	} else {

		output = NO_COLLISION_FOUND;

	}

	return ErrorCode::NONE;

}
Exemple #2
0
//****************************************************************************
void MD5UtilCore::checkCollisionRange (const CommandLineOptions& options, bool& solutionFound, std::string& output, const unsigned int threadIndex) {

	static const unsigned int MAX_DIGITS = 16;

	unsigned int threadCount = 1;
	unsigned int maxDigits = options.getMaxLength ();
	unsigned int minDigits = options.getMinLength ();
	uint_least64_t range = 0;
	uint_least64_t startIndex = 0;
	VBUInt plaintextGenerator (0, options.getAlphabet ().length ());
	std::string plaintextToTest;

	if (options.getThreadCount () > 1) {

		threadCount = options.getThreadCount ();

	}

	if (options.getMinLength () == 0 || options.getMinLength () > options.getMaxLength ()) {

		minDigits = 1;

	}

	if (options.getMaxLength () == 0 || options.getMaxLength () < options.getMinLength ()) {

		maxDigits = MAX_DIGITS;

	}

	range = plaintextGenerator.maxValue (maxDigits) / threadCount;
	startIndex = range * threadIndex;
	plaintextGenerator.setBaseTenValue (startIndex);

	for (; plaintextGenerator < VBUInt (startIndex + range); plaintextGenerator++) {

		for (unsigned int digits = minDigits; digits <= maxDigits; digits++) {

			if (solutionFound) {

				break;

			} else {

				plaintextToTest = plaintextGenerator.toString (options.getAlphabet ().getCharacters (), digits);

				if (hash (plaintextToTest) == options.getInputText ()) {

					solutionFound = true;
					output = plaintextToTest;
					break;

				}

			}

		}

	}

}