aboutsummaryrefslogtreecommitdiff
path: root/src/md5.cpp
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/md5.cpp
parent3eab91520c4875ba7ec3ea61c3c544a0332bb082 (diff)
downloadadvent-of-code-d4d515b2159dd50b76da060bfa11337bca04feed.tar.gz
advent-of-code-d4d515b2159dd50b76da060bfa11337bca04feed.zip
md5 in common
Diffstat (limited to 'src/md5.cpp')
-rw-r--r--src/md5.cpp26
1 files changed, 26 insertions, 0 deletions
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;
+}
+
}