Show HN: I made a C program to create a vanity SHA-1 hash for a text file

https://news.ycombinator.com/rss Hits: 6
Summary

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <openssl/sha.h> #define TARGET_PREFIX "20250327" #define MAX_WORDS 256 #define MAX_TEXT 2048 #define MAX_ATTEMPTS (1ULL << 32) // 2^32 attempts (~4.3B, enough for 8-char prefix) const char *ORIGINAL_TEXT = "They're not particularly rare, but I think they're more pleasing to see.\n\n" "For instance this \"2822302\" makes me especially happy: https://github.com/BrowserBox/BrowserBox/commit/2822302387c4cb7ff71c4239da3dc5fa4c07e165\n\n" "It even extends up to 10 digits! That's not particularly rare - roughly 1% chance (10^10/16^10 i think) - but I just think they look nice.\n\n" "Are there any other people out there who are particularly pleased when they hit that? Sorta like hitting 7777 on the odometer, or whatever.\n\n" "I'm also a fan of the purely numeric identifiers Twitter/X uses (and has for ages).\n\n" "This all reminds me of that \"commit fuzzing tool\" that can make your log have whatever commit you want. Asked AI, turns out it's: https://github.com/not-an-aardvark/lucky-commit\n\n" "Lucky Commit! What a perfect name. I guess this Ask HN should be: Does anyone else like lucky commits?\n\n" "BTW the SHA has of this message starts with: 20250327"; typedef struct { char *lower; char *upper; int start; int len; } Word; void normalize_text(char *dest, const char *src, int len) { int j = 0, last_space = 0; for (int i = 0; i < len && src[i]; i++) { if (32 == src[i]) { if (!last_space && j > 0) dest[j++] = ' '; last_space = 1; } else { dest[j++] = src[i]; last_space = 0; } } dest[j] = '\0'; } void compute_hash(const char *text, char *hash_str) { unsigned char hash[SHA_DIGEST_LENGTH]; SHA1((unsigned char *)text, strlen(text), hash); for (int i = 0; i < SHA_DIGEST_LENGTH; i++) { sprintf(hash_str + (i * 2), "%02x", hash[i]); } hash_str[SHA_DIGEST_LENGTH * 2] = '\0'; } int is_in_url(int pos, const char *text) { const char *ptr = text; while (ptr < text + pos) { if (strncmp(ptr, "http", ...

First seen: 2025-03-31 17:43

Last seen: 2025-03-31 23:44