Add project files.
This commit is contained in:
1 parent
fe7d334156
commit
cfb7a69f65
4 files changed
+345
No files matched your search
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35222.181
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StringMatcher", "StringMatcher\StringMatcher.vcxproj", "{5002B6AE-126F-44E7-9900-23F8D8C25EAB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Debug|x64.Build.0 = Debug|x64
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Debug|x86.Build.0 = Debug|Win32
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Release|x64.ActiveCfg = Release|x64
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Release|x64.Build.0 = Release|x64
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5002B6AE-126F-44E7-9900-23F8D8C25EAB}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0501BE47-0053-4907-99ED-B860ED8424F9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,157 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
#include <iomanip>
|
||||
|
||||
std::string generate_random_string(std::mt19937& gen, std::uniform_int_distribution<>& dist, const std::string& chars, int length) {
|
||||
std::string result(length, '\0');
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int rand_val = dist(gen);
|
||||
result[i] = chars[rand_val];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string determine_character_set(const std::string& target) {
|
||||
bool has_letters = false;
|
||||
bool has_digits = false;
|
||||
bool has_symbols = false;
|
||||
|
||||
for (char c : target) {
|
||||
if (std::isalpha(c)) {
|
||||
has_letters = true;
|
||||
}
|
||||
else if (std::isdigit(c)) {
|
||||
has_digits = true;
|
||||
}
|
||||
else {
|
||||
has_symbols = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string char_set;
|
||||
if (has_letters) {
|
||||
char_set += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
}
|
||||
if (has_digits) {
|
||||
char_set += "0123456789";
|
||||
}
|
||||
if (has_symbols) {
|
||||
char_set += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
}
|
||||
|
||||
return char_set;
|
||||
}
|
||||
|
||||
std::string format_duration(double seconds) {
|
||||
int years = static_cast<int>(seconds / 31536000);
|
||||
seconds -= years * 31536000;
|
||||
int days = static_cast<int>(seconds / 86400);
|
||||
seconds -= days * 86400;
|
||||
int hours = static_cast<int>(seconds / 3600);
|
||||
seconds -= hours * 3600;
|
||||
int minutes = static_cast<int>(seconds / 60);
|
||||
seconds -= minutes * 60;
|
||||
int secs = static_cast<int>(seconds);
|
||||
|
||||
std::ostringstream oss;
|
||||
if (years > 0) oss << years << "y ";
|
||||
if (days > 0 || years > 0) oss << days << "d ";
|
||||
if (hours > 0 || days > 0 || years > 0) oss << hours << "h ";
|
||||
if (minutes > 0 || hours > 0 || days > 0 || years > 0) oss << minutes << "m ";
|
||||
oss << secs << "s";
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string format_large_number(long long number) {
|
||||
std::ostringstream oss;
|
||||
if (number >= 1'000'000'000) {
|
||||
oss << std::fixed << std::setprecision(3) << (number / 1'000'000'000.0) << "B";
|
||||
}
|
||||
else if (number >= 1'000'000) {
|
||||
oss << std::fixed << std::setprecision(3) << (number / 1'000'000.0) << "M";
|
||||
}
|
||||
else if (number >= 1'000) {
|
||||
oss << std::fixed << std::setprecision(3) << (number / 1'000.0) << "K";
|
||||
}
|
||||
else {
|
||||
oss << number;
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string target_input;
|
||||
|
||||
if (argc < 2) {
|
||||
std::cout << "Enter target to match: ";
|
||||
std::getline(std::cin, target_input);
|
||||
}
|
||||
else {
|
||||
target_input = argv[1];
|
||||
}
|
||||
|
||||
std::istringstream stream(target_input);
|
||||
std::string word;
|
||||
std::unordered_set<std::string> target_words;
|
||||
while (stream >> word) {
|
||||
target_words.insert(word);
|
||||
}
|
||||
|
||||
std::string char_set = determine_character_set(target_input);
|
||||
if (char_set.empty()) {
|
||||
std::cerr << "Target string does not contain any recognizable characters." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> dist(0, char_set.size() - 1);
|
||||
|
||||
long long generated_attempts = 0;
|
||||
|
||||
std::cout << "Attempting to match string \"" << target_input << "\"\n";
|
||||
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
bool found_match = false;
|
||||
|
||||
while (!found_match) {
|
||||
for (const std::string& target_word : target_words) {
|
||||
int string_length = target_word.length();
|
||||
std::string random_str = generate_random_string(gen, dist, char_set, string_length);
|
||||
generated_attempts++;
|
||||
|
||||
if (random_str == target_word) {
|
||||
std::cout << "Match found: " << random_str << " at attempt " << format_large_number(generated_attempts) << std::endl;
|
||||
found_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (generated_attempts % 1'000'000 == 0) {
|
||||
auto current_time = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = current_time - start_time;
|
||||
std::cout << "Generated " << format_large_number(generated_attempts) << " attempts in " << format_duration(elapsed.count()) << ".\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = end_time - start_time;
|
||||
|
||||
std::cout << "Generated " << format_large_number(generated_attempts) << " attempts in " << format_duration(elapsed.count()) << ".\n";
|
||||
std::cout << std::fixed << std::setprecision(2);
|
||||
std::cout << "Rate: " << format_large_number(static_cast<long long>(generated_attempts / elapsed.count())) << " attempts per second.\n";
|
||||
|
||||
std::cout << "Press Enter to exit...\n";
|
||||
std::cin.get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{5002b6ae-126f-44e7-9900-23f8d8c25eab}</ProjectGuid>
|
||||
<RootNamespace>StringMatcher</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="StringMatcher.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="StringMatcher.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user