fork(6) download
  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<unistd.h>
  4. #include<string.h>
  5. typedef unsigned int uint;
  6.  
  7. using namespace std;
  8.  
  9. union block{
  10. uint v[16];
  11. char s[64];
  12. };
  13.  
  14. uint h0, h1, h2, h3, h4;
  15.  
  16. uint LR(uint a, int x){
  17. return a << x | a >> 32-x;
  18. }
  19.  
  20. block buf[10000];
  21.  
  22. int main()
  23. {
  24. h0 = 0x67452301;
  25. h1 = 0xEFCDAB89;
  26. h2 = 0x98BADCFE;
  27. h3 = 0x10325476;
  28. h4 = 0xC3D2E1F0;
  29.  
  30. int len = read(0, buf[0].s, 640000), nbits = len * 8;
  31. buf[0].s[len++] = 0x80;
  32. printf("%d\n", nbits);
  33.  
  34. // if(len%64 != 56) return !printf("length != 55 (mod 64)\n");
  35.  
  36. uint nblock = (len+7)/64 + 1;
  37. buf[nblock-1].v[14] = 0;
  38. buf[nblock-1].v[15] = nbits;
  39.  
  40. for(int t = 0; t < nblock; t++){
  41. block cur = buf[t];
  42. printf("\n\n");
  43. for(int i = 0; i < 64; i++) printf("%c", cur.s[i]);
  44. printf("\n\n");
  45. for(int i = 0; i < 16; i++){
  46. if(t == nblock-1 && i == 15) continue;
  47. swap(cur.s[i*4+0], cur.s[i*4+3]);
  48. swap(cur.s[i*4+1], cur.s[i*4+2]);
  49. }
  50. uint w[16];
  51. for(int i = 0; i < 16; i++) w[i] = cur.v[i];
  52.  
  53. uint a, b, c, d, e, f, k;
  54. a = h0; b = h1; c = h2; d = h3; e = h4;
  55. for(int i = 0; i < 80; i++){
  56. if(i >= 16) w[i%16] = LR(w[(i-3+16)%16]^w[(i-8+16)%16]^w[(i-14+16)%16]^w[(i-16+16)%16], 1);
  57. if(i <= 19){
  58. f = (b&c)|(~b&d);
  59. k = 0x5A827999;
  60. }
  61. else if(i <= 39){
  62. f = (b^c^d);
  63. k = 0x6ED9EBA1;
  64. }
  65. else if(i <= 59){
  66. f = (b&c)|(b&d)|(c&d);
  67. k = 0x8F1BBCDC;
  68. }
  69. else if(i <= 79){
  70. f = b^c^d;
  71. k = 0xCA62C1D6;
  72. }
  73. uint tmp = LR(a, 5) + f + e + k + w[i%16];
  74. e = d; d = c; c = LR(b, 30); b = a; a = tmp;
  75. }
  76. h0 = h0 + a;
  77. h1 = h1 + b;
  78. h2 = h2 + c;
  79. h3 = h3 + d;
  80. h4 = h4 + e;
  81. printf("h0 = 0x%08x; h1 = 0x%08x; h2 = 0x%08x; h3 = 0x%08x; h4 = 0x%08x;\n", h0, h1, h2, h3, h4);
  82. }
  83. printf("%d\n", nbits);
  84. printf("%08x %08x %08x %08x %08x\n", h0, h1, h2, h3, h4);
  85. }
  86.  
Success #stdin #stdout 0s 15856KB
stdin
Standard input is empty
stdout
0


�

h0 = 0xda39a3ee; h1 = 0x5e6b4b0d; h2 = 0x3255bfef; h3 = 0x95601890; h4 = 0xafd80709;
0
da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709