aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-10 13:50:25 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-10 13:50:25 +0800
commitd4d515b2159dd50b76da060bfa11337bca04feed (patch)
tree335ada5afe1bab5c8b691d26e9cac0b38c2258f4 /src
parent3eab91520c4875ba7ec3ea61c3c544a0332bb082 (diff)
downloadadvent-of-code-d4d515b2159dd50b76da060bfa11337bca04feed.tar.gz
advent-of-code-d4d515b2159dd50b76da060bfa11337bca04feed.zip
md5 in common
Diffstat (limited to 'src')
-rw-r--r--src/2015/day4/aoc.cpp25
-rw-r--r--src/2015/day4/aoc.h3
-rw-r--r--src/md5.cpp26
-rw-r--r--src/md5.h2
4 files changed, 28 insertions, 28 deletions
diff --git a/src/2015/day4/aoc.cpp b/src/2015/day4/aoc.cpp
index ab5f301..34693df 100644
--- a/src/2015/day4/aoc.cpp
+++ b/src/2015/day4/aoc.cpp
@@ -2,31 +2,6 @@
namespace aoc2015 {
-char* md5sum(char* s) {
- static char md5[64] = {0};
- uint8_t* x = md5String(s);
- memset(md5, 0x0, 64);
- for (auto i = 0; i < 16; i++) {
- sprintf(md5 + i * 2, "%02x", x[i]);
- }
- return md5;
-}
-
-int lead_zeros(char* s) {
- char* p = s;
- int total = 0;
- while (*p != '\0') {
- if (*p == '0') {
- total += 1;
- p++;
- }
- else {
- break;
- }
- }
- return total;
-}
-
int day4(const char* secret, int target) {
char buf[128] = {0};
int len = strlen(secret);
diff --git a/src/2015/day4/aoc.h b/src/2015/day4/aoc.h
index 88a38fc..8c4c846 100644
--- a/src/2015/day4/aoc.h
+++ b/src/2015/day4/aoc.h
@@ -4,8 +4,5 @@
namespace aoc2015 {
-char* md5sum(char *);
-int lead_zeros(char*);
int day4(const char*, int);
-
}
diff --git a/src/md5.cpp b/src/md5.cpp
index c11bf2f..0cd4254 100644
--- a/src/md5.cpp
+++ b/src/md5.cpp
@@ -224,4 +224,30 @@ uint8_t* md5File(FILE *file){
uint32_t rotateLeft(uint32_t x, uint32_t n){
return (x << n) | (x >> (32 - n));
}
+
+char* md5sum(char* s) {
+ static char md5[64] = {0};
+ uint8_t* x = md5String(s);
+ memset(md5, 0x0, 64);
+ for (auto i = 0; i < 16; i++) {
+ sprintf(md5 + i * 2, "%02x", x[i]);
+ }
+ return md5;
+}
+
+int lead_zeros(char* s) {
+ char* p = s;
+ int total = 0;
+ while (*p != '\0') {
+ if (*p == '0') {
+ total += 1;
+ p++;
+ }
+ else {
+ break;
+ }
+ }
+ return total;
+}
+
}
diff --git a/src/md5.h b/src/md5.h
index 2726e41..5393e43 100644
--- a/src/md5.h
+++ b/src/md5.h
@@ -27,4 +27,6 @@ uint32_t H(uint32_t X, uint32_t Y, uint32_t Z);
uint32_t I(uint32_t X, uint32_t Y, uint32_t Z);
uint32_t rotateLeft(uint32_t x, uint32_t n);
+char* md5sum(char*);
+int lead_zeros(char* s);
}