-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf112e3
commit b244b6a
Showing
70 changed files
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TESTTEST |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
#include <sstream> | ||
#include <algorithm> | ||
|
||
std::string compress(const std::string& data, std::unordered_map<char, std::string>& encoding) { | ||
// Step 1: Frequency Analysis | ||
std::unordered_map<char, int> frequency; | ||
for (char c : data) { | ||
frequency[c]++; | ||
} | ||
|
||
// Step 2: Sort by frequency and assign the smallest binary codes to most frequent elements | ||
std::vector<std::pair<char, int>> sorted_items(frequency.begin(), frequency.end()); | ||
std::sort(sorted_items.begin(), sorted_items.end(), [](auto& a, auto& b) { | ||
return b.second < a.second; | ||
}); | ||
|
||
int code = 0; | ||
for (const auto& item : sorted_items) { | ||
encoding[item.first] = std::to_string(code); // use the integer as the code directly | ||
code++; | ||
} | ||
|
||
// Step 3: Encode the data | ||
std::stringstream compressed_data; | ||
for (char c : data) { | ||
compressed_data << encoding[c]; | ||
if (encoding[c].length() == 2) { | ||
compressed_data << ","; // add a comma only after two-digit values | ||
} | ||
} | ||
|
||
std::string result = compressed_data.str(); | ||
if (result.back() == ',') { | ||
result.pop_back(); // Remove trailing comma | ||
} | ||
|
||
return result; | ||
} | ||
|
||
std::string decompress(const std::string& compressed_data, const std::unordered_map<char, std::string>& encoding) { | ||
// Reverse the encoding map to create a decoding map | ||
std::unordered_map<std::string, char> decoding; | ||
for (const auto& pair : encoding) { | ||
decoding[pair.second] = pair.first; | ||
} | ||
|
||
std::string decompressed_data; | ||
std::stringstream ss(compressed_data); | ||
std::string token; | ||
|
||
// This will handle single and two-digit values correctly | ||
while (std::getline(ss, token, ',')) { | ||
// Retrieve the original character for the decoded token | ||
if (decoding.find(token) != decoding.end()) { | ||
decompressed_data += decoding.at(token); | ||
} else { | ||
std::cerr << "Error: Unknown token " << token << " during decompression.\n"; | ||
} | ||
} | ||
|
||
return decompressed_data; | ||
} | ||
|
||
int main() { | ||
std::string data = "1234"; | ||
std::unordered_map<char, std::string> encoding; | ||
|
||
std::string compressed_data = compress(data, encoding); | ||
std::cout << "Compressed Data: " << compressed_data << std::endl; | ||
|
||
std::cout << "Encoding:" << std::endl; | ||
for (const auto& pair : encoding) { | ||
std::cout << pair.first << ": " << pair.second << std::endl; | ||
} | ||
|
||
std::string decompressed_data = decompress(compressed_data, encoding); | ||
std::cout << "Decompressed Data: " << decompressed_data << std::endl; | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import random | ||
import time | ||
|
||
def check_pw(pw, password): | ||
print(f"Guessing password: {pw} Guess number: {check_pw.guesses}") | ||
return pw == password | ||
|
||
def main(): | ||
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", | ||
"v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", | ||
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", | ||
"@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "]", "{", "}", "|", ",", "'", "<", | ||
">", "/", "?", "~"] | ||
|
||
password = input("Password: ") | ||
pw_length = int(input("Password Length: ")) | ||
check_pw.guesses = 0 | ||
|
||
start_time = time.time() | ||
|
||
while True: | ||
current_pw = ''.join(random.choice(chars) for _ in range(pw_length)) | ||
check_pw.guesses += 1 | ||
|
||
if check_pw(current_pw, password): | ||
end_time = time.time() | ||
duration = end_time - start_time | ||
print(f"Guess successful: {password} in {check_pw.guesses} guesses, took {duration:.2f}s") | ||
break | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import hashlib | ||
import time | ||
|
||
# Function to generate SHA256 hash of a string | ||
def sha256(s): | ||
return hashlib.sha256(s.encode()).hexdigest() | ||
|
||
# Function to generate combinations using recursive backtracking | ||
def generate_combinations(char_set, max_length, password, current_string, guesses): | ||
if sha256(current_string) == password: | ||
elapsed_time = time.time() - generate_combinations.start_time | ||
print(f"\n\n\n\nFound {password} ({current_string}) with {guesses} guesses in {elapsed_time:.6f} seconds") | ||
exit(0) | ||
|
||
for c in char_set: | ||
current_string += c | ||
guesses += 1 | ||
|
||
if len(current_string) <= max_length: | ||
generate_combinations(char_set, max_length, password, current_string, guesses) | ||
|
||
current_string = current_string[:-1] | ||
|
||
def main(): | ||
char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+[]{}|,'.<>?~" | ||
|
||
password = input("Hashed Input Password: ") | ||
max_length = int(input("Length Before Hashing: ")) | ||
|
||
current_string = "" | ||
guesses = 0 | ||
|
||
generate_combinations.start_time = time.time() | ||
generate_combinations(char_set, max_length, password, current_string, guesses) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import time | ||
|
||
# Function to generate combinations using recursive backtracking | ||
def generate_combinations(char_set, max_length, password, current_string, guesses): | ||
if current_string == password: | ||
elapsed_time = time.time() - generate_combinations.start_time | ||
print(f"Found {password} with {guesses} guesses in {elapsed_time:.6f} seconds") | ||
exit(0) | ||
|
||
for c in char_set: | ||
current_string += c | ||
guesses += 1 | ||
|
||
if len(current_string) <= max_length: | ||
generate_combinations(char_set, max_length, password, current_string, guesses) | ||
|
||
current_string = current_string[:-1] | ||
|
||
def main(): | ||
char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+[]{}|,'.<>?~" | ||
|
||
password = input("Password: ") | ||
max_length = int(input("Length: ")) | ||
|
||
current_string = "" | ||
guesses = 0 | ||
|
||
generate_combinations.start_time = time.time() | ||
generate_combinations(char_set, max_length, password, current_string, guesses) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import time | ||
|
||
def generate_combinations(char_set, max_length, password): | ||
char_set_len = len(char_set) | ||
current_combination = [0] * max_length | ||
guesses = 0 | ||
|
||
start_time = time.time() | ||
|
||
while True: | ||
guesses += 1 | ||
# Generate the current string from current_combination | ||
current_string = ''.join(char_set[i] for i in current_combination) | ||
|
||
|
||
if current_string == password: | ||
elapsed_time = time.time() - start_time | ||
print(f"Found {password} with {guesses} guesses in {elapsed_time:.6f} seconds") | ||
return | ||
|
||
# Increment the combination | ||
pos = max_length - 1 | ||
while pos >= 0: | ||
current_combination[pos] += 1 | ||
if current_combination[pos] == char_set_len: | ||
current_combination[pos] = 0 | ||
pos -= 1 | ||
else: | ||
break | ||
|
||
if __name__ == "__main__": | ||
char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+[]{}|,'.<>?~" | ||
password = input("Password: ") | ||
max_length = int(input("Length: ")) | ||
|
||
generate_combinations(char_set, max_length, password) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import threading | ||
import time | ||
import os | ||
|
||
# Global variables | ||
found = False | ||
found_lock = threading.Lock() | ||
|
||
# Function to generate combinations using recursive backtracking | ||
def generate_combinations(char_set, max_length, password, current_string, guesses): | ||
global found | ||
if found: | ||
return | ||
|
||
if len(current_string) == max_length: | ||
return | ||
|
||
for c in char_set: | ||
if found: | ||
return | ||
|
||
current_string += c | ||
guesses[0] += 1 | ||
|
||
if current_string == password: | ||
with found_lock: | ||
if not found: # Double-check in case another thread found it first | ||
found = True | ||
print(f"Found {password} with {guesses[0]} guesses") | ||
return | ||
|
||
generate_combinations(char_set, max_length, password, current_string, guesses) | ||
current_string = current_string[:-1] | ||
|
||
def worker(char_set, max_length, password, guesses): | ||
generate_combinations(char_set, max_length, password, "", guesses) | ||
|
||
def main(): | ||
global found | ||
|
||
char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+[]{}|,'.<>?~" | ||
|
||
password = input("Password: ") | ||
max_length = int(input("Length: ")) | ||
|
||
start = time.time() | ||
|
||
num_threads = min(32, os.cpu_count()) # Number of threads | ||
threads = [] | ||
guesses = [0] # Shared list to keep track of guesses | ||
|
||
for _ in range(num_threads): | ||
t = threading.Thread(target=worker, args=(char_set, max_length, password, guesses)) | ||
threads.append(t) | ||
t.start() | ||
|
||
for t in threads: | ||
t.join() | ||
|
||
elapsed_time = time.time() - start | ||
print(f"Time elapsed: {elapsed_time:.6f}s") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"rustc_fingerprint":13165650680765644735,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/codespace/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nub_checks\nunix\n","stderr":""},"16495917692426387086":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.80.1 (3f5fd8dd4 2024-08-06)\nbinary: rustc\ncommit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\ncommit-date: 2024-08-06\nhost: x86_64-unknown-linux-gnu\nrelease: 1.80.1\nLLVM version: 18.1.7\n","stderr":""},"12647030484516954926":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""},"14371922958718593042":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/codespace/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}} | ||
{"rustc_fingerprint":13893072419711178074,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/codespace/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.80.1 (3f5fd8dd4 2024-08-06)\nbinary: rustc\ncommit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\ncommit-date: 2024-08-06\nhost: x86_64-unknown-linux-gnu\nrelease: 1.80.1\nLLVM version: 18.1.7\n","stderr":""},"16495917692426387086":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""}},"successes":{}} |
Binary file removed
BIN
-9.76 KB
...emental/test-0i7v2b465x0kk/s-gzg0lvsglp-0264rkp-5etpqcaflh06ic3l9fsulffu7/query-cache.bin
Binary file not shown.
Binary file renamed
BIN
+206 KB
...p-5etpqcaflh06ic3l9fsulffu7/dep-graph.bin → ...m-5etpqcaflh06ic3l9fsulffu7/dep-graph.bin
Binary file not shown.
Binary file added
BIN
+9.37 KB
...emental/test-0i7v2b465x0kk/s-gzg4edk33t-0mnep3m-5etpqcaflh06ic3l9fsulffu7/query-cache.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+216 KB
...n-crmw3472vlib5ui9zyf0emo55/dep-graph.bin → ...q-crmw3472vlib5ui9zyf0emo55/dep-graph.bin
Binary file not shown.
Binary file renamed
BIN
+10.5 KB
...crmw3472vlib5ui9zyf0emo55/query-cache.bin → ...crmw3472vlib5ui9zyf0emo55/query-cache.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+991 KB
...1-3ik1bnd79cds809v2gilo798o/dep-graph.bin → ...k-3ik1bnd79cds809v2gilo798o/dep-graph.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+335 KB
...3ik1bnd79cds809v2gilo798o/query-cache.bin → ...3ik1bnd79cds809v2gilo798o/query-cache.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.