Beispiel #1
0
void CTestSnowflakeID::Test_SnowflakeID(void)
{
    CSnowflakeID objID;
    int64_t iID = 0;
    CTimer objTimer;
    std::map<int64_t, char> mapID;
    std::map<int64_t, char>::iterator itmapID;

    objID.setMachineID(10);
    const char *pszID = objID.getSnowflakeID();
    printf("%s\n", pszID);
    for (int i = 0; i < 10000; i++)
    {
        iID = objID.Generate();
        itmapID = mapID.find(iID);
        if (mapID.end() != itmapID)
        {
            CPPUNIT_ASSERT(false);
        }
        else
        {
            mapID[iID] = 0;
        }
    }

    const int iCount = 100000;
    objTimer.reStart();
    for (int i = 0; i < iCount; i++)
    {
        objID.Generate();
    }
    std::cout << "SnowflakeID time:" << objTimer.Elapsed() << std::endl;

    /*CUUID objUUID;
    objTimer.reStart();
    for (int i = 0; i < iCount; i++)
    {
    objUUID.getUUID();
    }
    std::cout << "UUID time:" << objTimer.Elapsed() << std::endl;*/

    CPPUNIT_ASSERT(true);
}
Beispiel #2
0
void UnstructuredGrid<T,Traits>::initStdMesh()
{
#ifdef WINDOWS
  CTimer timer;
  timer.Start();
#endif
  genElAtVert();
#ifdef WINDOWS
  std::cout<<"Time for routine GenElAtVert(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genNeighboursAtEl();
#ifdef WINDOWS
  std::cout<<"Time for routine genNeighboursAtEl(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genEdgesAtEl();
#ifdef WINDOWS
  std::cout<<"Time for routine GenEdgesAtEl(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genFacesAtEl();
#ifdef WINDOWS
  std::cout<<"Time for routine GenFacesAtEl(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genVertAtEdg();
#ifdef WINDOWS
  std::cout<<"Time for routine GenVertAtEdg(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genVertAtFac();
#ifdef WINDOWS
  std::cout<<"Time for routine GenVertAtFac(): "<<timer.Elapsed()<<std::endl;
  timer.Stop();
  timer.Start();
#endif
  genVertexVertex();
  
  if(refinementLevel_==1)  
    vertAtBdr();

};
Beispiel #3
0
int main(int argc, char *argv[])
{
	// Init signal handler.
	signal(SIGABRT, &sigHandler);
	signal(SIGINT, &sigHandler);
	signal(SIGTERM, &sigHandler);

	boost::program_options::options_description desc("Allowed options");
	desc.add_options()
		("help", "Procudes this help message")
		("version", "Print program message\n")
		("h", boost::program_options::value<string>(), "Hash to crack. A MD5 hash is exactly 32 hex chars long")
		("c", boost::program_options::value<string>(), "Sets the charset. Can be every combination of the following:\n  c: \tA-Z\n  s: \ta-z\n  d: \t0-9\n  x: \tprintable special characters\n")
		("min", boost::program_options::value<int>(), "Minimum password length. Must be over 4")
		("max", boost::program_options::value<int>(), "Maximum password length. Must be 11 or less");
	boost::program_options::variables_map vm;
	try {
		boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
		boost::program_options::notify(vm); 
	}
	catch(boost::program_options::error) {
		// Print.
		cout << "[-] Error: Wrong paramaters. Use MD5reduced --help for more information" << endl;

		// Exit.
		return EXIT_FAILURE;
	}

	// Print the help screen.
	if (vm.count("help")) {
		// Print.
		cout << desc << endl;

		// Exit.
		return EXIT_SUCCESS;
	}

	// Print the help screen.
	if (vm.count("version")) {
		// Print.
		cout << "MD5reduced " << VERSION << endl;
		cout << "(c) Tobias Sielaff, 2011" << endl;

		// Exit.
		return EXIT_SUCCESS;
	}

	// All needed params?
	if (!vm.count("h") || !vm.count("c") || !vm.count("min") || !vm.count("max")) {
		// Print.
		cout << "[-] Error: Missing paramaters. Use MD5reduced --help for more information" << endl;

		// Exit.
		return EXIT_FAILURE;
	}

	// Init MD5.
	string hash = vm["h"].as<string>();
	if (!MD5Init(hash)) {
		// Print.
		cout << "[-] Error: Invaild hash specified. Use MD5reduced --help for more information" << endl;

		// Exit.
		return EXIT_FAILURE;
	}

	// Init charset.
	CCharset charset;
	if (!charset.Initialize(vm["c"].as<string>())) {
		// Print.
		cout << "[-] Error: Invaild charset specified. Use MD5reduced --help for more information" << endl;

		// Exit.
		return EXIT_FAILURE;
	}

	// Init package.
	CPackage package(&charset);

	// Init length.
	int min = vm["min"].as<int>();
	int max = vm["max"].as<int>();
	if (min < 4 || max > 11 || min > max) {
		// Print.
		cout << "[-] Error: Invaild length specified. Use MD5reduced --help for more information" << endl;

		// Exit.
		return EXIT_FAILURE;
	}
	
	// Print config.
	cout << "------------------------------------" << endl;
	cout << "Hash: " << hash << endl;
	cout << "Charset: " << charset.GetCharset() << endl;
	cout << "Min. length: " << min << endl;
	cout << "Max. length: " << max << endl;
	cout << "Threads: " << boost::thread::hardware_concurrency() << endl;
	cout << "Total combinations: " << charset.GetAllCombs(min, max) << endl;
	cout << "------------------------------------" << endl << endl;

	// Bench, start!
	CTimer timer;
	timer.Start();

	// Go!
	for (int i = min; i <= max; i++) {
		// Init stats, plain & bruter.
		CStats *stats = new CStats();
		CPlain *plain = new CPlain(i);
		CBruter *bruter = new CBruter(plain, &charset, &package, stats);

		// Go!
		bruter->Launch();
		bruter->Wait();

		// Cracked?
		if (bruter->HasResult()) {
			cout << "[+] Cracked! => " << bruter->GetResult() << "					" << endl;
			break;
		}

		// Cleanup.
		delete bruter;
		delete plain;
		delete stats;
	}
	cout << "[+] Finished (in " << str(boost::format("%.2f") % (timer.Elapsed() / 1000.0)) << " seconds)!					" << endl;

	// Cleanup.
	MD5Cleanup();

	// Done!
	return EXIT_SUCCESS;
}