Created
June 19, 2024 04:07
-
-
Save grishka/ed84e4bbfacfbcf4ddc5e63cfc966c69 to your computer and use it in GitHub Desktop.
SHA-256 brute-forcer for https://shallenge.quirino.net
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
// | |
// main.c | |
// shallenge | |
// | |
// Created by Grishka on 19.06.2024. | |
// | |
#include <stdio.h> | |
#include <CommonCrypto/CommonDigest.h> | |
#include <pthread.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#define NTHREADS 10 | |
pthread_mutex_t printMutex; | |
void* threadEntry(void *arg){ | |
unsigned int threadIndex=(unsigned int)(((size_t)arg) & 0xF); | |
printf("Thread %d starting\n", (int)threadIndex); | |
char strToHash[]="grishka/What+am+I+doing+with+my+life/AppleM1Max+CPU/00000000"; | |
//const char *hex="0123456789abcdef"; | |
//const char *hex="wxyzWXYZ+/123456789"; | |
const char *alphabet="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM+/"; | |
unsigned int len=(unsigned int)strlen(strToHash); | |
unsigned char hash[32]; | |
unsigned int *hashAsInts=(unsigned int*)hash; | |
for(uint64_t i=threadIndex;i<=0xffffffffffff;i+=NTHREADS){ | |
/*strToHash[len-1]=hex[i & 0xF]; | |
strToHash[len-2]=hex[(i >> 4) & 0xF]; | |
strToHash[len-3]=hex[(i >> 8) & 0xF]; | |
strToHash[len-4]=hex[(i >> 12) & 0xF]; | |
strToHash[len-5]=hex[(i >> 16) & 0xF]; | |
strToHash[len-6]=hex[(i >> 20) & 0xF]; | |
strToHash[len-7]=hex[(i >> 24) & 0xF]; | |
strToHash[len-8]=hex[(i >> 28) & 0xF];*/ | |
strToHash[len-1]=alphabet[i & 63]; | |
strToHash[len-2]=alphabet[(i >> 6) & 63]; | |
strToHash[len-3]=alphabet[(i >> 12) & 63]; | |
strToHash[len-4]=alphabet[(i >> 18) & 63]; | |
strToHash[len-5]=alphabet[(i >> 24) & 63]; | |
strToHash[len-6]=alphabet[(i >> 30) & 63]; | |
strToHash[len-7]=alphabet[(i >> 36) & 63]; | |
strToHash[len-8]=alphabet[(i >> 42) & 63]; | |
CC_SHA256(strToHash, len, hash); | |
//if((hashAsInts[0] & 0x0000ffff)==0){ | |
if(hashAsInts[0]==0){ | |
pthread_mutex_lock(&printMutex); | |
printf("%s:\n", strToHash); | |
for(int i=0;i<32;i++){ | |
if(i>0 && i%4==0) | |
printf(" "); | |
printf("%02x", hash[i]); | |
} | |
printf("\n\n"); | |
pthread_mutex_unlock(&printMutex); | |
} | |
} | |
printf("Thread %d exiting\n", (int)threadIndex); | |
return NULL; | |
} | |
int main(int argc, const char * argv[]) { | |
pthread_mutex_init(&printMutex, NULL); | |
pthread_t threads[NTHREADS]; | |
for(size_t i=0;i<NTHREADS;i++){ | |
pthread_create(&threads[i], NULL, threadEntry, (void*)i); | |
} | |
for(size_t i=0;i<NTHREADS;i++){ | |
pthread_join(threads[i], NULL); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment