PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 66 lines | 45 code | 7 blank | 14 comment | 1 complexity | f2b74d2fe48379a963ff5732c64835d5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * XTeaKeyTest
  3. *
  4. * A test class for XTeaKey
  5. * Copyright (c) 2007 Henri Torgemane
  6. *
  7. * See LICENSE.txt for full license information.
  8. */
  9. package com.hurlant.crypto.tests
  10. {
  11. import com.hurlant.crypto.prng.Random;
  12. import com.hurlant.crypto.symmetric.ECBMode;
  13. import com.hurlant.crypto.symmetric.XTeaKey;
  14. import com.hurlant.util.Hex;
  15. import flash.utils.ByteArray;
  16. import flash.utils.getTimer;
  17. public class XTeaKeyTest extends TestCase
  18. {
  19. public function XTeaKeyTest(h:ITestHarness) {
  20. super(h, "XTeaKey Test");
  21. runTest(testGetBlockSize, "XTea Block Size");
  22. runTest(testVectors, "XTea Test Vectors");
  23. h.endTestCase();
  24. }
  25. public function testGetBlockSize():void {
  26. var tea:XTeaKey = new XTeaKey(Hex.toArray("deadbabecafebeefdeadbabecafebeef"));
  27. assert("tea blocksize", tea.getBlockSize()==8);
  28. }
  29. public function testVectors():void {
  30. // blah.
  31. // can't find working test vectors.
  32. // algorithms should not get published without vectors :(
  33. var keys:Array=[
  34. "00000000000000000000000000000000",
  35. "2b02056806144976775d0e266c287843"];
  36. var pts:Array=[
  37. "0000000000000000",
  38. "74657374206d652e"];
  39. var cts:Array=[
  40. "2dc7e8d3695b0538",
  41. "7909582138198783"];
  42. // self-fullfilling vectors.
  43. // oh well, at least I can decrypt what I produce. :(
  44. for (var i:uint=0;i<keys.length;i++) {
  45. var key:ByteArray = Hex.toArray(keys[i]);
  46. var pt:ByteArray = Hex.toArray(pts[i]);
  47. var tea:XTeaKey = new XTeaKey(key);
  48. tea.encrypt(pt);
  49. var out:String = Hex.fromArray(pt);
  50. assert("comparing "+cts[i]+" to "+out, cts[i]==out);
  51. // now go back to plaintext.
  52. pt.position=0;
  53. tea.decrypt(pt);
  54. out = Hex.fromArray(pt);
  55. assert("comparing "+pts[i]+" to "+out, pts[i]==out);
  56. }
  57. }
  58. }
  59. }