Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <inttypes.h>
- struct state {uint64_t a,b,c,d,e,f,g,h,i,j,k,l;};
- struct block {uint64_t a,b,c,d,e,f,g,h;};
- /*
- [ 0 1 -1 1 1 -1]
- [ 1 0 1 1 -1 1]
- [-1 -1 0 -1 -1 1]
- [-1 1 -1 0 1 -1]
- [ 1 -1 1 -1 0 1]
- [ 1 -1 1 -1 1 0]
- [ 0 1 -1 1 -1 1]
- [-1 0 1 -1 1 -1]
- [-1 1 0 1 -1 1]
- [ 1 -1 -1 0 1 -1]
- [ 1 -1 1 -1 0 1]
- [-1 1 -1 1 -1 0]
- */
- struct state F(struct state x)
- {
- return (struct state) {
- .a = x.b - x.c + x.d + x.e - x.f,
- .b = x.a + x.c + x.d - x.e + x.f,
- .c = x.f - x.a - x.b - x.d - x.e,
- .d = x.b - x.a - x.c + x.e - x.f,
- .e = x.a - x.b + x.c - x.d + x.f,
- .f = x.a - x.b + x.c - x.d + x.e,
- .g = x.h - x.i + x.j - x.k + x.l,
- .h = x.i - x.g - x.j + x.k - x.l,
- .i = x.h - x.g + x.j - x.k + x.l,
- .j = x.g - x.h - x.i + x.k - x.l,
- .k = x.g - x.h + x.i - x.j + x.l,
- .l = x.h - x.g - x.i + x.h - x.k
- };
- }
- uint64_t rotl(uint64_t x, uint8_t r)
- {
- return (x << r) | (x >> (64-r));
- }
- uint64_t rotr(uint64_t x, uint8_t r)
- {
- return (x >> r) | (x << (64-r));
- }
- struct state G(struct state x)
- {
- uint64_t t1, t2;
- x.b = rotl(x.b, 17);
- x.c = rotl(x.c, 3);
- x.d = rotl(x.d, 23);
- x.e = rotl(x.e, 7);
- x.f = rotl(x.f, 11);
- x.h = rotl(x.h, 61);
- x.i = rotl(x.i, 41);
- x.j = rotl(x.j, 5);
- x.k = rotl(x.k, 29);
- x.l = rotl(x.l, 47);
- t1 = x.a^x.b^x.c^x.d^x.e^x.f;
- t2 = x.g^x.h^x.i^x.j^x.k^x.l;
- x.a ^= t1; x.b ^= t1; x.c ^= t1; x.d ^= t1; x.e ^= t1; x.f ^= t1;
- x.g ^= t2; x.h ^= t2; x.i ^= t2; x.j ^= t2; x.k ^= t2; x.l ^= t2;
- return (struct state) {
- .a = x.a,
- .b = rotr(x.b, 17),
- .c = rotr(x.c, 3),
- .d = rotr(x.d, 23),
- .e = rotr(x.e, 7),
- .f = rotr(x.f, 11),
- .g = x.g,
- .h = rotr(x.h, 61),
- .i = rotr(x.i, 41),
- .j = rotr(x.j, 5),
- .k = rotr(x.k, 29),
- .l = rotr(x.l, 47)
- };
- }
- struct state T(struct state x)
- {
- return (struct state) {
- .a = x.b, .b = x.g, .c = x.e,
- .d = x.j, .e = x.l, .f = x.c,
- .g = x.k, .h = x.d, .i = x.f,
- .j = x.a, .k = x.h, .l = x.i
- };
- };
- struct state xor(struct state x, struct state y)
- {
- return (struct state) {
- .a = x.a^y.a,
- .b = x.b^y.b,
- .c = x.c^y.c,
- .d = x.d^y.d,
- .e = x.e^y.e,
- .f = x.f^y.f,
- .g = x.g^y.g,
- .h = x.h^y.h,
- .i = x.i^y.i,
- .j = x.j^y.j,
- .k = x.k^y.k,
- .l = x.l^y.l
- };
- }
- const char* magic = "MakeHashGreatAgainMakeGratedHashAgainGrateAmericanCheezeAgainGreatHashRateMeganMakeAmericaGreatForOnceBakeAmericaGrapeAgain";
- struct state cyber(struct state x)
- {
- int i;
- const struct state c = *(const struct state *)magic;
- x = F(x);
- x = G(x);
- for (i=0; i<11; i++)
- {
- x = T(x);
- x = xor(x, c);
- x = F(x);
- x = G(x);
- }
- return x;
- }
- //message broken into 512-bit blocks, padded with 1-bit followed by zeroes
- struct state process_message(const struct block *m, size_t length, uint64_t count)
- {
- size_t i;
- struct state s = {0};
- for (i=0; i<length; i++)
- {
- struct state x = {
- .a=0,.b=0,.c=0,.d=count++,
- .e=m[i].a,.f=m[i].b,.g=m[i].c,.h=m[i].d,.i=m[i].e,.j=m[i].f,.k=m[i].g,.l=m[i].h
- };
- s = xor(s, cyber(x));
- }
- return s;
- }
- struct block compute_convfefe(struct state s, uint64_t length)
- {
- s = cyber(s);
- s.a = 0; s.b = 0; s.c = 0; s.d = length;
- s = cyber(s);
- return (struct block) {
- .a = s.a,
- .b = s.b,
- .c = s.c,
- .d = s.d,
- .e = s.e,
- .f = s.f,
- .g = s.g,
- .h = s.h
- };
- }
- int main()
- {
- struct block b = {0x8000000000000000,0,0,0};
- struct state s = process_message(&b, 1, 0);
- b = compute_convfefe(s, 1);
- printf("%016"PRIx64",%016"PRIx64",%016"PRIx64",%016"PRIx64",%016"PRIx64",%016"PRIx64",%016"PRIx64",%016"PRIx64"\n", b.a,b.b,b.c,b.d,b.e,b.f,b.g,b.h);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement