Created
November 3, 2024 04:17
-
-
Save quasar098/5624fd23d0bee2d3bceca46395245538 to your computer and use it in GitHub Desktop.
leetfast.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#include <windows.h> | |
#include <string> | |
#include <unordered_map> | |
#include <vector> | |
std::wstring ExePath() { | |
TCHAR buffer[MAX_PATH] = { 0 }; | |
GetModuleFileName(NULL, buffer, MAX_PATH); | |
std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/"); | |
return std::wstring(buffer).substr(0, pos); | |
} | |
std::vector<std::string> read_lines(const char* fname) { | |
std::ifstream file(fname); | |
if (!file.is_open()) { | |
std::cout << "error: cannot open file"; | |
exit(1); | |
} | |
std::string str; | |
std::vector<std::string> lines; | |
while (std::getline(file, str)) { | |
lines.push_back(str); | |
} | |
return lines; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
int chars_leet_max = 10; | |
if (argc < 2 || argc > 3) { | |
std::cout << "usage: " << argv[0] << " <in-filename> [chars-max=10]\n"; | |
std::cout << "warning: does not output original line, only leet'd/modified lines\n"; | |
std::cout << "chars-max param will completely ignore input passwords if more than n"; | |
std::cout << "chars can be leet'd (so pws like bananananananananananananana may be ignored)"; | |
exit(1); | |
} | |
if (argc == 3) { | |
chars_leet_max = atoi(argv[2]); | |
if (chars_leet_max < 0) { | |
std::cout << "error: chars-max must be above 0"; | |
exit(1); | |
} | |
} | |
const char* replace_map[256] = {}; | |
replace_map['a'] = "a4@"; | |
replace_map['e'] = "e3"; | |
replace_map['i'] = "i1"; | |
replace_map['o'] = "o0"; | |
int replace_map_used_count = 0; | |
for (int i = 0; i < 256; i++) { | |
if (replace_map[i]) { | |
replace_map_used_count++; | |
} | |
} | |
char* replace_map_keys = new char[replace_map_used_count]; | |
const char** replace_map_values = new const char*[replace_map_used_count]; | |
int* replace_map_value_lengths = new int[replace_map_used_count]; | |
replace_map_used_count = 0; | |
for (int i = 0; i < 256; i++) { | |
if (replace_map[i]) { | |
replace_map_keys[replace_map_used_count] = (char) i; | |
replace_map_values[replace_map_used_count] = replace_map[i]; | |
replace_map_value_lengths[replace_map_used_count] = strlen(replace_map[i]); | |
replace_map_used_count++; | |
} | |
} | |
std::vector<std::string> lines = read_lines(argv[1]); | |
for (std::string line : lines) { | |
int line_length = line.length(); | |
int letters_to_cycle_count = 0; | |
for (int j = 0; j < line_length; j++) { | |
for (int i = 0; i < replace_map_used_count; i++) { | |
char k = replace_map_keys[i]; | |
if (line.at(j) == k) { | |
letters_to_cycle_count++; | |
break; | |
} | |
} | |
} | |
if (letters_to_cycle_count > chars_leet_max) { | |
continue; | |
} | |
char* cycler_type = new char[letters_to_cycle_count]; | |
int* cycler = new int[letters_to_cycle_count]; | |
int* cycler_max = new int[letters_to_cycle_count]; | |
int* replace_indicies = new int[letters_to_cycle_count]; | |
letters_to_cycle_count = 0; | |
for (int j = 0; j < line_length; j++) { | |
for (int i = 0; i < replace_map_used_count; i++) { | |
char k = replace_map_keys[i]; | |
if (line.at(j) == k) { | |
cycler[letters_to_cycle_count] = 0; | |
cycler_max[letters_to_cycle_count] = replace_map_value_lengths[i]; | |
cycler_type[letters_to_cycle_count] = i; | |
replace_indicies[letters_to_cycle_count] = j; | |
letters_to_cycle_count++; | |
break; | |
} | |
} | |
} | |
while (true) { | |
bool broken = false; | |
for (int i = 0; i < letters_to_cycle_count; i++) { | |
cycler[i]++; | |
if (cycler[i] >= cycler_max[i]) { | |
cycler[i] = 0; | |
line[replace_indicies[i]] = replace_map_values[cycler_type[i]][0]; | |
continue; | |
} | |
line[replace_indicies[i]] = replace_map_values[cycler_type[i]][cycler[i]]; | |
broken = true; | |
break; | |
} | |
if (!broken) { // gotta be a good sport and finish the job | |
break; | |
} | |
std::cout << line << "\n"; | |
} | |
// std::cout << line << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment