// Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. private static void MDTimeTrial() { Console.WriteLine("MD5 time trial. Digesting {0} {1}-byte blocks ...", TEST_BLOCK_LEN, TEST_BLOCK_COUNT); /* Initialize block */ byte[] block = new byte[TEST_BLOCK_LEN]; for (int i = 0; i < TEST_BLOCK_LEN; i++) { block[i] = (byte)(i & 0xff); } /* Start timer */ DateTime startTime = DateTime.Now; /* Digest blocks */ MD5 md5 = new MD5(); for (int i = 0; i < TEST_BLOCK_COUNT; i++) { md5.Update(block, TEST_BLOCK_LEN); } byte[] digest = md5.Final(); /* Stop timer */ DateTime endTime = DateTime.Now; TimeSpan time = endTime - startTime; Console.WriteLine("done"); Console.Write("Digest = "); MDPrint(digest); Console.WriteLine(); Console.WriteLine("Time = {0} seconds\n", time.TotalSeconds); Console.WriteLine("Speed = {0} bytes/second", (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT / time.TotalSeconds); }
// Digests a string and prints the result. private static void MDString(string s) { System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("iso-8859-1"); if (encoding == null) { throw new SystemException("Cannot get iso-8859-1 encoding."); } byte[] bytes = encoding.GetBytes(s); MD5 md5 = new MD5(); md5.Update(bytes); byte[] digest = md5.Final(); Console.Write("MD5 (\"{0}\") = ", s); MDPrint(digest); Console.WriteLine(); }
public byte[] CreateKey() { var name_bytes = DatOpener.ToLowerAscii(Name); int name_length = name_bytes.Length; var md5 = new MD5(); Array.Reverse(name_bytes); var key = new byte[1024]; int key_pos = 0; for (int i = 0; i < 64; ++i) { int name_pos = i % name_length; md5.Update(name_bytes, name_pos, name_length - name_pos); md5.Final(); Buffer.BlockCopy(md5.State, 0, key, key_pos, 16); key_pos += 16; } return(key); }
internal static string Digest(string username, string password, string peername) { Encoding encoding = Encoding.GetEncoding("iso-8859-1"); if (encoding == null) { throw new SystemException("Cannot get iso-8859-1 encoding."); } byte[] usernameBytes = encoding.GetBytes(username == null ? "" : username); byte[] passwordBytes = encoding.GetBytes(password == null ? "" : password); byte[] peernameBytes = encoding.GetBytes(peername == null ? "" : peername); MD5 md5 = new MD5(); md5.Update(peernameBytes); md5.Update(usernameBytes); md5.Update(passwordBytes); byte[] digest = md5.Final(); return(encoding.GetString(digest)); }
private static void XX_Encrypt(byte[] thing, int offset, byte[] username) { lock (thePass) { if (thePass[0] == 'x') { String s1 = "7rLrT7iG3kWWLuSDYdS/KIXO8JF86h12KyCTG1Mh0qxWdSZ6ezHRST0UuGl6xkbMgsXj4+eZbXNyYijRmoaaJm+hQCWSOW+0OHGCnYWB4upxi0Fogdu0gb+q4VFzyUFknEpZPg=="; String s2 = "PCuJhpWX5eApg2mRs0bvSIdfwSDUa0kjiSdd76ORgXYyhtLbHm4Uq6afLbfROLi5pDpjKVS9Vr9aZo+F3IpyZ6Zn6m/Xf1PRtq3jdseJht4VSduxHrpocKVdRh3LixXKr6Ue6A=="; byte[] pass1 = Encoding.ASCII.GetBytes(s1); byte[] pass2 = Encoding.ASCII.GetBytes(s2); for (int inx = 0; inx < pass2.Length; inx++) { thePass[inx] = (byte)(pass1[inx] ^ pass2[inx]); if (thePass[inx] == 0) { thePass[inx] = pass1[inx]; } } thePass[136] = 0; } } MD5 md5 = new MD5(); if (username != null && username[0] != 0) { md5.Update(username); } md5.Update(thePass); byte[] md5Bytes = md5.Final(); for (int thingIndex = offset, md5Index = 0; thingIndex < thing.Length; thingIndex++, md5Index++) { thing[thingIndex] = (byte)(thing[thingIndex] ^ md5Bytes[md5Index % md5Bytes.Length]); } }
// Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. private static void MDTimeTrial () { Console.WriteLine ("MD5 time trial. Digesting {0} {1}-byte blocks ...", TEST_BLOCK_LEN, TEST_BLOCK_COUNT); /* Initialize block */ byte[] block = new byte[TEST_BLOCK_LEN]; for (int i = 0; i < TEST_BLOCK_LEN; i++) block[i] = (byte) (i & 0xff); /* Start timer */ DateTime startTime = DateTime.Now; /* Digest blocks */ MD5 md5 = new MD5 (); for (int i = 0; i < TEST_BLOCK_COUNT; i++) md5.Update (block, TEST_BLOCK_LEN); byte[] digest = md5.Final (); /* Stop timer */ DateTime endTime = DateTime.Now; TimeSpan time = endTime - startTime; Console.WriteLine ("done"); Console.Write ("Digest = "); MDPrint (digest); Console.WriteLine (); Console.WriteLine ("Time = {0} seconds\n", time.TotalSeconds); Console.WriteLine ("Speed = {0} bytes/second", (long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / time.TotalSeconds); }
// Digests a string and prints the result. private static void MDString (string s) { System.Text.Encoding encoding = System.Text.Encoding.GetEncoding ("iso-8859-1"); if (encoding == null) throw new SystemException ("Cannot get iso-8859-1 encoding."); byte[] bytes = encoding.GetBytes (s); MD5 md5 = new MD5 (); md5.Update (bytes); byte[] digest = md5.Final (); Console.Write ("MD5 (\"{0}\") = ", s); MDPrint (digest); Console.WriteLine (); }