c
This commit is contained in:
5
2015_day_4/Makefile
Normal file
5
2015_day_4/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
compile:
|
||||
gcc day4.c -Werror=switch -o day4 -lcrypto
|
||||
|
||||
run:
|
||||
./day4
|
||||
@@ -9,4 +9,10 @@ For example:
|
||||
If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043 starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so.
|
||||
If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like 000006136ef....
|
||||
|
||||
Your puzzle input is yzbqklnj.
|
||||
Your puzzle input is yzbqklnj.
|
||||
|
||||
|
||||
|
||||
|
||||
I'm going to use the RFC 1321 library here, as designing an md5 implementation is a bit too much for right now
|
||||
Correction, I will use the old style openssl/md5.h
|
||||
33
2015_day_4/day4.c
Normal file
33
2015_day_4/day4.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <openssl/md5.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(){
|
||||
printf("\nWEST");
|
||||
const char *input_string = "yzbqklnj";
|
||||
unsigned char output_digest[MD5_DIGEST_LENGTH];
|
||||
unsigned long long int iteration_number = 0;
|
||||
|
||||
//creating empty md5 context
|
||||
MD5_CTX context;
|
||||
|
||||
zeroes = {0,0,0,0,0}
|
||||
//comparing first 5 digits of output
|
||||
while (memcmp(charx, zeros, 5) !=0){
|
||||
if(!MD5_Init(&context)){
|
||||
fprintf(stderr,"Error MD5init failed");
|
||||
return 1;
|
||||
}
|
||||
//suffix generation
|
||||
if(iteration_number !=0){
|
||||
suffix = iteration_number +1;
|
||||
}
|
||||
suffix =
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//input = yzbqklnj
|
||||
Reference in New Issue
Block a user