Get the latest tech news

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


gcc -O2 -o vanity vanity.c -lssl -lcrypto. GitHub Gist: instantly share code, notes, and snippets.

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? Asked AI, turns out it's: https://github.com/not-an-aardvark/lucky-commit\n\n""Lucky Commit! 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";typedefstruct {char*lower;char*upper;intstart;intlen;} Word;voidnormalize_text(char*dest, constchar*src, intlen) {intj=0, last_space=0;for (inti=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';}voidcompute_hash(constchar*text, char*hash_str) { unsigned charhash[SHA_DIGEST_LENGTH];SHA1((unsigned char*)text, strlen(text), hash);for (inti=0; i<SHA_DIGEST_LENGTH; i++) {sprintf(hash_str+ (i*2), "%02x", hash[i]); }hash_str[SHA_DIGEST_LENGTH*2] ='\0';}intis_in_url(intpos, constchar*text) {constchar*ptr=text;while (ptr<text+pos) {if (strncmp(ptr, "http", 4) ==0) {constchar*start=ptr;while (*ptr&& !isspace(*ptr)) ptr++;if (pos >= start-text&&pos<ptr-text) return1; } else {ptr++; } }return0;}intparse_words(constchar*text, Word*words, int*skip_indices, int*mutable_count) {intword_count=0, i=0, start=0;inttext_len=strlen(text);char*buf=malloc(text_len+1);while (i <= text_len) {if (i==text_len||text[i] ==32) {if (i>start) {intlen=i-start;strncpy(buf, text+start, len);buf[len] ='\0';if (strncmp(buf, "http", 4) ==0|| !isalpha(buf[0])) {skip_indices[word_count] =1; } else {words[*mutable_count].lower=strdup(buf);words[*mutable_count].upper=strdup(buf);words[*mutable_count].upper[0] =toupper(buf[0]);words[*mutable_count].lower[0] =tolower(buf[0]);words[*mutable_count].start=start;words[*mutable_count].len=len; (*mutable_count)++; }word_count++; }start=i+1; }i++; }free(buf);returnword_count;}intmain(intargc, char*argv[]) {constchar*file_path= (argc>1) ?

Get the Android app

Or read this on Hacker News

Read more on:

Photo of text file

text file

Photo of C program

C program

Photo of vanity SHA-1 hash

vanity SHA-1 hash

Related news:

News photo

Show HN: Vomitorium – all of your project in 1 text file

News photo

The text file that runs the internet

News photo

Synthesia launches LLM-powered assistant to turn any text file or link into AI video