Subversion Repositories cryptochat

Rev

View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. /*
  2. CryptoJS v3.1.2
  3. code.google.com/p/crypto-js
  4. (c) 2009-2013 by Jeff Mott. All rights reserved.
  5. code.google.com/p/crypto-js/wiki/License
  6. */
  7. (function () {
  8.     // Shortcuts
  9.     var C = CryptoJS;
  10.     var C_lib = C.lib;
  11.     var WordArray = C_lib.WordArray;
  12.     var BlockCipher = C_lib.BlockCipher;
  13.     var C_algo = C.algo;
  14.  
  15.     // Permuted Choice 1 constants
  16.     var PC1 = [
  17.         57, 49, 41, 33, 25, 17, 9,  1,
  18.         58, 50, 42, 34, 26, 18, 10, 2,
  19.         59, 51, 43, 35, 27, 19, 11, 3,
  20.         60, 52, 44, 36, 63, 55, 47, 39,
  21.         31, 23, 15, 7,  62, 54, 46, 38,
  22.         30, 22, 14, 6,  61, 53, 45, 37,
  23.         29, 21, 13, 5,  28, 20, 12, 4
  24.     ];
  25.  
  26.     // Permuted Choice 2 constants
  27.     var PC2 = [
  28.         14, 17, 11, 24, 1,  5,
  29.         3,  28, 15, 6,  21, 10,
  30.         23, 19, 12, 4,  26, 8,
  31.         16, 7,  27, 20, 13, 2,
  32.         41, 52, 31, 37, 47, 55,
  33.         30, 40, 51, 45, 33, 48,
  34.         44, 49, 39, 56, 34, 53,
  35.         46, 42, 50, 36, 29, 32
  36.     ];
  37.  
  38.     // Cumulative bit shift constants
  39.     var BIT_SHIFTS = [1,  2,  4,  6,  8,  10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  40.  
  41.     // SBOXes and round permutation constants
  42.     var SBOX_P = [
  43.         {
  44.             0x0: 0x808200,
  45.             0x10000000: 0x8000,
  46.             0x20000000: 0x808002,
  47.             0x30000000: 0x2,
  48.             0x40000000: 0x200,
  49.             0x50000000: 0x808202,
  50.             0x60000000: 0x800202,
  51.             0x70000000: 0x800000,
  52.             0x80000000: 0x202,
  53.             0x90000000: 0x800200,
  54.             0xa0000000: 0x8200,
  55.             0xb0000000: 0x808000,
  56.             0xc0000000: 0x8002,
  57.             0xd0000000: 0x800002,
  58.             0xe0000000: 0x0,
  59.             0xf0000000: 0x8202,
  60.             0x8000000: 0x0,
  61.             0x18000000: 0x808202,
  62.             0x28000000: 0x8202,
  63.             0x38000000: 0x8000,
  64.             0x48000000: 0x808200,
  65.             0x58000000: 0x200,
  66.             0x68000000: 0x808002,
  67.             0x78000000: 0x2,
  68.             0x88000000: 0x800200,
  69.             0x98000000: 0x8200,
  70.             0xa8000000: 0x808000,
  71.             0xb8000000: 0x800202,
  72.             0xc8000000: 0x800002,
  73.             0xd8000000: 0x8002,
  74.             0xe8000000: 0x202,
  75.             0xf8000000: 0x800000,
  76.             0x1: 0x8000,
  77.             0x10000001: 0x2,
  78.             0x20000001: 0x808200,
  79.             0x30000001: 0x800000,
  80.             0x40000001: 0x808002,
  81.             0x50000001: 0x8200,
  82.             0x60000001: 0x200,
  83.             0x70000001: 0x800202,
  84.             0x80000001: 0x808202,
  85.             0x90000001: 0x808000,
  86.             0xa0000001: 0x800002,
  87.             0xb0000001: 0x8202,
  88.             0xc0000001: 0x202,
  89.             0xd0000001: 0x800200,
  90.             0xe0000001: 0x8002,
  91.             0xf0000001: 0x0,
  92.             0x8000001: 0x808202,
  93.             0x18000001: 0x808000,
  94.             0x28000001: 0x800000,
  95.             0x38000001: 0x200,
  96.             0x48000001: 0x8000,
  97.             0x58000001: 0x800002,
  98.             0x68000001: 0x2,
  99.             0x78000001: 0x8202,
  100.             0x88000001: 0x8002,
  101.             0x98000001: 0x800202,
  102.             0xa8000001: 0x202,
  103.             0xb8000001: 0x808200,
  104.             0xc8000001: 0x800200,
  105.             0xd8000001: 0x0,
  106.             0xe8000001: 0x8200,
  107.             0xf8000001: 0x808002
  108.         },
  109.         {
  110.             0x0: 0x40084010,
  111.             0x1000000: 0x4000,
  112.             0x2000000: 0x80000,
  113.             0x3000000: 0x40080010,
  114.             0x4000000: 0x40000010,
  115.             0x5000000: 0x40084000,
  116.             0x6000000: 0x40004000,
  117.             0x7000000: 0x10,
  118.             0x8000000: 0x84000,
  119.             0x9000000: 0x40004010,
  120.             0xa000000: 0x40000000,
  121.             0xb000000: 0x84010,
  122.             0xc000000: 0x80010,
  123.             0xd000000: 0x0,
  124.             0xe000000: 0x4010,
  125.             0xf000000: 0x40080000,
  126.             0x800000: 0x40004000,
  127.             0x1800000: 0x84010,
  128.             0x2800000: 0x10,
  129.             0x3800000: 0x40004010,
  130.             0x4800000: 0x40084010,
  131.             0x5800000: 0x40000000,
  132.             0x6800000: 0x80000,
  133.             0x7800000: 0x40080010,
  134.             0x8800000: 0x80010,
  135.             0x9800000: 0x0,
  136.             0xa800000: 0x4000,
  137.             0xb800000: 0x40080000,
  138.             0xc800000: 0x40000010,
  139.             0xd800000: 0x84000,
  140.             0xe800000: 0x40084000,
  141.             0xf800000: 0x4010,
  142.             0x10000000: 0x0,
  143.             0x11000000: 0x40080010,
  144.             0x12000000: 0x40004010,
  145.             0x13000000: 0x40084000,
  146.             0x14000000: 0x40080000,
  147.             0x15000000: 0x10,
  148.             0x16000000: 0x84010,
  149.             0x17000000: 0x4000,
  150.             0x18000000: 0x4010,
  151.             0x19000000: 0x80000,
  152.             0x1a000000: 0x80010,
  153.             0x1b000000: 0x40000010,
  154.             0x1c000000: 0x84000,
  155.             0x1d000000: 0x40004000,
  156.             0x1e000000: 0x40000000,
  157.             0x1f000000: 0x40084010,
  158.             0x10800000: 0x84010,
  159.             0x11800000: 0x80000,
  160.             0x12800000: 0x40080000,
  161.             0x13800000: 0x4000,
  162.             0x14800000: 0x40004000,
  163.             0x15800000: 0x40084010,
  164.             0x16800000: 0x10,
  165.             0x17800000: 0x40000000,
  166.             0x18800000: 0x40084000,
  167.             0x19800000: 0x40000010,
  168.             0x1a800000: 0x40004010,
  169.             0x1b800000: 0x80010,
  170.             0x1c800000: 0x0,
  171.             0x1d800000: 0x4010,
  172.             0x1e800000: 0x40080010,
  173.             0x1f800000: 0x84000
  174.         },
  175.         {
  176.             0x0: 0x104,
  177.             0x100000: 0x0,
  178.             0x200000: 0x4000100,
  179.             0x300000: 0x10104,
  180.             0x400000: 0x10004,
  181.             0x500000: 0x4000004,
  182.             0x600000: 0x4010104,
  183.             0x700000: 0x4010000,
  184.             0x800000: 0x4000000,
  185.             0x900000: 0x4010100,
  186.             0xa00000: 0x10100,
  187.             0xb00000: 0x4010004,
  188.             0xc00000: 0x4000104,
  189.             0xd00000: 0x10000,
  190.             0xe00000: 0x4,
  191.             0xf00000: 0x100,
  192.             0x80000: 0x4010100,
  193.             0x180000: 0x4010004,
  194.             0x280000: 0x0,
  195.             0x380000: 0x4000100,
  196.             0x480000: 0x4000004,
  197.             0x580000: 0x10000,
  198.             0x680000: 0x10004,
  199.             0x780000: 0x104,
  200.             0x880000: 0x4,
  201.             0x980000: 0x100,
  202.             0xa80000: 0x4010000,
  203.             0xb80000: 0x10104,
  204.             0xc80000: 0x10100,
  205.             0xd80000: 0x4000104,
  206.             0xe80000: 0x4010104,
  207.             0xf80000: 0x4000000,
  208.             0x1000000: 0x4010100,
  209.             0x1100000: 0x10004,
  210.             0x1200000: 0x10000,
  211.             0x1300000: 0x4000100,
  212.             0x1400000: 0x100,
  213.             0x1500000: 0x4010104,
  214.             0x1600000: 0x4000004,
  215.             0x1700000: 0x0,
  216.             0x1800000: 0x4000104,
  217.             0x1900000: 0x4000000,
  218.             0x1a00000: 0x4,
  219.             0x1b00000: 0x10100,
  220.             0x1c00000: 0x4010000,
  221.             0x1d00000: 0x104,
  222.             0x1e00000: 0x10104,
  223.             0x1f00000: 0x4010004,
  224.             0x1080000: 0x4000000,
  225.             0x1180000: 0x104,
  226.             0x1280000: 0x4010100,
  227.             0x1380000: 0x0,
  228.             0x1480000: 0x10004,
  229.             0x1580000: 0x4000100,
  230.             0x1680000: 0x100,
  231.             0x1780000: 0x4010004,
  232.             0x1880000: 0x10000,
  233.             0x1980000: 0x4010104,
  234.             0x1a80000: 0x10104,
  235.             0x1b80000: 0x4000004,
  236.             0x1c80000: 0x4000104,
  237.             0x1d80000: 0x4010000,
  238.             0x1e80000: 0x4,
  239.             0x1f80000: 0x10100
  240.         },
  241.         {
  242.             0x0: 0x80401000,
  243.             0x10000: 0x80001040,
  244.             0x20000: 0x401040,
  245.             0x30000: 0x80400000,
  246.             0x40000: 0x0,
  247.             0x50000: 0x401000,
  248.             0x60000: 0x80000040,
  249.             0x70000: 0x400040,
  250.             0x80000: 0x80000000,
  251.             0x90000: 0x400000,
  252.             0xa0000: 0x40,
  253.             0xb0000: 0x80001000,
  254.             0xc0000: 0x80400040,
  255.             0xd0000: 0x1040,
  256.             0xe0000: 0x1000,
  257.             0xf0000: 0x80401040,
  258.             0x8000: 0x80001040,
  259.             0x18000: 0x40,
  260.             0x28000: 0x80400040,
  261.             0x38000: 0x80001000,
  262.             0x48000: 0x401000,
  263.             0x58000: 0x80401040,
  264.             0x68000: 0x0,
  265.             0x78000: 0x80400000,
  266.             0x88000: 0x1000,
  267.             0x98000: 0x80401000,
  268.             0xa8000: 0x400000,
  269.             0xb8000: 0x1040,
  270.             0xc8000: 0x80000000,
  271.             0xd8000: 0x400040,
  272.             0xe8000: 0x401040,
  273.             0xf8000: 0x80000040,
  274.             0x100000: 0x400040,
  275.             0x110000: 0x401000,
  276.             0x120000: 0x80000040,
  277.             0x130000: 0x0,
  278.             0x140000: 0x1040,
  279.             0x150000: 0x80400040,
  280.             0x160000: 0x80401000,
  281.             0x170000: 0x80001040,
  282.             0x180000: 0x80401040,
  283.             0x190000: 0x80000000,
  284.             0x1a0000: 0x80400000,
  285.             0x1b0000: 0x401040,
  286.             0x1c0000: 0x80001000,
  287.             0x1d0000: 0x400000,
  288.             0x1e0000: 0x40,
  289.             0x1f0000: 0x1000,
  290.             0x108000: 0x80400000,
  291.             0x118000: 0x80401040,
  292.             0x128000: 0x0,
  293.             0x138000: 0x401000,
  294.             0x148000: 0x400040,
  295.             0x158000: 0x80000000,
  296.             0x168000: 0x80001040,
  297.             0x178000: 0x40,
  298.             0x188000: 0x80000040,
  299.             0x198000: 0x1000,
  300.             0x1a8000: 0x80001000,
  301.             0x1b8000: 0x80400040,
  302.             0x1c8000: 0x1040,
  303.             0x1d8000: 0x80401000,
  304.             0x1e8000: 0x400000,
  305.             0x1f8000: 0x401040
  306.         },
  307.         {
  308.             0x0: 0x80,
  309.             0x1000: 0x1040000,
  310.             0x2000: 0x40000,
  311.             0x3000: 0x20000000,
  312.             0x4000: 0x20040080,
  313.             0x5000: 0x1000080,
  314.             0x6000: 0x21000080,
  315.             0x7000: 0x40080,
  316.             0x8000: 0x1000000,
  317.             0x9000: 0x20040000,
  318.             0xa000: 0x20000080,
  319.             0xb000: 0x21040080,
  320.             0xc000: 0x21040000,
  321.             0xd000: 0x0,
  322.             0xe000: 0x1040080,
  323.             0xf000: 0x21000000,
  324.             0x800: 0x1040080,
  325.             0x1800: 0x21000080,
  326.             0x2800: 0x80,
  327.             0x3800: 0x1040000,
  328.             0x4800: 0x40000,
  329.             0x5800: 0x20040080,
  330.             0x6800: 0x21040000,
  331.             0x7800: 0x20000000,
  332.             0x8800: 0x20040000,
  333.             0x9800: 0x0,
  334.             0xa800: 0x21040080,
  335.             0xb800: 0x1000080,
  336.             0xc800: 0x20000080,
  337.             0xd800: 0x21000000,
  338.             0xe800: 0x1000000,
  339.             0xf800: 0x40080,
  340.             0x10000: 0x40000,
  341.             0x11000: 0x80,
  342.             0x12000: 0x20000000,
  343.             0x13000: 0x21000080,
  344.             0x14000: 0x1000080,
  345.             0x15000: 0x21040000,
  346.             0x16000: 0x20040080,
  347.             0x17000: 0x1000000,
  348.             0x18000: 0x21040080,
  349.             0x19000: 0x21000000,
  350.             0x1a000: 0x1040000,
  351.             0x1b000: 0x20040000,
  352.             0x1c000: 0x40080,
  353.             0x1d000: 0x20000080,
  354.             0x1e000: 0x0,
  355.             0x1f000: 0x1040080,
  356.             0x10800: 0x21000080,
  357.             0x11800: 0x1000000,
  358.             0x12800: 0x1040000,
  359.             0x13800: 0x20040080,
  360.             0x14800: 0x20000000,
  361.             0x15800: 0x1040080,
  362.             0x16800: 0x80,
  363.             0x17800: 0x21040000,
  364.             0x18800: 0x40080,
  365.             0x19800: 0x21040080,
  366.             0x1a800: 0x0,
  367.             0x1b800: 0x21000000,
  368.             0x1c800: 0x1000080,
  369.             0x1d800: 0x40000,
  370.             0x1e800: 0x20040000,
  371.             0x1f800: 0x20000080
  372.         },
  373.         {
  374.             0x0: 0x10000008,
  375.             0x100: 0x2000,
  376.             0x200: 0x10200000,
  377.             0x300: 0x10202008,
  378.             0x400: 0x10002000,
  379.             0x500: 0x200000,
  380.             0x600: 0x200008,
  381.             0x700: 0x10000000,
  382.             0x800: 0x0,
  383.             0x900: 0x10002008,
  384.             0xa00: 0x202000,
  385.             0xb00: 0x8,
  386.             0xc00: 0x10200008,
  387.             0xd00: 0x202008,
  388.             0xe00: 0x2008,
  389.             0xf00: 0x10202000,
  390.             0x80: 0x10200000,
  391.             0x180: 0x10202008,
  392.             0x280: 0x8,
  393.             0x380: 0x200000,
  394.             0x480: 0x202008,
  395.             0x580: 0x10000008,
  396.             0x680: 0x10002000,
  397.             0x780: 0x2008,
  398.             0x880: 0x200008,
  399.             0x980: 0x2000,
  400.             0xa80: 0x10002008,
  401.             0xb80: 0x10200008,
  402.             0xc80: 0x0,
  403.             0xd80: 0x10202000,
  404.             0xe80: 0x202000,
  405.             0xf80: 0x10000000,
  406.             0x1000: 0x10002000,
  407.             0x1100: 0x10200008,
  408.             0x1200: 0x10202008,
  409.             0x1300: 0x2008,
  410.             0x1400: 0x200000,
  411.             0x1500: 0x10000000,
  412.             0x1600: 0x10000008,
  413.             0x1700: 0x202000,
  414.             0x1800: 0x202008,
  415.             0x1900: 0x0,
  416.             0x1a00: 0x8,
  417.             0x1b00: 0x10200000,
  418.             0x1c00: 0x2000,
  419.             0x1d00: 0x10002008,
  420.             0x1e00: 0x10202000,
  421.             0x1f00: 0x200008,
  422.             0x1080: 0x8,
  423.             0x1180: 0x202000,
  424.             0x1280: 0x200000,
  425.             0x1380: 0x10000008,
  426.             0x1480: 0x10002000,
  427.             0x1580: 0x2008,
  428.             0x1680: 0x10202008,
  429.             0x1780: 0x10200000,
  430.             0x1880: 0x10202000,
  431.             0x1980: 0x10200008,
  432.             0x1a80: 0x2000,
  433.             0x1b80: 0x202008,
  434.             0x1c80: 0x200008,
  435.             0x1d80: 0x0,
  436.             0x1e80: 0x10000000,
  437.             0x1f80: 0x10002008
  438.         },
  439.         {
  440.             0x0: 0x100000,
  441.             0x10: 0x2000401,
  442.             0x20: 0x400,
  443.             0x30: 0x100401,
  444.             0x40: 0x2100401,
  445.             0x50: 0x0,
  446.             0x60: 0x1,
  447.             0x70: 0x2100001,
  448.             0x80: 0x2000400,
  449.             0x90: 0x100001,
  450.             0xa0: 0x2000001,
  451.             0xb0: 0x2100400,
  452.             0xc0: 0x2100000,
  453.             0xd0: 0x401,
  454.             0xe0: 0x100400,
  455.             0xf0: 0x2000000,
  456.             0x8: 0x2100001,
  457.             0x18: 0x0,
  458.             0x28: 0x2000401,
  459.             0x38: 0x2100400,
  460.             0x48: 0x100000,
  461.             0x58: 0x2000001,
  462.             0x68: 0x2000000,
  463.             0x78: 0x401,
  464.             0x88: 0x100401,
  465.             0x98: 0x2000400,
  466.             0xa8: 0x2100000,
  467.             0xb8: 0x100001,
  468.             0xc8: 0x400,
  469.             0xd8: 0x2100401,
  470.             0xe8: 0x1,
  471.             0xf8: 0x100400,
  472.             0x100: 0x2000000,
  473.             0x110: 0x100000,
  474.             0x120: 0x2000401,
  475.             0x130: 0x2100001,
  476.             0x140: 0x100001,
  477.             0x150: 0x2000400,
  478.             0x160: 0x2100400,
  479.             0x170: 0x100401,
  480.             0x180: 0x401,
  481.             0x190: 0x2100401,
  482.             0x1a0: 0x100400,
  483.             0x1b0: 0x1,
  484.             0x1c0: 0x0,
  485.             0x1d0: 0x2100000,
  486.             0x1e0: 0x2000001,
  487.             0x1f0: 0x400,
  488.             0x108: 0x100400,
  489.             0x118: 0x2000401,
  490.             0x128: 0x2100001,
  491.             0x138: 0x1,
  492.             0x148: 0x2000000,
  493.             0x158: 0x100000,
  494.             0x168: 0x401,
  495.             0x178: 0x2100400,
  496.             0x188: 0x2000001,
  497.             0x198: 0x2100000,
  498.             0x1a8: 0x0,
  499.             0x1b8: 0x2100401,
  500.             0x1c8: 0x100401,
  501.             0x1d8: 0x400,
  502.             0x1e8: 0x2000400,
  503.             0x1f8: 0x100001
  504.         },
  505.         {
  506.             0x0: 0x8000820,
  507.             0x1: 0x20000,
  508.             0x2: 0x8000000,
  509.             0x3: 0x20,
  510.             0x4: 0x20020,
  511.             0x5: 0x8020820,
  512.             0x6: 0x8020800,
  513.             0x7: 0x800,
  514.             0x8: 0x8020000,
  515.             0x9: 0x8000800,
  516.             0xa: 0x20800,
  517.             0xb: 0x8020020,
  518.             0xc: 0x820,
  519.             0xd: 0x0,
  520.             0xe: 0x8000020,
  521.             0xf: 0x20820,
  522.             0x80000000: 0x800,
  523.             0x80000001: 0x8020820,
  524.             0x80000002: 0x8000820,
  525.             0x80000003: 0x8000000,
  526.             0x80000004: 0x8020000,
  527.             0x80000005: 0x20800,
  528.             0x80000006: 0x20820,
  529.             0x80000007: 0x20,
  530.             0x80000008: 0x8000020,
  531.             0x80000009: 0x820,
  532.             0x8000000a: 0x20020,
  533.             0x8000000b: 0x8020800,
  534.             0x8000000c: 0x0,
  535.             0x8000000d: 0x8020020,
  536.             0x8000000e: 0x8000800,
  537.             0x8000000f: 0x20000,
  538.             0x10: 0x20820,
  539.             0x11: 0x8020800,
  540.             0x12: 0x20,
  541.             0x13: 0x800,
  542.             0x14: 0x8000800,
  543.             0x15: 0x8000020,
  544.             0x16: 0x8020020,
  545.             0x17: 0x20000,
  546.             0x18: 0x0,
  547.             0x19: 0x20020,
  548.             0x1a: 0x8020000,
  549.             0x1b: 0x8000820,
  550.             0x1c: 0x8020820,
  551.             0x1d: 0x20800,
  552.             0x1e: 0x820,
  553.             0x1f: 0x8000000,
  554.             0x80000010: 0x20000,
  555.             0x80000011: 0x800,
  556.             0x80000012: 0x8020020,
  557.             0x80000013: 0x20820,
  558.             0x80000014: 0x20,
  559.             0x80000015: 0x8020000,
  560.             0x80000016: 0x8000000,
  561.             0x80000017: 0x8000820,
  562.             0x80000018: 0x8020820,
  563.             0x80000019: 0x8000020,
  564.             0x8000001a: 0x8000800,
  565.             0x8000001b: 0x0,
  566.             0x8000001c: 0x20800,
  567.             0x8000001d: 0x820,
  568.             0x8000001e: 0x20020,
  569.             0x8000001f: 0x8020800
  570.         }
  571.     ];
  572.  
  573.     // Masks that select the SBOX input
  574.     var SBOX_MASK = [
  575.         0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  576.         0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  577.     ];
  578.  
  579.     /**
  580.      * DES block cipher algorithm.
  581.      */
  582.     var DES = C_algo.DES = BlockCipher.extend({
  583.         _doReset: function () {
  584.             // Shortcuts
  585.             var key = this._key;
  586.             var keyWords = key.words;
  587.  
  588.             // Select 56 bits according to PC1
  589.             var keyBits = [];
  590.             for (var i = 0; i < 56; i++) {
  591.                 var keyBitPos = PC1[i] - 1;
  592.                 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  593.             }
  594.  
  595.             // Assemble 16 subkeys
  596.             var subKeys = this._subKeys = [];
  597.             for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  598.                 // Create subkey
  599.                 var subKey = subKeys[nSubKey] = [];
  600.  
  601.                 // Shortcut
  602.                 var bitShift = BIT_SHIFTS[nSubKey];
  603.  
  604.                 // Select 48 bits according to PC2
  605.                 for (var i = 0; i < 24; i++) {
  606.                     // Select from the left 28 key bits
  607.                     subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  608.  
  609.                     // Select from the right 28 key bits
  610.                     subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  611.                 }
  612.  
  613.                 // Since each subkey is applied to an expanded 32-bit input,
  614.                 // the subkey can be broken into 8 values scaled to 32-bits,
  615.                 // which allows the key to be used without expansion
  616.                 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  617.                 for (var i = 1; i < 7; i++) {
  618.                     subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  619.                 }
  620.                 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  621.             }
  622.  
  623.             // Compute inverse subkeys
  624.             var invSubKeys = this._invSubKeys = [];
  625.             for (var i = 0; i < 16; i++) {
  626.                 invSubKeys[i] = subKeys[15 - i];
  627.             }
  628.         },
  629.  
  630.         encryptBlock: function (M, offset) {
  631.             this._doCryptBlock(M, offset, this._subKeys);
  632.         },
  633.  
  634.         decryptBlock: function (M, offset) {
  635.             this._doCryptBlock(M, offset, this._invSubKeys);
  636.         },
  637.  
  638.         _doCryptBlock: function (M, offset, subKeys) {
  639.             // Get input
  640.             this._lBlock = M[offset];
  641.             this._rBlock = M[offset + 1];
  642.  
  643.             // Initial permutation
  644.             exchangeLR.call(this, 4,  0x0f0f0f0f);
  645.             exchangeLR.call(this, 16, 0x0000ffff);
  646.             exchangeRL.call(this, 2,  0x33333333);
  647.             exchangeRL.call(this, 8,  0x00ff00ff);
  648.             exchangeLR.call(this, 1,  0x55555555);
  649.  
  650.             // Rounds
  651.             for (var round = 0; round < 16; round++) {
  652.                 // Shortcuts
  653.                 var subKey = subKeys[round];
  654.                 var lBlock = this._lBlock;
  655.                 var rBlock = this._rBlock;
  656.  
  657.                 // Feistel function
  658.                 var f = 0;
  659.                 for (var i = 0; i < 8; i++) {
  660.                     f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  661.                 }
  662.                 this._lBlock = rBlock;
  663.                 this._rBlock = lBlock ^ f;
  664.             }
  665.  
  666.             // Undo swap from last round
  667.             var t = this._lBlock;
  668.             this._lBlock = this._rBlock;
  669.             this._rBlock = t;
  670.  
  671.             // Final permutation
  672.             exchangeLR.call(this, 1,  0x55555555);
  673.             exchangeRL.call(this, 8,  0x00ff00ff);
  674.             exchangeRL.call(this, 2,  0x33333333);
  675.             exchangeLR.call(this, 16, 0x0000ffff);
  676.             exchangeLR.call(this, 4,  0x0f0f0f0f);
  677.  
  678.             // Set output
  679.             M[offset] = this._lBlock;
  680.             M[offset + 1] = this._rBlock;
  681.         },
  682.  
  683.         keySize: 64/32,
  684.  
  685.         ivSize: 64/32,
  686.  
  687.         blockSize: 64/32
  688.     });
  689.  
  690.     // Swap bits across the left and right words
  691.     function exchangeLR(offset, mask) {
  692.         var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  693.         this._rBlock ^= t;
  694.         this._lBlock ^= t << offset;
  695.     }
  696.  
  697.     function exchangeRL(offset, mask) {
  698.         var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  699.         this._lBlock ^= t;
  700.         this._rBlock ^= t << offset;
  701.     }
  702.  
  703.     /**
  704.      * Shortcut functions to the cipher's object interface.
  705.      *
  706.      * @example
  707.      *
  708.      *     var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  709.      *     var plaintext  = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  710.      */
  711.     C.DES = BlockCipher._createHelper(DES);
  712.  
  713.     /**
  714.      * Triple-DES block cipher algorithm.
  715.      */
  716.     var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  717.         _doReset: function () {
  718.             // Shortcuts
  719.             var key = this._key;
  720.             var keyWords = key.words;
  721.  
  722.             // Create DES instances
  723.             this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
  724.             this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
  725.             this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
  726.         },
  727.  
  728.         encryptBlock: function (M, offset) {
  729.             this._des1.encryptBlock(M, offset);
  730.             this._des2.decryptBlock(M, offset);
  731.             this._des3.encryptBlock(M, offset);
  732.         },
  733.  
  734.         decryptBlock: function (M, offset) {
  735.             this._des3.decryptBlock(M, offset);
  736.             this._des2.encryptBlock(M, offset);
  737.             this._des1.decryptBlock(M, offset);
  738.         },
  739.  
  740.         keySize: 192/32,
  741.  
  742.         ivSize: 64/32,
  743.  
  744.         blockSize: 64/32
  745.     });
  746.  
  747.     /**
  748.      * Shortcut functions to the cipher's object interface.
  749.      *
  750.      * @example
  751.      *
  752.      *     var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  753.      *     var plaintext  = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  754.      */
  755.     C.TripleDES = BlockCipher._createHelper(TripleDES);
  756. }());
  757.