commit 1e806db22eaeca2de0c5474b91a04877e4ebfc5a Author: Megamichi Date: Sun Dec 10 13:18:13 2023 +0100 upload diff --git a/c/hash_cracker b/c/hash_cracker new file mode 100755 index 0000000..d6db8b2 Binary files /dev/null and b/c/hash_cracker differ diff --git a/c/hash_cracker.c b/c/hash_cracker.c new file mode 100644 index 0000000..7ad96ea --- /dev/null +++ b/c/hash_cracker.c @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include + +void print_help(char *program_name) { + printf("Usage: %s -z -h -t \n", program_name); + printf("Options:\n"); + printf(" -z \tCharacters to use for hashing\n"); + printf(" -h \tHash to find\n"); + printf(" -t \tHash type (MD5, SHA1, SHA224, SHA256, SHA384, SHA512)\n"); + printf(" -help\t\tShow this help message\n"); +} + +char* hash(const char* data, const EVP_MD* hash_type) { + unsigned char hash[EVP_MAX_MD_SIZE]; + unsigned int hash_len; + + EVP_MD_CTX *mdctx; + mdctx = EVP_MD_CTX_new(); + + EVP_DigestInit_ex(mdctx, hash_type, NULL); + EVP_DigestUpdate(mdctx, data, strlen(data)); + EVP_DigestFinal_ex(mdctx, hash, &hash_len); + + EVP_MD_CTX_free(mdctx); + + char* hashed = malloc(sizeof(char) * (2 * hash_len + 1)); + for (int i = 0; i < hash_len; i++) { + sprintf(&hashed[i * 2], "%02x", hash[i]); + } + return hashed; +} + +int main(int argc, char *argv[]) { + char digits[256]; + char hash_text[256]; + char hash_type_str[256]; + + int c; + int z_flag = 0, h_flag = 0, t_flag = 0; + + while ((c = getopt(argc, argv, "z:h:t:help")) != -1) { + switch (c) { + case 'z': + strcpy(digits, optarg); + z_flag = 1; + break; + case 'h': + print_help(argv[0]); + exit(EXIT_SUCCESS); + case 't': + strcpy(hash_type_str, optarg); + t_flag = 1; + break; + case '?': + fprintf(stderr, "Invalid option. Use -help for usage information.\n"); + exit(EXIT_FAILURE); + } + } + + if (!(z_flag && h_flag && t_flag)) { + printf("zeichen:"); + fgets(digits, sizeof(digits), stdin); + digits[strcspn(digits, "\n")] = '\0'; + + printf("hash:"); + fgets(hash_text, sizeof(hash_text), stdin); + hash_text[strcspn(hash_text, "\n")] = '\0'; + + printf("Hashtype:"); + fgets(hash_type_str, sizeof(hash_type_str), stdin); + hash_type_str[strcspn(hash_type_str, "\n")] = '\0'; + } + + if (strcmp(hash_type_str, "help") == 0) { + print_help(argv[0]); + exit(EXIT_SUCCESS); + } + + printf("Verfügbare Hashtypen:\n"); + + const EVP_MD *hash_type; + EVP_MD *md; + const char* known_digests[] = {"MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", NULL}; + + for (int i = 0; known_digests[i] != NULL; i++) { + printf("%s,", known_digests[i]); + } + printf("\n"); + + hash_type = EVP_get_digestbyname(hash_type_str); + + if (!hash_type) { + printf("Ungültiger Hash-Typ\n"); + exit(1); + } + + int len = strlen(digits); + int i = 1; + while (1) { + int n = i; + char s[256] = ""; + while (n > 0) { + char digit[2] = {digits[(n - 1) % len], '\0'}; + strcat(s, digit); + n = (n - 1) / len; + } + + // Reverse the string to get correct order + int length = strlen(s); + for (int j = 0; j < length / 2; j++) { + char temp = s[j]; + s[j] = s[length - j - 1]; + s[length - j - 1] = temp; + } + + char* hashed = hash(s, hash_type); + printf("%s %s\n", s, hashed); + + if (strcmp(hashed, hash_text) == 0) { + printf("found: %s %s\n", s, hashed); + free(hashed); + exit(0); + } + free(hashed); + + i++; + } + + return 0; +} diff --git a/python/sha1_encripter.py b/python/sha1_encripter.py new file mode 100644 index 0000000..bbe6165 --- /dev/null +++ b/python/sha1_encripter.py @@ -0,0 +1,24 @@ +import hashlib +def hash(data, hash_type): + return hashlib.new(hash_type, data.encode('utf-8')).hexdigest() if hash_type in hashlib.algorithms_available else "Ungültiger Hash-Typ" + +digits = input("zeichen:") +hash_text = input("hash:") +for a in hashlib.algorithms_available: + print(a,end=",") +print("") +type = input("Hashtype:") + +i = 0 +while 1 : + n =i + s = '' + while n > 0: + s = digits[n % len(digits)] + s + n //= len(digits) + hashed = hash(s,type) + print(s,hashed) + if hashed == hash_text: + print("found: ",s,hashed) + exit() + i += 1 \ No newline at end of file