aoc/src/advent_utility.c

45 lines
1013 B
C
Raw Normal View History

#include <stdlib.h>
2021-09-08 12:12:11 -07:00
#include <string.h>
#include <stdio.h>
#include <md5.h>
#include "advent_utility.h"
struct Point new_Point(int x, int y) {
struct Point p;
p.x = x;
p.y = y;
return p;
}
struct Point *new_Point_p(int x, int y) {
struct Point *p = malloc(sizeof(struct Point));
p->x = x;
p->y = y;
return p;
}
int same_Point(const struct Point* a, const struct Point* b) {
if (a->x == b->x && a->y == b->y) {
return 1;
}
return 0;
}
int same_Point_v(const void *a, const void *b) {
return same_Point((const struct Point *)a, (const struct Point *)b);
}
2021-09-08 12:12:11 -07:00
char *md5_str(const char* input) {
unsigned char digest[16];
struct MD5Context context;
MD5Init(&context);
MD5Update(&context, input, strlen(input));
MD5Final(digest, &context);
char *md5string = malloc(33);
for(int i = 0; i < 16; ++i) {
sprintf(&md5string[i*2], "%02x", (unsigned int)digest[i]);
}
return md5string;
}