mirror of
https://codeberg.org/scip/bubblebabble.git
synced 2025-12-16 19:00:57 +01:00
move to codeberg (#1)
This commit is contained in:
121
bubblebabble.c
121
bubblebabble.c
@@ -30,89 +30,48 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "bubblebabble.h"
|
||||
|
||||
static char *
|
||||
fingerprint_bubblebabble(u_char *dgst_raw, size_t dgst_raw_len)
|
||||
{
|
||||
char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' };
|
||||
char consonants[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
|
||||
'n', 'p', 'r', 's', 't', 'v', 'z', 'x' };
|
||||
u_int i, j = 0, rounds, seed = 1;
|
||||
char *retval;
|
||||
char *fingerprint_bubblebabble(u_char *dgst_raw, size_t dgst_raw_len) {
|
||||
char vowels[] = {'a', 'e', 'i', 'o', 'u', 'y'};
|
||||
char consonants[] = {'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
|
||||
'n', 'p', 'r', 's', 't', 'v', 'z', 'x'};
|
||||
u_int i, j = 0, rounds, seed = 1;
|
||||
char *retval;
|
||||
|
||||
rounds = (dgst_raw_len / 2) + 1;
|
||||
if ((retval = calloc(rounds, 6)) == NULL)
|
||||
return NULL;
|
||||
retval[j++] = 'x';
|
||||
for (i = 0; i < rounds; i++) {
|
||||
u_int idx0, idx1, idx2, idx3, idx4;
|
||||
if ((i + 1 < rounds) || (dgst_raw_len % 2 != 0)) {
|
||||
idx0 = (((((u_int)(dgst_raw[2 * i])) >> 6) & 3) +
|
||||
seed) % 6;
|
||||
idx1 = (((u_int)(dgst_raw[2 * i])) >> 2) & 15;
|
||||
idx2 = ((((u_int)(dgst_raw[2 * i])) & 3) +
|
||||
(seed / 6)) % 6;
|
||||
retval[j++] = vowels[idx0];
|
||||
retval[j++] = consonants[idx1];
|
||||
retval[j++] = vowels[idx2];
|
||||
if ((i + 1) < rounds) {
|
||||
idx3 = (((u_int)(dgst_raw[(2 * i) + 1])) >> 4) & 15;
|
||||
idx4 = (((u_int)(dgst_raw[(2 * i) + 1]))) & 15;
|
||||
retval[j++] = consonants[idx3];
|
||||
retval[j++] = '-';
|
||||
retval[j++] = consonants[idx4];
|
||||
seed = ((seed * 5) +
|
||||
((((u_int)(dgst_raw[2 * i])) * 7) +
|
||||
((u_int)(dgst_raw[(2 * i) + 1])))) % 36;
|
||||
}
|
||||
} else {
|
||||
idx0 = seed % 6;
|
||||
idx1 = 16;
|
||||
idx2 = seed / 6;
|
||||
retval[j++] = vowels[idx0];
|
||||
retval[j++] = consonants[idx1];
|
||||
retval[j++] = vowels[idx2];
|
||||
}
|
||||
}
|
||||
retval[j++] = 'x';
|
||||
retval[j++] = '\0';
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *input;
|
||||
u_char digest[1024];
|
||||
size_t digestlen;
|
||||
char *hash;
|
||||
int out = 1;
|
||||
|
||||
if(argc < 2) {
|
||||
input = stdin;
|
||||
}
|
||||
else {
|
||||
if((input = fopen(argv[1], "rb")) == NULL) {
|
||||
fprintf(stderr, "oops, could not open file!\n");
|
||||
goto done;
|
||||
rounds = (dgst_raw_len / 2) + 1;
|
||||
if ((retval = calloc(rounds, 6)) == NULL)
|
||||
return NULL;
|
||||
retval[j++] = 'x';
|
||||
for (i = 0; i < rounds; i++) {
|
||||
u_int idx0, idx1, idx2, idx3, idx4;
|
||||
if ((i + 1 < rounds) || (dgst_raw_len % 2 != 0)) {
|
||||
idx0 = (((((u_int)(dgst_raw[2 * i])) >> 6) & 3) + seed) % 6;
|
||||
idx1 = (((u_int)(dgst_raw[2 * i])) >> 2) & 15;
|
||||
idx2 = ((((u_int)(dgst_raw[2 * i])) & 3) + (seed / 6)) % 6;
|
||||
retval[j++] = vowels[idx0];
|
||||
retval[j++] = consonants[idx1];
|
||||
retval[j++] = vowels[idx2];
|
||||
if ((i + 1) < rounds) {
|
||||
idx3 = (((u_int)(dgst_raw[(2 * i) + 1])) >> 4) & 15;
|
||||
idx4 = (((u_int)(dgst_raw[(2 * i) + 1]))) & 15;
|
||||
retval[j++] = consonants[idx3];
|
||||
retval[j++] = '-';
|
||||
retval[j++] = consonants[idx4];
|
||||
seed = ((seed * 5) + ((((u_int)(dgst_raw[2 * i])) * 7) +
|
||||
((u_int)(dgst_raw[(2 * i) + 1])))) %
|
||||
36;
|
||||
}
|
||||
} else {
|
||||
idx0 = seed % 6;
|
||||
idx1 = 16;
|
||||
idx2 = seed / 6;
|
||||
retval[j++] = vowels[idx0];
|
||||
retval[j++] = consonants[idx1];
|
||||
retval[j++] = vowels[idx2];
|
||||
}
|
||||
}
|
||||
|
||||
digestlen = fread(digest, 1, 1024, input);
|
||||
|
||||
if(digestlen > 0) {
|
||||
hash = fingerprint_bubblebabble(digest, digestlen);
|
||||
fprintf(stdout, "%s\n", hash);
|
||||
free(hash);
|
||||
out = 0;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "oops, could not calculate bubbles!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
return out;
|
||||
retval[j++] = 'x';
|
||||
retval[j++] = '\0';
|
||||
return retval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user