novnc-rails 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +0 -0
  3. data/LICENSE.txt +0 -0
  4. data/README.md +0 -0
  5. data/lib/novnc-rails.rb +8 -0
  6. data/lib/novnc-rails/version.rb +5 -0
  7. data/vendor/assets/javascripts/noVNC/Orbitron700.ttf +0 -0
  8. data/vendor/assets/javascripts/noVNC/Orbitron700.woff +0 -0
  9. data/vendor/assets/javascripts/noVNC/base.css +512 -0
  10. data/vendor/assets/javascripts/noVNC/base64.js +113 -0
  11. data/vendor/assets/javascripts/noVNC/black.css +71 -0
  12. data/vendor/assets/javascripts/noVNC/blue.css +64 -0
  13. data/vendor/assets/javascripts/noVNC/des.js +276 -0
  14. data/vendor/assets/javascripts/noVNC/display.js +751 -0
  15. data/vendor/assets/javascripts/noVNC/input.js +388 -0
  16. data/vendor/assets/javascripts/noVNC/jsunzip.js +676 -0
  17. data/vendor/assets/javascripts/noVNC/keyboard.js +543 -0
  18. data/vendor/assets/javascripts/noVNC/keysym.js +378 -0
  19. data/vendor/assets/javascripts/noVNC/keysymdef.js +15 -0
  20. data/vendor/assets/javascripts/noVNC/logo.js +1 -0
  21. data/vendor/assets/javascripts/noVNC/playback.js +102 -0
  22. data/vendor/assets/javascripts/noVNC/rfb.js +1889 -0
  23. data/vendor/assets/javascripts/noVNC/ui.js +979 -0
  24. data/vendor/assets/javascripts/noVNC/util.js +656 -0
  25. data/vendor/assets/javascripts/noVNC/web-socket-js/README.txt +109 -0
  26. data/vendor/assets/javascripts/noVNC/web-socket-js/WebSocketMain.swf +0 -0
  27. data/vendor/assets/javascripts/noVNC/web-socket-js/swfobject.js +4 -0
  28. data/vendor/assets/javascripts/noVNC/web-socket-js/web_socket.js +391 -0
  29. data/vendor/assets/javascripts/noVNC/websock.js +388 -0
  30. data/vendor/assets/javascripts/noVNC/webutil.js +239 -0
  31. metadata +86 -0
@@ -0,0 +1,113 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ // From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
6
+
7
+ /*jslint white: false */
8
+ /*global console */
9
+
10
+ var Base64 = {
11
+ /* Convert data (an array of integers) to a Base64 string. */
12
+ toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
13
+ base64Pad : '=',
14
+
15
+ encode: function (data) {
16
+ "use strict";
17
+ var result = '';
18
+ var toBase64Table = Base64.toBase64Table;
19
+ var length = data.length;
20
+ var lengthpad = (length % 3);
21
+ // Convert every three bytes to 4 ascii characters.
22
+
23
+ for (var i = 0; i < (length - 2); i += 3) {
24
+ result += toBase64Table[data[i] >> 2];
25
+ result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
26
+ result += toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
27
+ result += toBase64Table[data[i + 2] & 0x3f];
28
+ }
29
+
30
+ // Convert the remaining 1 or 2 bytes, pad out to 4 characters.
31
+ var j = 0;
32
+ if (lengthpad === 2) {
33
+ j = length - lengthpad;
34
+ result += toBase64Table[data[j] >> 2];
35
+ result += toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
36
+ result += toBase64Table[(data[j + 1] & 0x0f) << 2];
37
+ result += toBase64Table[64];
38
+ } else if (lengthpad === 1) {
39
+ j = length - lengthpad;
40
+ result += toBase64Table[data[j] >> 2];
41
+ result += toBase64Table[(data[j] & 0x03) << 4];
42
+ result += toBase64Table[64];
43
+ result += toBase64Table[64];
44
+ }
45
+
46
+ return result;
47
+ },
48
+
49
+ /* Convert Base64 data to a string */
50
+ /* jshint -W013 */
51
+ toBinaryTable : [
52
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
53
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
54
+ -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
55
+ 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
56
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
57
+ 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
58
+ -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
59
+ 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
60
+ ],
61
+ /* jshint +W013 */
62
+
63
+ decode: function (data, offset) {
64
+ "use strict";
65
+ offset = typeof(offset) !== 'undefined' ? offset : 0;
66
+ var toBinaryTable = Base64.toBinaryTable;
67
+ var base64Pad = Base64.base64Pad;
68
+ var result, result_length;
69
+ var leftbits = 0; // number of bits decoded, but yet to be appended
70
+ var leftdata = 0; // bits decoded, but yet to be appended
71
+ var data_length = data.indexOf('=') - offset;
72
+
73
+ if (data_length < 0) { data_length = data.length - offset; }
74
+
75
+ /* Every four characters is 3 resulting numbers */
76
+ result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5);
77
+ result = new Array(result_length);
78
+
79
+ // Convert one by one.
80
+ for (var idx = 0, i = offset; i < data.length; i++) {
81
+ var c = toBinaryTable[data.charCodeAt(i) & 0x7f];
82
+ var padding = (data.charAt(i) === base64Pad);
83
+ // Skip illegal characters and whitespace
84
+ if (c === -1) {
85
+ console.error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
86
+ continue;
87
+ }
88
+
89
+ // Collect data into leftdata, update bitcount
90
+ leftdata = (leftdata << 6) | c;
91
+ leftbits += 6;
92
+
93
+ // If we have 8 or more bits, append 8 bits to the result
94
+ if (leftbits >= 8) {
95
+ leftbits -= 8;
96
+ // Append if not padding.
97
+ if (!padding) {
98
+ result[idx++] = (leftdata >> leftbits) & 0xff;
99
+ }
100
+ leftdata &= (1 << leftbits) - 1;
101
+ }
102
+ }
103
+
104
+ // If there are any bits left, the base64 string was corrupted
105
+ if (leftbits) {
106
+ err = new Error('Corrupted base64 string');
107
+ err.name = 'Base64-Error';
108
+ throw err;
109
+ }
110
+
111
+ return result;
112
+ }
113
+ }; /* End of Base64 namespace */
@@ -0,0 +1,71 @@
1
+ /*
2
+ * noVNC black CSS
3
+ * Copyright (C) 2012 Joel Martin
4
+ * Copyright (C) 2013 Samuel Mannehed for Cendio AB
5
+ * noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
6
+ * This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
7
+ */
8
+
9
+ #keyboardinput {
10
+ background-color:#000;
11
+ }
12
+
13
+ .noVNC_status_normal {
14
+ background: #4c4c4c; /* Old browsers */
15
+ background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
16
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
17
+ background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
18
+ background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
19
+ background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
20
+ background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
21
+ }
22
+ .noVNC_status_error {
23
+ background: #f04040; /* Old browsers */
24
+ background: -moz-linear-gradient(top, #f04040 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
25
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f04040), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
26
+ background: -webkit-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
27
+ background: -o-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
28
+ background: -ms-linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
29
+ background: linear-gradient(top, #f04040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
30
+ }
31
+ .noVNC_status_warn {
32
+ background: #f0f040; /* Old browsers */
33
+ background: -moz-linear-gradient(top, #f0f040 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
34
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f0f040), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
35
+ background: -webkit-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
36
+ background: -o-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
37
+ background: -ms-linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
38
+ background: linear-gradient(top, #f0f040 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
39
+ }
40
+
41
+ .triangle-right {
42
+ border:2px solid #fff;
43
+ background:#000;
44
+ color:#fff;
45
+ }
46
+
47
+ .noVNC_status_button {
48
+ font-size: 12px;
49
+ vertical-align: middle;
50
+ border:1px solid #4c4c4c;
51
+
52
+ background: #4c4c4c; /* Old browsers */
53
+ background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
54
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
55
+ background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
56
+ background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
57
+ background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
58
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 ); /* IE6-9 */
59
+ background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
60
+ }
61
+
62
+ .noVNC_status_button_selected {
63
+ background: #9dd53a; /* Old browsers */
64
+ background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
65
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */
66
+ background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
67
+ background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera11.10+ */
68
+ background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */
69
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */
70
+ background: linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */
71
+ }
@@ -0,0 +1,64 @@
1
+ /*
2
+ * noVNC blue CSS
3
+ * Copyright (C) 2012 Joel Martin
4
+ * Copyright (C) 2013 Samuel Mannehed for Cendio AB
5
+ * noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
6
+ * This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
7
+ */
8
+
9
+ .noVNC_status_normal {
10
+ background-color:#04073d;
11
+ background-image: -webkit-gradient(
12
+ linear,
13
+ left bottom,
14
+ left top,
15
+ color-stop(0.54, rgb(10,15,79)),
16
+ color-stop(0.5, rgb(4,7,61))
17
+ );
18
+ background-image: -moz-linear-gradient(
19
+ center bottom,
20
+ rgb(10,15,79) 54%,
21
+ rgb(4,7,61) 50%
22
+ );
23
+ }
24
+ .noVNC_status_error {
25
+ background-color:#f04040;
26
+ background-image: -webkit-gradient(
27
+ linear,
28
+ left bottom,
29
+ left top,
30
+ color-stop(0.54, rgb(240,64,64)),
31
+ color-stop(0.5, rgb(4,7,61))
32
+ );
33
+ background-image: -moz-linear-gradient(
34
+ center bottom,
35
+ rgb(4,7,61) 54%,
36
+ rgb(249,64,64) 50%
37
+ );
38
+ }
39
+ .noVNC_status_warn {
40
+ background-color:#f0f040;
41
+ background-image: -webkit-gradient(
42
+ linear,
43
+ left bottom,
44
+ left top,
45
+ color-stop(0.54, rgb(240,240,64)),
46
+ color-stop(0.5, rgb(4,7,61))
47
+ );
48
+ background-image: -moz-linear-gradient(
49
+ center bottom,
50
+ rgb(4,7,61) 54%,
51
+ rgb(240,240,64) 50%
52
+ );
53
+ }
54
+
55
+ .triangle-right {
56
+ border:2px solid #fff;
57
+ background:#04073d;
58
+ color:#fff;
59
+ }
60
+
61
+ #keyboardinput {
62
+ background-color:#04073d;
63
+ }
64
+
@@ -0,0 +1,276 @@
1
+ /*
2
+ * Ported from Flashlight VNC ActionScript implementation:
3
+ * http://www.wizhelp.com/flashlight-vnc/
4
+ *
5
+ * Full attribution follows:
6
+ *
7
+ * -------------------------------------------------------------------------
8
+ *
9
+ * This DES class has been extracted from package Acme.Crypto for use in VNC.
10
+ * The unnecessary odd parity code has been removed.
11
+ *
12
+ * These changes are:
13
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
14
+ *
15
+ * This software is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
+ *
19
+
20
+ * DesCipher - the DES encryption method
21
+ *
22
+ * The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
23
+ *
24
+ * Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
25
+ *
26
+ * Permission to use, copy, modify, and distribute this software
27
+ * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
28
+ * without fee is hereby granted, provided that this copyright notice is kept
29
+ * intact.
30
+ *
31
+ * WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
32
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
33
+ * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34
+ * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
35
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
36
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
37
+ *
38
+ * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
39
+ * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
40
+ * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
41
+ * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
42
+ * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
43
+ * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
44
+ * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
45
+ * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
46
+ * HIGH RISK ACTIVITIES.
47
+ *
48
+ *
49
+ * The rest is:
50
+ *
51
+ * Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
52
+ *
53
+ * Redistribution and use in source and binary forms, with or without
54
+ * modification, are permitted provided that the following conditions
55
+ * are met:
56
+ * 1. Redistributions of source code must retain the above copyright
57
+ * notice, this list of conditions and the following disclaimer.
58
+ * 2. Redistributions in binary form must reproduce the above copyright
59
+ * notice, this list of conditions and the following disclaimer in the
60
+ * documentation and/or other materials provided with the distribution.
61
+ *
62
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
63
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
66
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72
+ * SUCH DAMAGE.
73
+ *
74
+ * Visit the ACME Labs Java page for up-to-date versions of this and other
75
+ * fine Java utilities: http://www.acme.com/java/
76
+ */
77
+
78
+ /* jslint white: false */
79
+
80
+ function DES(passwd) {
81
+ "use strict";
82
+
83
+ // Tables, permutations, S-boxes, etc.
84
+ // jshint -W013
85
+ var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
86
+ 25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
87
+ 50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
88
+ totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
89
+ z = 0x0, a,b,c,d,e,f, SP1,SP2,SP3,SP4,SP5,SP6,SP7,SP8,
90
+ keys = [];
91
+
92
+ // jshint -W015
93
+ a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
94
+ SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
95
+ z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
96
+ a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
97
+ c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
98
+ a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
99
+ SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
100
+ a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
101
+ z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
102
+ z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|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+ var i, j, l, m, n, o, pc1m = [], pcr = [], kn = [],
138
+ raw0, raw1, rawi, KnLi;
139
+
140
+ for (j = 0, l = 56; j < 56; ++j, l -= 8) {
141
+ l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
142
+ m = l & 0x7;
143
+ pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
144
+ }
145
+
146
+ for (i = 0; i < 16; ++i) {
147
+ m = i << 1;
148
+ n = m + 1;
149
+ kn[m] = kn[n] = 0;
150
+ for (o = 28; o < 59; o += 28) {
151
+ for (j = o - 28; j < o; ++j) {
152
+ l = j + totrot[i];
153
+ if (l < o) {
154
+ pcr[j] = pc1m[l];
155
+ } else {
156
+ pcr[j] = pc1m[l - 28];
157
+ }
158
+ }
159
+ }
160
+ for (j = 0; j < 24; ++j) {
161
+ if (pcr[PC2[j]] !== 0) {
162
+ kn[m] |= 1 << (23 - j);
163
+ }
164
+ if (pcr[PC2[j + 24]] !== 0) {
165
+ kn[n] |= 1 << (23 - j);
166
+ }
167
+ }
168
+ }
169
+
170
+ // cookey
171
+ for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
172
+ raw0 = kn[rawi++];
173
+ raw1 = kn[rawi++];
174
+ keys[KnLi] = (raw0 & 0x00fc0000) << 6;
175
+ keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
176
+ keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
177
+ keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
178
+ ++KnLi;
179
+ keys[KnLi] = (raw0 & 0x0003f000) << 12;
180
+ keys[KnLi] |= (raw0 & 0x0000003f) << 16;
181
+ keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
182
+ keys[KnLi] |= (raw1 & 0x0000003f);
183
+ ++KnLi;
184
+ }
185
+ }
186
+
187
+ // Encrypt 8 bytes of text
188
+ function enc8(text) {
189
+ var i = 0, b = text.slice(), fval, keysi = 0,
190
+ l, r, x; // left, right, accumulator
191
+
192
+ // Squash 8 bytes to 2 ints
193
+ l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
194
+ r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
195
+
196
+ x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
197
+ r ^= x;
198
+ l ^= (x << 4);
199
+ x = ((l >>> 16) ^ r) & 0x0000ffff;
200
+ r ^= x;
201
+ l ^= (x << 16);
202
+ x = ((r >>> 2) ^ l) & 0x33333333;
203
+ l ^= x;
204
+ r ^= (x << 2);
205
+ x = ((r >>> 8) ^ l) & 0x00ff00ff;
206
+ l ^= x;
207
+ r ^= (x << 8);
208
+ r = (r << 1) | ((r >>> 31) & 1);
209
+ x = (l ^ r) & 0xaaaaaaaa;
210
+ l ^= x;
211
+ r ^= x;
212
+ l = (l << 1) | ((l >>> 31) & 1);
213
+
214
+ for (i = 0; i < 8; ++i) {
215
+ x = (r << 28) | (r >>> 4);
216
+ x ^= keys[keysi++];
217
+ fval = SP7[x & 0x3f];
218
+ fval |= SP5[(x >>> 8) & 0x3f];
219
+ fval |= SP3[(x >>> 16) & 0x3f];
220
+ fval |= SP1[(x >>> 24) & 0x3f];
221
+ x = r ^ keys[keysi++];
222
+ fval |= SP8[x & 0x3f];
223
+ fval |= SP6[(x >>> 8) & 0x3f];
224
+ fval |= SP4[(x >>> 16) & 0x3f];
225
+ fval |= SP2[(x >>> 24) & 0x3f];
226
+ l ^= fval;
227
+ x = (l << 28) | (l >>> 4);
228
+ x ^= keys[keysi++];
229
+ fval = SP7[x & 0x3f];
230
+ fval |= SP5[(x >>> 8) & 0x3f];
231
+ fval |= SP3[(x >>> 16) & 0x3f];
232
+ fval |= SP1[(x >>> 24) & 0x3f];
233
+ x = l ^ keys[keysi++];
234
+ fval |= SP8[x & 0x0000003f];
235
+ fval |= SP6[(x >>> 8) & 0x3f];
236
+ fval |= SP4[(x >>> 16) & 0x3f];
237
+ fval |= SP2[(x >>> 24) & 0x3f];
238
+ r ^= fval;
239
+ }
240
+
241
+ r = (r << 31) | (r >>> 1);
242
+ x = (l ^ r) & 0xaaaaaaaa;
243
+ l ^= x;
244
+ r ^= x;
245
+ l = (l << 31) | (l >>> 1);
246
+ x = ((l >>> 8) ^ r) & 0x00ff00ff;
247
+ r ^= x;
248
+ l ^= (x << 8);
249
+ x = ((l >>> 2) ^ r) & 0x33333333;
250
+ r ^= x;
251
+ l ^= (x << 2);
252
+ x = ((r >>> 16) ^ l) & 0x0000ffff;
253
+ l ^= x;
254
+ r ^= (x << 16);
255
+ x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
256
+ l ^= x;
257
+ r ^= (x << 4);
258
+
259
+ // Spread ints to bytes
260
+ x = [r, l];
261
+ for (i = 0; i < 8; i++) {
262
+ b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
263
+ if (b[i] < 0) { b[i] += 256; } // unsigned
264
+ }
265
+ return b;
266
+ }
267
+
268
+ // Encrypt 16 bytes of text using passwd as key
269
+ function encrypt(t) {
270
+ return enc8(t.slice(0, 8)).concat(enc8(t.slice(8, 16)));
271
+ }
272
+
273
+ setKeys(passwd); // Setup keys
274
+ return {'encrypt': encrypt}; // Public interface
275
+
276
+ } // function DES