PageRenderTime 110ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 56 lines | 41 code | 3 blank | 12 comment | 2 complexity | 511779e99fcbcf657586d9fca60a6615 MD5 | raw file
 1/**
 2 * MD2Test
 3 * 
 4 * A test class for MD2
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.crypto.tests
10{
11	import com.hurlant.crypto.hash.MD2;
12	import com.hurlant.util.Hex;
13	
14	import flash.utils.ByteArray;
15	
16	public class MD2Test extends TestCase
17	{
18		public function MD2Test(h:ITestHarness)
19		{
20			super(h, "MD2 Test");
21			runTest(testMd2, "MD2 Test Vectors");
22			h.endTestCase();
23		}
24		
25		/**
26		 * Test Vectors grabbed from
27		 * http://www.faqs.org/rfcs/rfc1319.html
28		 */
29		public function testMd2():void {
30			var srcs:Array = [
31			"",
32			Hex.fromString("a"),
33			Hex.fromString("abc"),
34			Hex.fromString("message digest"),
35			Hex.fromString("abcdefghijklmnopqrstuvwxyz"),
36			Hex.fromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
37			Hex.fromString("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
38			];
39			var hashes:Array = [
40			"8350e5a3e24c153df2275c9f80692773",
41			"32ec01ec4a6dac72c0ab96fb34c0b5d1",
42			"da853b0d3f88d99b30283a69e6ded6bb",
43			"ab4f496bfb2a530b219ff33031fe06b0",
44			"4e8ddff3650292ab5a4108c3aa47940b",
45			"da33def2a42df13975352846c30338cd",
46			"d5976f79d83d3a0dc9806c3c66f3efd8"
47			];
48			var md2:MD2 = new MD2;
49			for (var i:uint=0;i<srcs.length;i++) {
50				var src:ByteArray = Hex.toArray(srcs[i]);
51				var digest:ByteArray = md2.hash(src);
52				assert("MD2 Test "+i, Hex.fromArray(digest) == hashes[i]);
53			}
54		}
55	}
56}