Created
November 21, 2025 19:14
-
-
Save leok7v/afec90425c24b88684666fd7cf1ff878 to your computer and use it in GitHub Desktop.
Identifiers that are Readable, Spellable, and Pronounceable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* This file is part of proquint: http://github.com/dsw/proquint . | |
| See License.txt for copyright and terms of use. */ | |
| /* | |
| Convert between proquint, hex, and decimal strings. | |
| Please see the article on proquints: http://arXiv.org/html/0901.4016 | |
| Daniel S. Wilkerson | |
| */ | |
| #include "proquint.h" | |
| static const char consonants[] = "bdfghjklmnprstvz"; | |
| static const char vowels[] = "aiou"; | |
| void uint2quint(char *quint /*output*/, uint32_t i, int sepChar) { | |
| uint32_t j; | |
| int bitwidths[5] = {4, 2, 4, 2, 4}; | |
| for (int q = 0; q < 2; q++) { | |
| for (int s = 0; s < 5; s++) { | |
| int bw = bitwidths[s]; | |
| uint32_t mask = (bw == 4 ? 0xF0000000U : 0xC0000000U); | |
| j = i & mask; | |
| i <<= bw; | |
| j >>= (32 - bw); | |
| *quint++ = (bw == 4 ? consonants[j] : vowels[j]); | |
| } | |
| if (q == 0 && sepChar) { | |
| *quint++ = (char)sepChar; | |
| } | |
| } | |
| } | |
| uint32_t quint2uint(const char *quint) { | |
| uint32_t res = 0; | |
| char c; | |
| const char *p; | |
| while ((c = *quint++)) { | |
| if ((p = strchr(consonants, c))) { | |
| res <<= 4; | |
| res += (p - consonants); | |
| } else if ((p = strchr(vowels, c))) { | |
| res <<= 2; | |
| res += (p - vowels); | |
| } | |
| /* Skip separators or invalid characters */ | |
| } | |
| return res; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* This file is part of proquint: http://github.com/dsw/proquint . | |
| See License.txt for copyright and terms of use. */ | |
| #ifndef PROQUINT_H | |
| #define PROQUINT_H | |
| /* | |
| Convert between proquint, hex, and decimal strings. | |
| Please see the article on proquints: http://arXiv.org/html/0901.4016 | |
| Daniel S. Wilkerson | |
| Four-bits as a consonant: | |
| 0 1 2 3 4 5 6 7 8 9 A B C D E F | |
| b d f g h j k l m n p r s t v z | |
| Two-bits as a vowel: | |
| 0 1 2 3 | |
| a i o u | |
| Whole 16-bit word, where "con" = consonant, "vo" = vowel. | |
| 0 1 2 3 4 5 6 7 8 9 A B C D E F | |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| |con0 |vo1|con2 |vo3|con4 | | |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| |-Hex0--|-Hex1--|-Hex2--|-Hex3--| | |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| */ | |
| /* Assume that unsigned int is 32-bits; change this otherwise. */ | |
| typedef unsigned int uint32_t; | |
| /* Map a uint to two quints using optional sepCar to separate them. */ | |
| void uint2quint(char *quint /*output*/, uint32_t i, int sepChar); | |
| /* Map a quint to a uint, skipping non-coding characters. */ | |
| uint32_t quint2uint(char const *quint); | |
| #endif /* PROQUINT_H */ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful for Lorem Ipsum and password generators