[转载]MD5算法之C#程序 MD5算法描述[4]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 austinlei 的 blog

      gg (ref b, c, d, a, x[k+ 8], s24, 0x455a14ed); /* 28 */
      gg (ref a, b, c, d, x[k+13], s21, 0xa9e3e905); /* 29 */
      gg (ref d, a, b, c, x[k+ 2], s22, 0xfcefa3f8); /* 30 */
      gg (ref c, d, a, b, x[k+ 7], s23, 0x676f02d9); /* 31 */
      gg (ref b, c, d, a, x[k+12], s24, 0x8d2a4c8a); /* 32 */

      /* round 3 */
      hh (ref a, b, c, d, x[k+ 5], s31, 0xfffa3942); /* 33 */
      hh (ref d, a, b, c, x[k+ 8], s32, 0x8771f681); /* 34 */
      hh (ref c, d, a, b, x[k+11], s33, 0x6d9d6122); /* 35 */
      hh (ref b, c, d, a, x[k+14], s34, 0xfde5380c); /* 36 */
      hh (ref a, b, c, d, x[k+ 1], s31, 0xa4beea44); /* 37 */
      hh (ref d, a, b, c, x[k+ 4], s32, 0x4bdecfa9); /* 38 */
      hh (ref c, d, a, b, x[k+ 7], s33, 0xf6bb4b60); /* 39 */
      hh (ref b, c, d, a, x[k+10], s34, 0xbebfbc70); /* 40 */
      hh (ref a, b, c, d, x[k+13], s31, 0x289b7ec6); /* 41 */
      hh (ref d, a, b, c, x[k+ 0], s32, 0xeaa127fa); /* 42 */
      hh (ref c, d, a, b, x[k+ 3], s33, 0xd4ef3085); /* 43 */
      hh (ref b, c, d, a, x[k+ 6], s34,  0x4881d05); /* 44 */
      hh (ref a, b, c, d, x[k+ 9], s31, 0xd9d4d039); /* 45 */
      hh (ref d, a, b, c, x[k+12], s32, 0xe6db99e5); /* 46 */
      hh (ref c, d, a, b, x[k+15], s33, 0x1fa27cf8); /* 47 */
      hh (ref b, c, d, a, x[k+ 2], s34, 0xc4ac5665); /* 48 */

      /* round 4 */
      ii (ref a, b, c, d, x[k+ 0], s41, 0xf4292244); /* 49 */
      ii (ref d, a, b, c, x[k+ 7], s42, 0x432aff97); /* 50 */
      ii (ref c, d, a, b, x[k+14], s43, 0xab9423a7); /* 51 */
      ii (ref b, c, d, a, x[k+ 5], s44, 0xfc93a039); /* 52 */
      ii (ref a, b, c, d, x[k+12], s41, 0x655b59c3); /* 53 */
      ii (ref d, a, b, c, x[k+ 3], s42, 0x8f0ccc92); /* 54 */
      ii (ref c, d, a, b, x[k+10], s43, 0xffeff47d); /* 55 */
      ii (ref b, c, d, a, x[k+ 1], s44, 0x85845dd1); /* 56 */
      ii (ref a, b, c, d, x[k+ 8], s41, 0x6fa87e4f); /* 57 */
      ii (ref d, a, b, c, x[k+15], s42, 0xfe2ce6e0); /* 58 */
      ii (ref c, d, a, b, x[k+ 6], s43, 0xa3014314); /* 59 */
      ii (ref b, c, d, a, x[k+13], s44, 0x4e0811a1); /* 60 */
      ii (ref a, b, c, d, x[k+ 4], s41, 0xf7537e82); /* 61 */
      ii (ref d, a, b, c, x[k+11], s42, 0xbd3af235); /* 62 */
      ii (ref c, d, a, b, x[k+ 2], s43, 0x2ad7d2bb); /* 63 */
      ii (ref b, c, d, a, x[k+ 9], s44, 0xeb86d391); /* 64 */

      a+=a;
      b+=b;
      c+=c;
      d+=d;
    }
    return new uint32[]{a,b,c,d};
  }
  public static byte[] md5array(byte[] input){
    md5_init();
    uint32[] block = md5_append(input);
    uint32[] bits = md5_trasform(block);

    /* encodes bits (uint32[]) into output (byte[]). assumes len is
     * a multiple of 4.
         */
    byte[] output=new byte[bits.length*4];
    for(int i=0,j=0;i<bits.length;i++,j+=4){
      output[j] = (byte)(bits[i] & 0xff);
      output[j+1] = (byte)((bits[i] >> 8) & 0xff);
      output[j+2] = (byte)((bits[i] >> 16) & 0xff);
      output[j+3] = (byte)((bits[i] >> 24) & 0xff);
    }
    return output;
  }

  public static string arraytohexstring(byte[] array,bool uppercase){
    string hexstring="";
    string format="x2";
    if(uppercase){
      format="x2";
    }
    foreach(byte b in array){

本文关键:[转载]MD5算法之C#程序 MD5算法描述
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top