Skip to content

Commit

Permalink
Puch
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrophobis committed Aug 29, 2024
1 parent cf112e3 commit b244b6a
Show file tree
Hide file tree
Showing 70 changed files with 287 additions and 1 deletion.
1 change: 1 addition & 0 deletions c++/a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TESTTEST
Binary file modified c++/a.out
Binary file not shown.
84 changes: 84 additions & 0 deletions c++/compress.cpp
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;
}
32 changes: 32 additions & 0 deletions python/pw.py
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()
37 changes: 37 additions & 0 deletions python/pwh.py
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()
32 changes: 32 additions & 0 deletions python/pwr.py
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()
36 changes: 36 additions & 0 deletions python/pws.py
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)
64 changes: 64 additions & 0 deletions python/pwt.py
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()
2 changes: 1 addition & 1 deletion rust/target/.rustc_info.json
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b244b6a

Please sign in to comment.