78 lines
7.6 KiB
JavaScript
78 lines
7.6 KiB
JavaScript
|
/*
|
||
|
* Ported from Flashlight VNC ActionScript implementation:
|
||
|
* http://www.wizhelp.com/flashlight-vnc/
|
||
|
*
|
||
|
* Full attribution follows:
|
||
|
*
|
||
|
* -------------------------------------------------------------------------
|
||
|
*
|
||
|
* This DES class has been extracted from package Acme.Crypto for use in VNC.
|
||
|
* The unnecessary odd parity code has been removed.
|
||
|
*
|
||
|
* These changes are:
|
||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||
|
*
|
||
|
* This software is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
*
|
||
|
|
||
|
* DesCipher - the DES encryption method
|
||
|
*
|
||
|
* The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
||
|
*
|
||
|
* Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||
|
*
|
||
|
* Permission to use, copy, modify, and distribute this software
|
||
|
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
||
|
* without fee is hereby granted, provided that this copyright notice is kept
|
||
|
* intact.
|
||
|
*
|
||
|
* WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
||
|
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||
|
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||
|
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
||
|
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||
|
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||
|
*
|
||
|
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||
|
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||
|
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||
|
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||
|
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||
|
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||
|
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
||
|
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
||
|
* HIGH RISK ACTIVITIES.
|
||
|
*
|
||
|
*
|
||
|
* The rest is:
|
||
|
*
|
||
|
* Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without
|
||
|
* modification, are permitted provided that the following conditions
|
||
|
* are met:
|
||
|
* 1. Redistributions of source code must retain the above copyright
|
||
|
* notice, this list of conditions and the following disclaimer.
|
||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||
|
* notice, this list of conditions and the following disclaimer in the
|
||
|
* documentation and/or other materials provided with the distribution.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
|
* SUCH DAMAGE.
|
||
|
*
|
||
|
* Visit the ACME Labs Java page for up-to-date versions of this and other
|
||
|
* fine Java utilities: http://www.acme.com/java/
|
||
|
*/
|
||
|
|
||
|
function DES(r){"use strict";function n(r){var n,o,f,c,t=0,e=r.slice(),i=0;for(o=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++],f=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++],c=252645135&(o>>>4^f),f^=c,o^=c<<4,c=65535&(o>>>16^f),f^=c,o^=c<<16,c=858993459&(f>>>2^o),o^=c,f^=c<<2,c=16711935&(f>>>8^o),o^=c,f^=c<<8,f=f<<1|f>>>31&1,c=2863311530&(o^f),o^=c,f^=c,o=o<<1|o>>>31&1,t=0;t<8;++t)c=f<<28|f>>>4,c^=d[i++],n=D[63&c],n|=p[c>>>8&63],n|=l[c>>>16&63],n|=s[c>>>24&63],c=f^d[i++],n|=E[63&c],n|=y[c>>>8&63],n|=v[c>>>16&63],n|=a[c>>>24&63],o^=n,c=o<<28|o>>>4,c^=d[i++],n=D[63&c],n|=p[c>>>8&63],n|=l[c>>>16&63],n|=s[c>>>24&63],c=o^d[i++],n|=E[63&c],n|=y[c>>>8&63],n|=v[c>>>16&63],n|=a[c>>>24&63],f^=n;for(f=f<<31|f>>>1,c=2863311530&(o^f),o^=c,f^=c,o=o<<31|o>>>1,c=16711935&(o>>>8^f),f^=c,o^=c<<8,c=858993459&(o>>>2^f),f^=c,o^=c<<2,c=65535&(f>>>16^o),o^=c,f^=c<<16,c=252645135&(f>>>4^o),o^=c,f^=c<<4,c=[f,o],t=0;t<8;t++)e[t]=(c[t>>>2]>>>8*(3-t%4))%256,e[t]<0&&(e[t]+=256);return e}function o(r){return n(r.slice(0,8)).concat(n(r.slice(8,16)))}var f,c,t,e,i,u,s,a,l,v,p,y,D,E,S=[13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31],b=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],d=[];return f=65536,c=1<<24,t=f|c,e=4,i=1024,u=e|i,s=[t|i,0,0|f,t|u,t|e,f|u,0|e,0|f,0|i,t|i,t|u,0|i,c|u,t|e,0|c,0|e,0|u,c|i,c|i,f|i,f|i,0|t,0|t,c|u,f|e,c|e,c|e,f|e,0,0|u,f|u,0|c,0|f,t|u,0|e,0|t,t|i,0|c,0|c,0|i,t|e,0|f,f|i,c|e,0|i,0|e,c|u,f|u,t|u,f|e,0|t,c|u,c|e,0|u,f|u,t|i,0|u,c|i,c|i,0,f|e,f|i,0,t|e],f=1<<20,c=1<<31,t=f|c,e=32,i=32768,u=e|i,a=[t|u,c|i,0|i,f|u,0|f,0|e,t|e,c|u,c|e,t|u,t|i,0|c,c|i,0|f,0|e,t|e,f|i,f|e,c|u,0,0|c,0|i,f|u,0|t,f|e,c|e,0,f|i,0|u,t|i,0|t,0|u,0,f|u,t|e,0|f,c|u,0|t,t|i,0|i,0|t,c|i,0|e,t|u,f|u,0|e,0|i,0|c,0|u,t|i,0|f,c|e,f|e,c|u,c|e,f|e,f|i,0,c|i,0|u,0|c,t|e,t|u,f|i],f=1<<17,c=1<<27,t=f|c,e=8,i=512,u=e|i,l=[0|u,t|i,0,t|e,c|i,0,f|u,c|i,f|e,c|e,c|e,0|f,t|u,f|e,0|t,0|u,0|c,0|e,t|i,0|i,f|i,0|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