Advertisement
Guest User

Convfefe

a guest
Jun 1st, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.76 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <inttypes.h>
  5.  
  6. struct state {uint64_t a,b,c,d,e,f,g,h,i,j,k,l;};
  7. struct block {uint64_t a,b,c,d,e,f,g,h;};
  8.  
  9. /*
  10. [ 0  1 -1  1  1 -1]
  11. [ 1  0  1  1 -1  1]
  12. [-1 -1  0 -1 -1  1]
  13. [-1  1 -1  0  1 -1]
  14. [ 1 -1  1 -1  0  1]
  15. [ 1 -1  1 -1  1  0]
  16.  
  17. [ 0  1 -1  1 -1  1]
  18. [-1  0  1 -1  1 -1]
  19. [-1  1  0  1 -1  1]
  20. [ 1 -1 -1  0  1 -1]
  21. [ 1 -1  1 -1  0  1]
  22. [-1  1 -1  1 -1  0]
  23. */
  24. struct state F(struct state x)
  25. {
  26.     return (struct state) {
  27.         .a = x.b - x.c + x.d + x.e - x.f,
  28.         .b = x.a + x.c + x.d - x.e + x.f,
  29.         .c = x.f - x.a - x.b - x.d - x.e,
  30.         .d = x.b - x.a - x.c + x.e - x.f,
  31.         .e = x.a - x.b + x.c - x.d + x.f,
  32.         .f = x.a - x.b + x.c - x.d + x.e,
  33.  
  34.         .g = x.h - x.i + x.j - x.k + x.l,
  35.         .h = x.i - x.g - x.j + x.k - x.l,
  36.         .i = x.h - x.g + x.j - x.k + x.l,
  37.         .j = x.g - x.h - x.i + x.k - x.l,
  38.         .k = x.g - x.h + x.i - x.j + x.l,
  39.         .l = x.h - x.g - x.i + x.h - x.k
  40.     };
  41. }
  42. uint64_t rotl(uint64_t x, uint8_t r)
  43. {
  44.     return (x << r) | (x >> (64-r));
  45. }
  46. uint64_t rotr(uint64_t x, uint8_t r)
  47. {
  48.     return (x >> r) | (x << (64-r));
  49. }
  50. struct state G(struct state x)
  51. {
  52.     uint64_t t1, t2;
  53.     x.b = rotl(x.b, 17);
  54.     x.c = rotl(x.c,  3);
  55.     x.d = rotl(x.d, 23);
  56.     x.e = rotl(x.e,  7);
  57.     x.f = rotl(x.f, 11);
  58.                      
  59.     x.h = rotl(x.h, 61);
  60.     x.i = rotl(x.i, 41);
  61.     x.j = rotl(x.j,  5);
  62.     x.k = rotl(x.k, 29);
  63.     x.l = rotl(x.l, 47);
  64.    
  65.     t1 = x.a^x.b^x.c^x.d^x.e^x.f;
  66.     t2 = x.g^x.h^x.i^x.j^x.k^x.l;
  67.  
  68.     x.a ^= t1; x.b ^= t1; x.c ^= t1; x.d ^= t1; x.e ^= t1; x.f ^= t1;
  69.     x.g ^= t2; x.h ^= t2; x.i ^= t2; x.j ^= t2; x.k ^= t2; x.l ^= t2;
  70.  
  71.     return (struct state) {
  72.             .a = x.a,
  73.             .b = rotr(x.b, 17),
  74.             .c = rotr(x.c,  3),
  75.             .d = rotr(x.d, 23),
  76.             .e = rotr(x.e,  7),
  77.             .f = rotr(x.f, 11),
  78.  
  79.             .g = x.g,
  80.             .h = rotr(x.h, 61),
  81.             .i = rotr(x.i, 41),
  82.             .j = rotr(x.j,  5),
  83.             .k = rotr(x.k, 29),
  84.             .l = rotr(x.l, 47)
  85.     };
  86. }
  87.  
  88. struct state T(struct state x)
  89. {
  90.     return (struct state) {
  91.         .a = x.b, .b = x.g, .c = x.e,
  92.         .d = x.j, .e = x.l, .f = x.c,
  93.         .g = x.k, .h = x.d, .i = x.f,
  94.         .j = x.a, .k = x.h, .l = x.i
  95.     };
  96. };
  97.  
  98. struct state xor(struct state x, struct state y)
  99. {
  100.  
  101.     return (struct state) {
  102.             .a = x.a^y.a,
  103.             .b = x.b^y.b,
  104.             .c = x.c^y.c,
  105.             .d = x.d^y.d,
  106.             .e = x.e^y.e,
  107.             .f = x.f^y.f,
  108.            
  109.             .g = x.g^y.g,
  110.             .h = x.h^y.h,
  111.             .i = x.i^y.i,
  112.             .j = x.j^y.j,
  113.             .k = x.k^y.k,
  114.             .l = x.l^y.l
  115.     };
  116. }
  117.  
  118. const char* magic = "MakeHashGreatAgainMakeGratedHashAgainGrateAmericanCheezeAgainGreatHashRateMeganMakeAmericaGreatForOnceBakeAmericaGrapeAgain";
  119. struct state cyber(struct state x)
  120. {
  121.     int i;
  122.     const struct state c = *(const struct state *)magic;
  123.  
  124.     x = F(x);
  125.     x = G(x);
  126.     for (i=0; i<11; i++)
  127.     {
  128.         x = T(x);
  129.         x = xor(x, c);
  130.         x = F(x);
  131.         x = G(x);
  132.     }
  133.     return x;
  134. }
  135.  
  136. //message broken into 512-bit blocks, padded with 1-bit followed by zeroes
  137. struct state process_message(const struct block *m,  size_t length, uint64_t count)
  138. {
  139.  
  140.     size_t i;
  141.     struct state s = {0};
  142.     for (i=0; i<length; i++)
  143.     {
  144.         struct state x = {
  145.             .a=0,.b=0,.c=0,.d=count++,
  146.             .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
  147.         };
  148.  
  149.         s = xor(s, cyber(x));
  150.     }
  151.     return s;
  152. }
  153.  
  154. struct block compute_convfefe(struct state s, uint64_t length)
  155. {
  156.     s = cyber(s);
  157.     s.a = 0; s.b = 0; s.c = 0; s.d = length;
  158.     s = cyber(s);
  159.  
  160.     return (struct block) {
  161.         .a = s.a,
  162.         .b = s.b,
  163.         .c = s.c,
  164.         .d = s.d,
  165.         .e = s.e,
  166.         .f = s.f,
  167.         .g = s.g,
  168.         .h = s.h
  169.     };
  170. }
  171.  
  172. int main()
  173. {
  174.     struct block b = {0x8000000000000000,0,0,0};
  175.     struct state s = process_message(&b, 1, 0);
  176.     b = compute_convfefe(s, 1);
  177.     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);
  178.  
  179.     return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement