Created
January 30, 2017 04:57
-
-
Save VictorTaelin/d12aa96e9580dbb422917a77d4ca3c39 to your computer and use it in GitHub Desktop.
hash
This file contains 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
#include <stdio.h> | |
void hash(int* bits, int bitsLen, int* out, int outLen){ | |
const int tt[9] = {1,2,0,0,0,1,1,2,2}; | |
int st[128], i, k, j, x, y, a, b, o = 0; | |
for (int i=0; i<128; ++i) | |
st[i] = i%3; | |
for (k=0; k < bitsLen + outLen; ++k){ | |
for (j=0; j<32; ++j){ | |
if (k < bitsLen) | |
st[0] = bits[k]; | |
for (i=j%2; i<128; i+=2){ | |
x = i%128; | |
y = (i+1)%128; | |
a = st[x]; | |
b = st[y]; | |
st[x] = tt[a*3+b]; | |
st[y] = tt[b*3+a]; | |
}; | |
}; | |
if (k >= bitsLen) | |
out[o++] = (st[0] + st[1]*3 + st[2]*9 + st[3]*27) % 2; | |
}; | |
}; | |
void printHex(int* bits, int bitsLen){ | |
for (int i=0; i<bitsLen/4; ++i) | |
printf("%x", bits[i*4+0]*8+bits[i*4+1]*4+bits[i*4+2]*2+bits[i*4+3]); | |
}; | |
void toBits(int n, int* bits, int bitsLen){ | |
for (int i=0; i<bitsLen; ++i) | |
bits[bitsLen-i-1] = (n >> i) & 1; | |
}; | |
int main(){ | |
const int bitsLen = 16; | |
int bits[bitsLen] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
const int outLen = 256; | |
int out[outLen]; | |
for (int i=0; i<4096; ++i){ | |
toBits(i, bits, bitsLen); | |
hash(bits, bitsLen, out, outLen); | |
printHex(bits, bitsLen); | |
printf(": "); | |
printHex(out, outLen); | |
printf("\n"); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment