diff --git a/resources/openpgp.js b/resources/openpgp.js index 5515c8db..289f8442 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -3174,22 +3174,21 @@ function openpgp_packet_compressed() { this.decompressedData = packet.data; break; case 2: // - ZLIB [RFC1950] - // TODO: This is pretty hacky. Not fully utilizing ZLIB (ADLER-32). No real JS implementations out there for this? - var compressionMethod = this.compressedData.charCodeAt(0)%0x10; //RFC 1950. Bits 0-3 Compression Method - //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size. - //2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary (how is this defined). Basic checksum, and compression level. - if(compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951 - var inflater = new zip.Inflater(); - var output = inflater.append(util.str2Uint8Array(this.compressedData.substring(2,this.compressedData.length-4))); - var outputString = util.Uint8Array2str(output); - //TODO check ADLER32 checksum - var packet = openpgp_packet.read_packet(outputString,0,outputString.length); - util.print_info('Decompressed packet [Type 2-ZLIB]: ' + packet); - this.decompressedData = packet.data; - } - else{ - util.print_error("Compression algorithm ZLIB is not fully implemented."); - } + var compressionMethod = this.compressedData.charCodeAt(0) % 0x10; //RFC 1950. Bits 0-3 Compression Method + //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size. + //2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary (how is this defined). Basic checksum, and compression level. + if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951 + // remove 4 bytes ADLER32 checksum from the end + var compData = this.compressedData.substring(0, this.compressedData.length - 4); + var radix = s2r(compData).replace(/\n/g,""); + var outputString = JXG.decompress(radix); + //TODO check ADLER32 checksum + var packet = openpgp_packet.read_packet(outputString, 0, outputString.length); + util.print_info('Decompressed packet [Type 2-ZLIB]: ' + packet); + this.decompressedData = packet.data; + } else { + util.print_error("Compression algorithm ZLIB only supports DEFLATE compression method."); + } break; case 3: // - BZip2 [BZ2] // TODO: need to implement this @@ -4691,6 +4690,1218 @@ var Util = function() { * an instance that should be used. */ var util = new Util(); +JXG = {exists: (function(undefined){return function(v){return !(v===undefined || v===null);}})()}; +JXG.decompress = function(str) {return unescape((new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(str))).unzip()[0][0]);}; +/* + Copyright 2008-2012 + Matthias Ehmann, + Michael Gerhaeuser, + Carsten Miller, + Bianca Valentin, + Alfred Wassermann, + Peter Wilfahrt + + This file is part of JSXGraph. + + Dual licensed under the Apache License Version 2.0, or LGPL Version 3 licenses. + + You should have received a copy of the GNU Lesser General Public License + along with JSXCompressor. If not, see . + + You should have received a copy of the Apache License along with JSXCompressor. + If not, see . + +*/ + +/** + * @fileoverview Utilities for uncompressing and base64 decoding + */ + +/** + * @class Util class + * Class for gunzipping, unzipping and base64 decoding of files. + * It is used for reading GEONExT, Geogebra and Intergeo files. + * + * Only Huffman codes are decoded in gunzip. + * The code is based on the source code for gunzip.c by Pasi Ojala + * @see http://www.cs.tut.fi/~albert/Dev/gunzip/gunzip.c + * @see http://www.cs.tut.fi/~albert + */ +JXG.Util = {}; + +/** + * Unzip zip files + */ +JXG.Util.Unzip = function (barray){ + var outputArr = [], + output = "", + debug = false, + gpflags, + files = 0, + unzipped = [], + crc, + buf32k = new Array(32768), + bIdx = 0, + modeZIP=false, + + CRC, SIZE, + + bitReverse = [ + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff + ], + + cplens = [ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 + ], + + cplext = [ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 + ], /* 99==invalid */ + + cpdist = [ + 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, + 0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, + 0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, + 0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001 + ], + + cpdext = [ + 0, 0, 0, 0, 1, 1, 2, 2, + 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13 + ], + + border = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], + + bA = barray, + + bytepos=0, + bitpos=0, + bb = 1, + bits=0, + + NAMEMAX = 256, + + nameBuf = [], + + fileout; + + function readByte(){ + bits+=8; + if (bytepos"); + return bA[bytepos++]; + } else + return -1; + }; + + function byteAlign(){ + bb = 1; + }; + + function readBit(){ + var carry; + bits++; + carry = (bb & 1); + bb >>= 1; + if (bb==0){ + bb = readByte(); + carry = (bb & 1); + bb = (bb>>1) | 0x80; + } + return carry; + }; + + function readBits(a) { + var res = 0, + i = a; + + while(i--) { + res = (res<<1) | readBit(); + } + if(a) { + res = bitReverse[res]>>(8-a); + } + return res; + }; + + function flushBuffer(){ + //document.write('FLUSHBUFFER:'+buf32k); + bIdx = 0; + }; + function addBuffer(a){ + SIZE++; + //CRC=updcrc(a,crc); + buf32k[bIdx++] = a; + outputArr.push(String.fromCharCode(a)); + //output+=String.fromCharCode(a); + if(bIdx==0x8000){ + //document.write('ADDBUFFER:'+buf32k); + bIdx=0; + } + }; + + function HufNode() { + this.b0=0; + this.b1=0; + this.jump = null; + this.jumppos = -1; + }; + + var LITERALS = 288; + + var literalTree = new Array(LITERALS); + var distanceTree = new Array(32); + var treepos=0; + var Places = null; + var Places2 = null; + + var impDistanceTree = new Array(64); + var impLengthTree = new Array(64); + + var len = 0; + var fpos = new Array(17); + fpos[0]=0; + var flens; + var fmax; + + function IsPat() { + while (1) { + if (fpos[len] >= fmax) + return -1; + if (flens[fpos[len]] == len) + return fpos[len]++; + fpos[len]++; + } + }; + + function Rec() { + var curplace = Places[treepos]; + var tmp; + if (debug) + document.write("
len:"+len+" treepos:"+treepos); + if(len==17) { //war 17 + return -1; + } + treepos++; + len++; + + tmp = IsPat(); + if (debug) + document.write("
IsPat "+tmp); + if(tmp >= 0) { + curplace.b0 = tmp; /* leaf cell for 0-bit */ + if (debug) + document.write("
b0 "+curplace.b0); + } else { + /* Not a Leaf cell */ + curplace.b0 = 0x8000; + if (debug) + document.write("
b0 "+curplace.b0); + if(Rec()) + return -1; + } + tmp = IsPat(); + if(tmp >= 0) { + curplace.b1 = tmp; /* leaf cell for 1-bit */ + if (debug) + document.write("
b1 "+curplace.b1); + curplace.jump = null; /* Just for the display routine */ + } else { + /* Not a Leaf cell */ + curplace.b1 = 0x8000; + if (debug) + document.write("
b1 "+curplace.b1); + curplace.jump = Places[treepos]; + curplace.jumppos = treepos; + if(Rec()) + return -1; + } + len--; + return 0; + }; + + function CreateTree(currentTree, numval, lengths, show) { + var i; + /* Create the Huffman decode tree/table */ + //document.write("
createtree
"); + if (debug) + document.write("currentTree "+currentTree+" numval "+numval+" lengths "+lengths+" show "+show); + Places = currentTree; + treepos=0; + flens = lengths; + fmax = numval; + for (i=0;i<17;i++) + fpos[i] = 0; + len = 0; + if(Rec()) { + //fprintf(stderr, "invalid huffman tree\n"); + if (debug) + alert("invalid huffman tree\n"); + return -1; + } + if (debug){ + document.write('
Tree: '+Places.length); + for (var a=0;a<32;a++){ + document.write("Places["+a+"].b0="+Places[a].b0+"
"); + document.write("Places["+a+"].b1="+Places[a].b1+"
"); + } + } + + /*if(show) { + var tmp; + for(tmp=currentTree;tmpjump?tmp->jump-currentTree:0,(tmp->jump?tmp->jump-currentTree:0)*6+0xcf0); + if(!(tmp.b0 & 0x8000)) { + //fprintf(stdout, " 0x%03x (%c)", tmp->b0,(tmp->b0<256 && isprint(tmp->b0))?tmp->b0:'�'); + } + if(!(tmp.b1 & 0x8000)) { + if((tmp.b0 & 0x8000)) + fprintf(stdout, " "); + fprintf(stdout, " 0x%03x (%c)", tmp->b1,(tmp->b1<256 && isprint(tmp->b1))?tmp->b1:'�'); + } + fprintf(stdout, "\n"); + } + }*/ + return 0; + }; + + function DecodeValue(currentTree) { + var len, i, + xtreepos=0, + X = currentTree[xtreepos], + b; + + /* decode one symbol of the data */ + while(1) { + b=readBit(); + if (debug) + document.write("b="+b); + if(b) { + if(!(X.b1 & 0x8000)){ + if (debug) + document.write("ret1"); + return X.b1; /* If leaf node, return data */ + } + X = X.jump; + len = currentTree.length; + for (i=0;i>1); + if(j > 23) { + j = (j<<1) | readBit(); /* 48..255 */ + + if(j > 199) { /* 200..255 */ + j -= 128; /* 72..127 */ + j = (j<<1) | readBit(); /* 144..255 << */ + } else { /* 48..199 */ + j -= 48; /* 0..151 */ + if(j > 143) { + j = j+136; /* 280..287 << */ + /* 0..143 << */ + } + } + } else { /* 0..23 */ + j += 256; /* 256..279 << */ + } + if(j < 256) { + addBuffer(j); + //document.write("out:"+String.fromCharCode(j)); + /*fprintf(errfp, "@%d %02x\n", SIZE, j);*/ + } else if(j == 256) { + /* EOF */ + break; + } else { + var len, dist; + + j -= 256 + 1; /* bytes + EOF */ + len = readBits(cplext[j]) + cplens[j]; + + j = bitReverse[readBits(5)]>>3; + if(cpdext[j] > 8) { + dist = readBits(8); + dist |= (readBits(cpdext[j]-8)<<8); + } else { + dist = readBits(cpdext[j]); + } + dist += cpdist[j]; + + /*fprintf(errfp, "@%d (l%02x,d%04x)\n", SIZE, len, dist);*/ + for(j=0;jparam: "+literalCodes+" "+distCodes+" "+lenCodes+"
"); + for(j=0; j<19; j++) { + ll[j] = 0; + } + + // Get the decode tree code lengths + + //document.write("
"); + for(j=0; jll:'+ll); + len = distanceTree.length; + for (i=0; idistanceTree"); + for(var a=0;a"+distanceTree[a].b0+" "+distanceTree[a].b1+" "+distanceTree[a].jump+" "+distanceTree[a].jumppos); + /*if (distanceTree[a].jumppos!=-1) + document.write(" "+distanceTree[a].jump.b0+" "+distanceTree[a].jump.b1); + */ + } + } + //document.write('
tree created'); + + //read in literal and distance code lengths + n = literalCodes + distCodes; + i = 0; + var z=-1; + if (debug) + document.write("
n="+n+" bits: "+bits+"
"); + while(i < n) { + z++; + j = DecodeValue(distanceTree); + if (debug) + document.write("
"+z+" i:"+i+" decode: "+j+" bits "+bits+"
"); + if(j<16) { // length of code in bits (0..15) + ll[i++] = j; + } else if(j==16) { // repeat last length 3 to 6 times + var l; + j = 3 + readBits(2); + if(i+j > n) { + flushBuffer(); + return 1; + } + l = i ? ll[i-1] : 0; + while(j--) { + ll[i++] = l; + } + } else { + if(j==17) { // 3 to 10 zero length codes + j = 3 + readBits(3); + } else { // j == 18: 11 to 138 zero length codes + j = 11 + readBits(7); + } + if(i+j > n) { + flushBuffer(); + return 1; + } + while(j--) { + ll[i++] = 0; + } + } + } + /*for(j=0; jliteralTree"); + while(1) { + j = DecodeValue(literalTree); + if(j >= 256) { // In C64: if carry set + var len, dist; + j -= 256; + if(j == 0) { + // EOF + break; + } + j--; + len = readBits(cplext[j]) + cplens[j]; + + j = DecodeValue(distanceTree); + if(cpdext[j] > 8) { + dist = readBits(8); + dist |= (readBits(cpdext[j]-8)<<8); + } else { + dist = readBits(cpdext[j]); + } + dist += cpdist[j]; + while(len--) { + var c = buf32k[(bIdx - dist) & 0x7fff]; + addBuffer(c); + } + } else { + addBuffer(j); + } + } + } + } while(!last); + flushBuffer(); + + byteAlign(); + return 0; +}; + +JXG.Util.Unzip.prototype.unzipFile = function(name) { + var i; + this.unzip(); + //alert(unzipped[0][1]); + for (i=0;i"); + } + */ + //alert(bA); + nextFile(); + return unzipped; + }; + + function nextFile(){ + if (debug) + alert("NEXTFILE"); + outputArr = []; + var tmp = []; + modeZIP = false; + tmp[0] = readByte(); + tmp[1] = readByte(); + if (debug) + alert("type: "+tmp[0]+" "+tmp[1]); + if (tmp[0] == parseInt("78",16) && tmp[1] == parseInt("da",16)){ //GZIP + if (debug) + alert("GEONExT-GZIP"); + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "geonext.gxt"; + files++; + } + if (tmp[0] == parseInt("78",16) && tmp[1] == parseInt("9c",16)){ //ZLIB + if (debug) + alert("ZLIB"); + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "ZLIB"; + files++; + } + if (tmp[0] == parseInt("1f",16) && tmp[1] == parseInt("8b",16)){ //GZIP + if (debug) + alert("GZIP"); + //DeflateLoop(); + skipdir(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "file"; + files++; + } + if (tmp[0] == parseInt("50",16) && tmp[1] == parseInt("4b",16)){ //ZIP + modeZIP = true; + tmp[2] = readByte(); + tmp[3] = readByte(); + if (tmp[2] == parseInt("3",16) && tmp[3] == parseInt("4",16)){ + //MODE_ZIP + tmp[0] = readByte(); + tmp[1] = readByte(); + if (debug) + alert("ZIP-Version: "+tmp[1]+" "+tmp[0]/10+"."+tmp[0]%10); + + gpflags = readByte(); + gpflags |= (readByte()<<8); + if (debug) + alert("gpflags: "+gpflags); + + var method = readByte(); + method |= (readByte()<<8); + if (debug) + alert("method: "+method); + + readByte(); + readByte(); + readByte(); + readByte(); + + var crc = readByte(); + crc |= (readByte()<<8); + crc |= (readByte()<<16); + crc |= (readByte()<<24); + + var compSize = readByte(); + compSize |= (readByte()<<8); + compSize |= (readByte()<<16); + compSize |= (readByte()<<24); + + var size = readByte(); + size |= (readByte()<<8); + size |= (readByte()<<16); + size |= (readByte()<<24); + + if (debug) + alert("local CRC: "+crc+"\nlocal Size: "+size+"\nlocal CompSize: "+compSize); + + var filelen = readByte(); + filelen |= (readByte()<<8); + + var extralen = readByte(); + extralen |= (readByte()<<8); + + if (debug) + alert("filelen "+filelen); + i = 0; + nameBuf = []; + while (filelen--){ + var c = readByte(); + if (c == "/" | c ==":"){ + i = 0; + } else if (i < NAMEMAX-1) + nameBuf[i++] = String.fromCharCode(c); + } + if (debug) + alert("nameBuf: "+nameBuf); + + //nameBuf[i] = "\0"; + if (!fileout) + fileout = nameBuf; + + var i = 0; + while (i < extralen){ + c = readByte(); + i++; + } + + CRC = 0xffffffff; + SIZE = 0; + + if (size = 0 && fileOut.charAt(fileout.length-1)=="/"){ + //skipdir + if (debug) + alert("skipdir"); + } + if (method == 8){ + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = nameBuf.join(''); + files++; + //return outputArr.join(''); + } + skipdir(); + } + } + }; + +function skipdir(){ + var crc, + tmp = [], + compSize, size, os, i, c; + + if ((gpflags & 8)) { + tmp[0] = readByte(); + tmp[1] = readByte(); + tmp[2] = readByte(); + tmp[3] = readByte(); + + if (tmp[0] == parseInt("50",16) && + tmp[1] == parseInt("4b",16) && + tmp[2] == parseInt("07",16) && + tmp[3] == parseInt("08",16)) + { + crc = readByte(); + crc |= (readByte()<<8); + crc |= (readByte()<<16); + crc |= (readByte()<<24); + } else { + crc = tmp[0] | (tmp[1]<<8) | (tmp[2]<<16) | (tmp[3]<<24); + } + + compSize = readByte(); + compSize |= (readByte()<<8); + compSize |= (readByte()<<16); + compSize |= (readByte()<<24); + + size = readByte(); + size |= (readByte()<<8); + size |= (readByte()<<16); + size |= (readByte()<<24); + + if (debug) + alert("CRC:"); + } + + if (modeZIP) + nextFile(); + + tmp[0] = readByte(); + if (tmp[0] != 8) { + if (debug) + alert("Unknown compression method!"); + return 0; + } + + gpflags = readByte(); + if (debug){ + if ((gpflags & ~(parseInt("1f",16)))) + alert("Unknown flags set!"); + } + + readByte(); + readByte(); + readByte(); + readByte(); + + readByte(); + os = readByte(); + + if ((gpflags & 4)){ + tmp[0] = readByte(); + tmp[2] = readByte(); + len = tmp[0] + 256*tmp[1]; + if (debug) + alert("Extra field size: "+len); + for (i=0;ihttp://www.webtoolkit.info/ +*/ +JXG.Util.Base64 = { + + // private property + _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", + + // public method for encoding + encode : function (input) { + var output = [], + chr1, chr2, chr3, enc1, enc2, enc3, enc4, + i = 0; + + input = JXG.Util.Base64._utf8_encode(input); + + while (i < input.length) { + + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output.push([this._keyStr.charAt(enc1), + this._keyStr.charAt(enc2), + this._keyStr.charAt(enc3), + this._keyStr.charAt(enc4)].join('')); + } + + return output.join(''); + }, + + // public method for decoding + decode : function (input, utf8) { + var output = [], + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + + enc1 = this._keyStr.indexOf(input.charAt(i++)); + enc2 = this._keyStr.indexOf(input.charAt(i++)); + enc3 = this._keyStr.indexOf(input.charAt(i++)); + enc4 = this._keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output.push(String.fromCharCode(chr1)); + + if (enc3 != 64) { + output.push(String.fromCharCode(chr2)); + } + if (enc4 != 64) { + output.push(String.fromCharCode(chr3)); + } + } + + output = output.join(''); + + if (utf8) { + output = JXG.Util.Base64._utf8_decode(output); + } + return output; + + }, + + // private method for UTF-8 encoding + _utf8_encode : function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }, + + // private method for UTF-8 decoding + _utf8_decode : function (utftext) { + var string = [], + i = 0, + c = 0, c2 = 0, c3 = 0; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + if (c < 128) { + string.push(String.fromCharCode(c)); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string.push(String.fromCharCode(((c & 31) << 6) | (c2 & 63))); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))); + i += 3; + } + } + return string.join(''); + }, + + _destrip: function (stripped, wrap){ + var lines = [], lineno, i, + destripped = []; + + if (wrap==null) + wrap = 76; + + stripped.replace(/ /g, ""); + lineno = stripped.length / wrap; + for (i = 0; i < lineno; i++) + lines[i]=stripped.substr(i * wrap, wrap); + if (lineno != stripped.length / wrap) + lines[lines.length]=stripped.substr(lineno * wrap, stripped.length-(lineno * wrap)); + + for (i = 0; i < lines.length; i++) + destripped.push(lines[i]); + return destripped.join('\n'); + }, + + decodeAsArray: function (input){ + var dec = this.decode(input), + ar = [], i; + for (i=0;i255){ + switch (c) { + case 8364: c=128; + break; + case 8218: c=130; + break; + case 402: c=131; + break; + case 8222: c=132; + break; + case 8230: c=133; + break; + case 8224: c=134; + break; + case 8225: c=135; + break; + case 710: c=136; + break; + case 8240: c=137; + break; + case 352: c=138; + break; + case 8249: c=139; + break; + case 338: c=140; + break; + case 381: c=142; + break; + case 8216: c=145; + break; + case 8217: c=146; + break; + case 8220: c=147; + break; + case 8221: c=148; + break; + case 8226: c=149; + break; + case 8211: c=150; + break; + case 8212: c=151; + break; + case 732: c=152; + break; + case 8482: c=153; + break; + case 353: c=154; + break; + case 8250: c=155; + break; + case 339: c=156; + break; + case 382: c=158; + break; + case 376: c=159; + break; + default: + break; + } + } + return c; +}; + +/** + * Decoding string into utf-8 + * @param {String} string to decode + * @return {String} utf8 decoded string + */ +JXG.Util.utf8Decode = function(utftext) { + var string = []; + var i = 0; + var c = 0, c1 = 0, c2 = 0, c3; + if (!JXG.exists(utftext)) return ''; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + + if (c < 128) { + string.push(String.fromCharCode(c)); + i++; + } else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string.push(String.fromCharCode(((c & 31) << 6) | (c2 & 63))); + i += 2; + } else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))); + i += 3; + } + }; + return string.join(''); +}; + +/** + * Generate a random uuid. + * http://www.broofa.com + * mailto:robert@broofa.com + * + * Copyright (c) 2010 Robert Kieffer + * Dual licensed under the MIT and GPL licenses. + * + * EXAMPLES: + * >>> Math.uuid() + * "92329D39-6F5C-4520-ABFC-AAB64544E172" + */ +JXG.Util.genUUID = function() { + // Private array of chars to use + var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''), + uuid = new Array(36), rnd=0, r; + + for (var i = 0; i < 36; i++) { + if (i==8 || i==13 || i==18 || i==23) { + uuid[i] = '-'; + } else if (i==14) { + uuid[i] = '4'; + } else { + if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0; + r = rnd & 0xf; + rnd = rnd >> 4; + uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; + } + } + + return uuid.join(''); +}; + /* Copyright (c) 2012 Gildas Lormeau. All rights reserved. diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index ee92cdda..79c47c4d 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -25,33 +25,33 @@ function openpgp_packet_encrypteddata(){this.tagType=9;this.decryptedData=this.e this.algorithmType+"\n encrypted data: Bytes ["+util.hexstrdump(this.encryptedData)+"]\n"};this.read_packet=function(a,b,c){this.packetLength=c;this.encryptedData=a.substring(b,b+c);return this};this.write_packet=function(a,b,c){a=""+openpgp_crypto_symmetricEncrypt(openpgp_crypto_getPrefixRandom(a),a,b,c,!0);return a=openpgp_packet.write_packet_header(9,a.length)+a}} function openpgp_packet_signature(){function a(b,a){var d;d=""+openpgp_packet.encode_length(a.length+1);d+=String.fromCharCode(b);return d+a}this.tagType=2;this.embeddedSignature=this.signatureTargetHash=this.signatureTargetHashAlgorithm=this.signatureTargetPublicKeyAlgorithm=this.reasonForRevocationString=this.reasonForRevocationFlag=this.signersUserId=this.keyFlags=this.policyURI=this.isPrimaryUserID=this.preferredKeyServer=this.keyServerPreferences=this.preferredCompressionAlgorithms=this.preferredHashAlgorithms= this.notationValue=this.notationName=this.notationFlags=this.issuerKeyId=this.revocationKeyFingerprint=this.revocationKeyAlgorithm=this.revocationKeyClass=this.preferredSymmetricAlgorithms=this.keyNeverExpires=this.keyExpirationTime=this.revocable=this.regular_expression=this.trustAmount=this.trustLevel=this.exportable=this.hashAlgorithm=this.publicKeyAlgorithm=this.MPIs=this.signedHashValue=this.signatureNeverExpires=this.signatureExpirationTime=this.signatureData=this.keyId=this.creationTime=this.signatureType= -null;this._raw_read_signature_sub_packet=function(a,c,d){0>d&&util.print_debug("openpgp.packet.signature.js\n_raw_read_signature_sub_packet length < 0 @:"+c);var e=c,f=0;192>a[e].charCodeAt()?f=a[e++].charCodeAt():192<=a[e].charCodeAt()&&224>a[e].charCodeAt()?f=(a[e++].charCodeAt()-192<<8)+a[e++].charCodeAt()+192:223a[e].charCodeAt()?f=1<<(a[e++].charCodeAt()&31):255>a[e].charCodeAt()&&(e++,f=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()); -var g=a[e++].charCodeAt()&127;switch(g){case 2:this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()));break;case 3:this.signatureExpirationTime=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt();this.signatureNeverExpires=0==this.signature_expiration_time;break;case 4:this.exportable=1==a[e++].charCodeAt();break;case 5:this.trustLevel=a[e++].charCodeAt();this.trustAmount=a[e++].charCodeAt(); -break;case 6:this.regular_expression=new String;for(g=0;gg;g++)this.revocationKeyFingerprint=a[e++].charCodeAt();break;case 16:this.issuerKeyId=a.substring(e,e+8);e+=8;break;case 20:this.notationFlags=a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=a[e++].charCodeAt()<<8|a[e++].charCodeAt();f=a[e++].charCodeAt()<<8|a[e++].charCodeAt();this.notationName="";for(g=0;gd&&util.print_debug("openpgp.packet.signature.js\n_raw_read_signature_sub_packet length < 0 @:"+a);var e=a,f=0;192>b[e].charCodeAt()?f=b[e++].charCodeAt():192<=b[e].charCodeAt()&&224>b[e].charCodeAt()?f=(b[e++].charCodeAt()-192<<8)+b[e++].charCodeAt()+192:223b[e].charCodeAt()?f=1<<(b[e++].charCodeAt()&31):255>b[e].charCodeAt()&&(e++,f=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt()); +var g=b[e++].charCodeAt()&127;switch(g){case 2:this.creationTime=new Date(1E3*(b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt()));break;case 3:this.signatureExpirationTime=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt();this.signatureNeverExpires=0==this.signature_expiration_time;break;case 4:this.exportable=1==b[e++].charCodeAt();break;case 5:this.trustLevel=b[e++].charCodeAt();this.trustAmount=b[e++].charCodeAt(); +break;case 6:this.regular_expression=new String;for(g=0;gg;g++)this.revocationKeyFingerprint=b[e++].charCodeAt();break;case 16:this.issuerKeyId=b.substring(e,e+8);e+=8;break;case 20:this.notationFlags=b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt();d=b[e++].charCodeAt()<<8|b[e++].charCodeAt();f=b[e++].charCodeAt()<<8|b[e++].charCodeAt();this.notationName="";for(g=0;g>24&255)+String.fromCharCode(b>>16&255)+String.fromCharCode(b>>8&255)+String.fromCharCode(b&255)),h=a(16,d.getKeyId()),g=g+String.fromCharCode(b.length+h.length>>8&255),g=g+String.fromCharCode(b.length+h.length&255),g=g+b+h,b=""+String.fromCharCode(4),b=b+String.fromCharCode(255),b=b+String.fromCharCode(g.length>>24),b=b+String.fromCharCode(g.length>>16&255),b=b+String.fromCharCode(g.length>>8&255),b=b+String.fromCharCode(g.length&255),h=String.fromCharCode(0), -h=h+String.fromCharCode(0),k=openpgp_crypto_hashData(f,c+g+b);util.print_debug("DSA Signature is calculated with:|"+c+g+b+"|\n"+util.hexstrdump(c+g+b)+"\n hash:"+util.hexstrdump(k));h+=k.charAt(0);h+=k.charAt(1);h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+b);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,c){switch(this.signatureType){case 0:if(4== -this.version){var d;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a.substring(i)+this.signatureData+d)}if(3==this.version)return!1;case 1:if(4== -this.version)return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a+this.signatureData+d);if(3==this.version)return!1;case 2:if(3==this.version)return!1; -d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,this.signatureData+d);case 16:case 17:case 18:case 19:case 48:return d=""+String.fromCharCode(this.version), -d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 24:if(3==this.version)return!1;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>> -24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 25:case 31:case 32:case 40:return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>> -16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}};this.read_packet=function(a,c,d){this.data=a.substring(c,c+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+ -c),null;var e=c;this.packetLength=d;this.version=a[e++].charCodeAt();switch(this.version){case 3:5!=a[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=a[e++].charCodeAt();this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()));this.signatureData=a.substring(c,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm= -a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f=0;fthis.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;f>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.obj.publicKeyPacket.MPIs,b.substring(i)+this.signatureData+d)}if(3==this.version)return!1;case 1:if(4== +this.version)return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.obj.publicKeyPacket.MPIs,b+this.signatureData+d);if(3==this.version)return!1;case 2:if(3==this.version)return!1; +d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.obj.publicKeyPacket.MPIs,this.signatureData+d);case 16:case 17:case 18:case 19:case 48:return d=""+String.fromCharCode(this.version), +d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.MPIs,b+this.signatureData+d);case 24:if(3==this.version)return!1;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>> +24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.MPIs,b+this.signatureData+d);case 25:case 31:case 32:case 40:return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>> +16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,a.MPIs,b+this.signatureData+d);default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}};this.read_packet=function(b,a,d){this.data=b.substring(a,a+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+ +a),null;var e=a;this.packetLength=d;this.version=b[e++].charCodeAt();switch(this.version){case 3:5!=b[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=b[e++].charCodeAt();this.creationTime=new Date(1E3*(b[e++].charCodeAt()<<24|b[e++].charCodeAt()<<16|b[e++].charCodeAt()<<8|b[e++].charCodeAt()));this.signatureData=b.substring(a,e);this.keyId=b.substring(e,e+8);e+=8;this.publicKeyAlgorithm= +b[e++].charCodeAt();this.hashAlgorithm=b[e++].charCodeAt();this.signedHashValue=b[e++].charCodeAt()<<8|b[e++].charCodeAt();d=0;0this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f=0;fthis.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;fthis.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a, d,c-2-(d-b)),d+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(a,d,c-2-(d-b)),d+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(a,d,c-2-(d-b)),d+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(a,d,c-2-(d-b)),d+=this.secMPIs[3].packetLength;else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a,d,c-2-(d-b)),d+=this.secMPIs[0].packetLength; else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(a,d,c-2-(d-b)),d+=this.secMPIs[0].packetLength;this.checksum=[];this.checksum[0]=a[d++].charCodeAt();this.checksum[1]=a[d++].charCodeAt()}else this.encryptedMPIData=a.substring(d,c);return this};this.decryptSecretMPIs=function(a){if(this.hasUnencryptedSecretKeyData)return this.secMPIs;var b=this.s2k.produce_key(a),c="";switch(this.symmetricEncryptionAlgorithm){case 1:return util.print_error("openpgp.packet.keymaterial.js\nsymmetric encryption algorithim: IDEA is not implemented"), -!1;case 2:c=normal_cfb_decrypt(function(a,b){return des(b,a,1,null,0)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 3:c=normal_cfb_decrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(b.substring(0,16)),this.encryptedMPIData,this.IV);break;case 4:c=normal_cfb_decrypt(function(a,b){return(new Blowfish(b)).encrypt(a)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 7:case 8:case 9:c=16;8==this.symmetricEncryptionAlgorithm&& -(c=24,b=this.s2k.produce_key(a,c));9==this.symmetricEncryptionAlgorithm&&(c=32,b=this.s2k.produce_key(a,c));c=normal_cfb_decrypt(function(a,b){return AESencrypt(util.str2bin(a),b)},this.IVLength,keyExpansion(b.substring(0,c)),this.encryptedMPIData,this.IV);break;case 10:return util.print_error("openpgp.packet.keymaterial.js\nKey material is encrypted with twofish: not implemented"),!1;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm), +!1;case 2:c=normal_cfb_decrypt(function(b,a){return des(a,b,1,null,0)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 3:c=normal_cfb_decrypt(function(b,a){var c=new openpgp_symenc_cast5;c.setKey(a);return c.encrypt(util.str2bin(b))},this.IVLength,util.str2bin(b.substring(0,16)),this.encryptedMPIData,this.IV);break;case 4:c=normal_cfb_decrypt(function(b,a){return(new Blowfish(a)).encrypt(b)},this.IVLength,b,this.encryptedMPIData,this.IV);break;case 7:case 8:case 9:c=16;8==this.symmetricEncryptionAlgorithm&& +(c=24,b=this.s2k.produce_key(a,c));9==this.symmetricEncryptionAlgorithm&&(c=32,b=this.s2k.produce_key(a,c));c=normal_cfb_decrypt(function(b,a){return AESencrypt(util.str2bin(b),a)},this.IVLength,keyExpansion(b.substring(0,c)),this.encryptedMPIData,this.IV);break;case 10:return util.print_error("openpgp.packet.keymaterial.js\nKey material is encrypted with twofish: not implemented"),!1;default:return util.print_error("openpgp.packet.keymaterial.js\nunknown encryption algorithm for secret key :"+this.symmetricEncryptionAlgorithm), !1}if(null==c)return util.print_error("openpgp.packet.keymaterial.js\ncleartextMPIs was null"),!1;a=c.length;if(254==this.s2kUsageConventions&&str_sha1(c.substring(0,c.length-20))==c.substring(c.length-20))a-=20;else if(254!=this.s2kUsageConventions&&util.calc_checksum(c.substring(0,c.length-2))==(c.charCodeAt(c.length-2)<<8|c.charCodeAt(c.length-1)))a-=2;else return!1;if(0this.publicKey.publicKeyAlgorithm)b=0,this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi, this.secMPIs[0].read(c,0,a),b+=this.secMPIs[0].packetLength,this.secMPIs[1]=new openpgp_type_mpi,this.secMPIs[1].read(c,b,a-b),b+=this.secMPIs[1].packetLength,this.secMPIs[2]=new openpgp_type_mpi,this.secMPIs[2].read(c,b,a-b),b+=this.secMPIs[2].packetLength,this.secMPIs[3]=new openpgp_type_mpi,this.secMPIs[3].read(c,b,a-b),b+=this.secMPIs[3].packetLength;else if(16==this.publicKey.publicKeyAlgorithm)this.secMPIs=[],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,c);else if(17==this.publicKey.publicKeyAlgorithm)this.secMPIs= [],this.secMPIs[0]=new openpgp_type_mpi,this.secMPIs[0].read(c,0,a);return!0};this.read_nodes=function(a,b,c,d){this.parentNode=a;if(14==this.tagType){for(var a=c,e=null;b.length!=a;)if(d=b.length-a,e=openpgp_packet.read_packet(b,a,d),null==e){util.print_error("openpgp.packet.keymaterial.js\n[user_keymat_pub]parsing ends here @:"+a+" l:"+d);break}else switch(e.tagType){case 2:if(24==e.signatureType){this.subKeySignature=e;a+=e.packetLength+e.headerLength;break}else if(40==e.signatureType){this.subKeyRevocationSignature= @@ -76,29 +76,29 @@ if(4==this.subKeySignature.version&&null!=this.subKeySignature.keyNeverExpires&& (a=String.fromCharCode(153)+this.parentNode.header.substring(1)+this.parentNode.data+String.fromCharCode(153)+this.header.substring(1)+this.packetdata),this.subKeyRevocationSignature[0].verify(a,this.parentNode)?2:0}return 3};this.getKeyId=function(){if(4==this.version)return this.getFingerprint().substring(12,20);if(3==this.version&&0this.publicKeyAlgorithm){var a=this.MPIs[0].substring(this.MPIs[0].mpiByteLength-8);util.print_debug("openpgp.msg.publickey read_nodes:\nV3 key ID: "+ a);return a}};this.getFingerprint=function(){if(4==this.version)return tohash=String.fromCharCode(153)+String.fromCharCode(this.packetdata.length>>8&255)+String.fromCharCode(this.packetdata.length&255)+this.packetdata,util.print_debug("openpgp.msg.publickey creating subkey fingerprint by hashing:"+util.hexstrdump(tohash)+"\npublickeyalgorithm: "+this.publicKeyAlgorithm),str_sha1(tohash,tohash.length);if(3==this.version&&0this.publicKeyAlgorithm)return MD5(this.MPIs[0].MPI)}; this.write_private_key=function(a,b,c,d,e,f){this.symmetricEncryptionAlgorithm=e;e=String.fromCharCode(4);e+=f;switch(a){case 1:e+=String.fromCharCode(a);e+=b.n.toMPI();e+=b.ee.toMPI();if(c)switch(e+=String.fromCharCode(254),e+=String.fromCharCode(this.symmetricEncryptionAlgorithm),e+=String.fromCharCode(3),e+=String.fromCharCode(d),a=b.d.toMPI()+b.p.toMPI()+b.q.toMPI()+b.u.toMPI(),b=str_sha1(a),util.print_debug_hexstr_dump("write_private_key sha1: ",b),f=openpgp_crypto_getRandomBytes(8),util.print_debug_hexstr_dump("write_private_key Salt: ", -f),e=e+f+String.fromCharCode(96),util.print_debug("write_private_key c: 96"),c=(new openpgp_type_s2k).write(3,d,c,f,96),this.symmetricEncryptionAlgorithm){case 3:this.IVLength=8;this.IV=openpgp_crypto_getRandomBytes(this.IVLength);ciphertextMPIs=normal_cfb_encrypt(function(a,b){var c=new openpgp_symenc_cast5;c.setKey(b);return c.encrypt(util.str2bin(a))},this.IVLength,util.str2bin(c.substring(0,16)),a+b,this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength), +f),e=e+f+String.fromCharCode(96),util.print_debug("write_private_key c: 96"),c=(new openpgp_type_s2k).write(3,d,c,f,96),this.symmetricEncryptionAlgorithm){case 3:this.IVLength=8;this.IV=openpgp_crypto_getRandomBytes(this.IVLength);ciphertextMPIs=normal_cfb_encrypt(function(b,a){var c=new openpgp_symenc_cast5;c.setKey(a);return c.encrypt(util.str2bin(b))},this.IVLength,util.str2bin(c.substring(0,16)),a+b,this.IV);e+=this.IV+ciphertextMPIs;break;case 7:case 8:case 9:this.IVLength=16,this.IV=openpgp_crypto_getRandomBytes(this.IVLength), ciphertextMPIs=normal_cfb_encrypt(AESencrypt,this.IVLength,c,a+b,this.IV),e+=this.IV+ciphertextMPIs}else e+=String.fromCharCode(0),e+=b.d.toMPI()+b.p.toMPI()+b.q.toMPI()+b.u.toMPI(),c=util.calc_checksum(b.d.toMPI()+b.p.toMPI()+b.q.toMPI()+b.u.toMPI()),e+=String.fromCharCode(c/256)+String.fromCharCode(c%256),util.print_debug_hexstr_dump("write_private_key basic checksum: "+c);break;default:e="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+a)}c=openpgp_packet.write_packet_header(5, e.length);return{string:c+e,header:c,body:e}};this.write_public_key=function(a,b,c){var d=String.fromCharCode(4),d=d+c;switch(a){case 1:d+=String.fromCharCode(1);d+=b.n.toMPI();d+=b.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+a)}a=openpgp_packet.write_packet_header(6,d.length);return{string:a+d,header:a,body:d}}} function openpgp_packet_marker(){this.tagType=10;this.read_packet=function(a,b){this.packetLength=3;return 80==a[b].charCodeAt()&&71==a[b+1].charCodeAt()&&80==a[b+2].charCodeAt()?this:null};this.toString=function(){return'5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)\n packet reads: "PGP"\n'}} function openpgp_packet_modificationdetectioncode(){this.tagType=19;this.hash=null;this.read_packet=function(a,b,c){this.packetLength=c;if(20!=c)return util.print_error("openpgp.packet.modificationdetectioncode.js\ninvalid length for a modification detection code packet!"+c),null;this.hash=a.substring(b,b+20);return this};this.toString=function(){return"5.14 Modification detection code packet\n bytes ("+this.hash.length+"): ["+util.hexstrdump(this.hash)+"]"}} -function _openpgp_packet(){function a(a){result="";192>a?result+=String.fromCharCode(a):191a?(result+=String.fromCharCode((a-192>>8)+192),result+=String.fromCharCode(a-192&255)):(result+=String.fromCharCode(255),result+=String.fromCharCode(a>>24&255),result+=String.fromCharCode(a>>16&255),result+=String.fromCharCode(a>>8&255),result+=String.fromCharCode(a&255));return result}this.encode_length=a;this.write_old_packet_header=function(a,c){var d="";256>c?(d+=String.fromCharCode(128|a<<2),d+= -String.fromCharCode(c)):(65536>c?(d+=String.fromCharCode(a<<2|129),d+=String.fromCharCode(c>>8)):(d+=String.fromCharCode(a<<2|130),d+=String.fromCharCode(c>>24&255),d+=String.fromCharCode(c>>16&255),d+=String.fromCharCode(c>>8&255)),d+=String.fromCharCode(c&255));return d};this.write_packet_header=function(b,c){var d;d=""+String.fromCharCode(192|b);return d+=a(c)};this.read_packet=function(a,c){if(null==a||a.length<=c||2>a.substring(c).length||0==(a[c].charCodeAt()&128))return util.print_error("Error during parsing. This message / key is propably not containing a valid OpenPGP format."), -null;var d=c,e=-1,f=-1,f=0;0!=(a[d].charCodeAt()&64)&&(f=1);var g;f?e=a[d].charCodeAt()&63:(e=(a[d].charCodeAt()&63)>>2,g=a[d].charCodeAt()&3);d++;var h=null,k=-1;if(f)if(192>a[d].charCodeAt())packet_length=a[d++].charCodeAt(),util.print_debug("1 byte length:"+packet_length);else if(192<=a[d].charCodeAt()&&224>a[d].charCodeAt())packet_length=(a[d++].charCodeAt()-192<<8)+a[d++].charCodeAt()+192,util.print_debug("2 byte length:"+packet_length);else if(223a[d].charCodeAt()){packet_length= -1<<(a[d++].charCodeAt()&31);util.print_debug("4 byte length:"+packet_length);k=d+packet_length;for(h=a.substring(d,d+packet_length);;)if(192>a[k].charCodeAt()){f=a[k++].charCodeAt();packet_length+=f;h+=a.substring(k,k+f);k+=f;break}else if(192<=a[k].charCodeAt()&&224>a[k].charCodeAt()){f=(a[k++].charCodeAt()-192<<8)+a[k++].charCodeAt()+192;packet_length+=f;h+=a.substring(k,k+f);k+=f;break}else if(223a[k].charCodeAt())f=1<<(a[k++].charCodeAt()&31),packet_length+=f,h+=a.substring(k, -k+f),k+=f;else{k++;f=a[k++].charCodeAt()<<24|a[k++].charCodeAt()<<16|a[k++].charCodeAt()<<8|a[k++].charCodeAt();h+=a.substring(k,k+f);packet_length+=f;k+=f;break}}else d++,packet_length=a[d++].charCodeAt()<<24|a[d++].charCodeAt()<<16|a[d++].charCodeAt()<<8|a[d++].charCodeAt();else switch(g){case 0:packet_length=a[d++].charCodeAt();break;case 1:packet_length=a[d++].charCodeAt()<<8|a[d++].charCodeAt();break;case 2:packet_length=a[d++].charCodeAt()<<24|a[d++].charCodeAt()<<16|a[d++].charCodeAt()<<8| -a[d++].charCodeAt()}-1==k&&(k=packet_length);null==h&&(h=a.substring(d,d+k));switch(e){case 0:break;case 1:e=new openpgp_packet_encryptedsessionkey;if(null!=e.read_pub_key_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 2:e=new openpgp_packet_signature;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 3:e=new openpgp_packet_encryptedsessionkey;if(null!=e.read_symmetric_key_packet(h,0,packet_length))return e.headerLength= -d-c,e.packetLength=k,e;break;case 4:e=new openpgp_packet_onepasssignature;if(e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 5:e=new openpgp_packet_keymaterial;e.header=a.substring(c,d);if(null!=e.read_tag5(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 6:e=new openpgp_packet_keymaterial;e.header=a.substring(c,d);if(null!=e.read_tag6(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 7:e=new openpgp_packet_keymaterial; -if(null!=e.read_tag7(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 8:e=new openpgp_packet_compressed;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 9:e=new openpgp_packet_encrypteddata;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 10:e=new openpgp_packet_marker;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 11:e=new openpgp_packet_literaldata; -if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.header=a.substring(c,d),e.packetLength=k,e;break;case 12:break;case 13:e=new openpgp_packet_userid;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 14:e=new openpgp_packet_keymaterial;e.header=a.substring(c,d);if(null!=e.read_tag14(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 17:e=new openpgp_packet_userattribute;if(null!=e.read_packet(h,0,packet_length))return e.headerLength= -d-c,e.packetLength=k,e;break;case 18:e=new openpgp_packet_encryptedintegrityprotecteddata;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;case 19:e=new openpgp_packet_modificationdetectioncode;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-c,e.packetLength=k,e;break;default:return util.print_error("openpgp.packet.js\n[ERROR] openpgp_packet: failed to parse packet @:"+d+"\nchar:'"+util.hexstrdump(a.substring(d))+"'\ninput:"+util.hexstrdump(a)), +function _openpgp_packet(){function a(b){result="";192>b?result+=String.fromCharCode(b):191b?(result+=String.fromCharCode((b-192>>8)+192),result+=String.fromCharCode(b-192&255)):(result+=String.fromCharCode(255),result+=String.fromCharCode(b>>24&255),result+=String.fromCharCode(b>>16&255),result+=String.fromCharCode(b>>8&255),result+=String.fromCharCode(b&255));return result}this.encode_length=a;this.write_old_packet_header=function(b,a){var d="";256>a?(d+=String.fromCharCode(128|b<<2),d+= +String.fromCharCode(a)):(65536>a?(d+=String.fromCharCode(b<<2|129),d+=String.fromCharCode(a>>8)):(d+=String.fromCharCode(b<<2|130),d+=String.fromCharCode(a>>24&255),d+=String.fromCharCode(a>>16&255),d+=String.fromCharCode(a>>8&255)),d+=String.fromCharCode(a&255));return d};this.write_packet_header=function(b,c){var d;d=""+String.fromCharCode(192|b);return d+=a(c)};this.read_packet=function(b,a){if(null==b||b.length<=a||2>b.substring(a).length||0==(b[a].charCodeAt()&128))return util.print_error("Error during parsing. This message / key is propably not containing a valid OpenPGP format."), +null;var d=a,e=-1,f=-1,f=0;0!=(b[d].charCodeAt()&64)&&(f=1);var g;f?e=b[d].charCodeAt()&63:(e=(b[d].charCodeAt()&63)>>2,g=b[d].charCodeAt()&3);d++;var h=null,k=-1;if(f)if(192>b[d].charCodeAt())packet_length=b[d++].charCodeAt(),util.print_debug("1 byte length:"+packet_length);else if(192<=b[d].charCodeAt()&&224>b[d].charCodeAt())packet_length=(b[d++].charCodeAt()-192<<8)+b[d++].charCodeAt()+192,util.print_debug("2 byte length:"+packet_length);else if(223b[d].charCodeAt()){packet_length= +1<<(b[d++].charCodeAt()&31);util.print_debug("4 byte length:"+packet_length);k=d+packet_length;for(h=b.substring(d,d+packet_length);;)if(192>b[k].charCodeAt()){f=b[k++].charCodeAt();packet_length+=f;h+=b.substring(k,k+f);k+=f;break}else if(192<=b[k].charCodeAt()&&224>b[k].charCodeAt()){f=(b[k++].charCodeAt()-192<<8)+b[k++].charCodeAt()+192;packet_length+=f;h+=b.substring(k,k+f);k+=f;break}else if(223b[k].charCodeAt())f=1<<(b[k++].charCodeAt()&31),packet_length+=f,h+=b.substring(k, +k+f),k+=f;else{k++;f=b[k++].charCodeAt()<<24|b[k++].charCodeAt()<<16|b[k++].charCodeAt()<<8|b[k++].charCodeAt();h+=b.substring(k,k+f);packet_length+=f;k+=f;break}}else d++,packet_length=b[d++].charCodeAt()<<24|b[d++].charCodeAt()<<16|b[d++].charCodeAt()<<8|b[d++].charCodeAt();else switch(g){case 0:packet_length=b[d++].charCodeAt();break;case 1:packet_length=b[d++].charCodeAt()<<8|b[d++].charCodeAt();break;case 2:packet_length=b[d++].charCodeAt()<<24|b[d++].charCodeAt()<<16|b[d++].charCodeAt()<<8| +b[d++].charCodeAt()}-1==k&&(k=packet_length);null==h&&(h=b.substring(d,d+k));switch(e){case 0:break;case 1:e=new openpgp_packet_encryptedsessionkey;if(null!=e.read_pub_key_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 2:e=new openpgp_packet_signature;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 3:e=new openpgp_packet_encryptedsessionkey;if(null!=e.read_symmetric_key_packet(h,0,packet_length))return e.headerLength= +d-a,e.packetLength=k,e;break;case 4:e=new openpgp_packet_onepasssignature;if(e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 5:e=new openpgp_packet_keymaterial;e.header=b.substring(a,d);if(null!=e.read_tag5(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 6:e=new openpgp_packet_keymaterial;e.header=b.substring(a,d);if(null!=e.read_tag6(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 7:e=new openpgp_packet_keymaterial; +if(null!=e.read_tag7(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 8:e=new openpgp_packet_compressed;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 9:e=new openpgp_packet_encrypteddata;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 10:e=new openpgp_packet_marker;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 11:e=new openpgp_packet_literaldata; +if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.header=b.substring(a,d),e.packetLength=k,e;break;case 12:break;case 13:e=new openpgp_packet_userid;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 14:e=new openpgp_packet_keymaterial;e.header=b.substring(a,d);if(null!=e.read_tag14(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 17:e=new openpgp_packet_userattribute;if(null!=e.read_packet(h,0,packet_length))return e.headerLength= +d-a,e.packetLength=k,e;break;case 18:e=new openpgp_packet_encryptedintegrityprotecteddata;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;case 19:e=new openpgp_packet_modificationdetectioncode;if(null!=e.read_packet(h,0,packet_length))return e.headerLength=d-a,e.packetLength=k,e;break;default:return util.print_error("openpgp.packet.js\n[ERROR] openpgp_packet: failed to parse packet @:"+d+"\nchar:'"+util.hexstrdump(b.substring(d))+"'\ninput:"+util.hexstrdump(b)), null}}}var openpgp_packet=new _openpgp_packet; function openpgp_packet_literaldata(){this.tagType=11;this.read_packet=function(a,b,c){this.packetLength=c;this.format=a[b];this.filename=a.substr(b+2,a.charCodeAt(b+1));this.date=new Date(1E3*parseInt(a.substr(b+2+a.charCodeAt(b+1),4)));this.data=a.substring(b+6+a.charCodeAt(b+1));return this};this.toString=function(){return"5.9. Literal Data Packet (Tag 11)\n length: "+this.packetLength+"\n format: "+this.format+"\n filename:"+this.filename+"\n date: "+this.date+"\n data: |"+ this.data+"|\n rdata: |"+this.real_data+"|\n"};this.write_packet=function(a){a=a.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n");this.filename="msg.txt";this.date=new Date;this.format="t";var b=openpgp_packet.write_packet_header(11,a.length+6+this.filename.length),b=b+this.format,b=b+String.fromCharCode(this.filename.length),b=b+this.filename,b=b+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>24&255),b=b+String.fromCharCode(Math.round(this.date.getTime()/1E3)>>16&255),b=b+String.fromCharCode(Math.round(this.date.getTime()/ 1E3)>>8&255),b=b+String.fromCharCode(Math.round(this.date.getTime()/1E3)&255);this.data=a;return b+a}} function openpgp_packet_compressed(){this.tagType=8;this.read_packet=function(a,b,c){this.packetLength=c;var d=b;this.type=a.charCodeAt(d++);this.compressedData=a.substring(b+1,b+c);return this};this.toString=function(){return"5.6. Compressed Data Packet (Tag 8)\n length: "+this.packetLength+"\n Compression Algorithm = "+this.type+"\n Compressed Data: Byte ["+util.hexstrdump(this.compressedData)+"]\n"};this.compress=function(a,b){this.type=a;this.decompressedData=b;switch(this.type){case 0:this.compressedData= this.decompressedData;break;case 1:util.print_error("Compression algorithm ZIP [RFC1951] is not implemented.");break;case 2:util.print_error("Compression algorithm ZLIB [RFC1950] is not implemented.");break;case 3:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}this.packetLength=this.compressedData.length+1;return this.compressedData};this.decompress=function(){if(null!=this.decompressedData)return this.decompressedData; -if(null==this.type)return null;switch(this.type){case 0:this.decompressedData=this.compressedData;break;case 1:var a=new zip.Inflater,a=a.append(util.str2Uint8Array(this.compressedData)),a=util.Uint8Array2str(a),a=openpgp_packet.read_packet(a,0,a.length);util.print_info("Decompressed packet [Type 1-ZIP]: "+a);this.decompressedData=a.data;break;case 2:8==this.compressedData.charCodeAt(0)%16?(a=new zip.Inflater,a=a.append(util.str2Uint8Array(this.compressedData.substring(2,this.compressedData.length- -4))),a=util.Uint8Array2str(a),a=openpgp_packet.read_packet(a,0,a.length),util.print_info("Decompressed packet [Type 2-ZLIB]: "+a),this.decompressedData=a.data):util.print_error("Compression algorithm ZLIB is not fully implemented.");break;case 3:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}util.print_debug("decompressed:"+util.hexstrdump(this.decompressedData));return this.decompressedData};this.write_packet= +if(null==this.type)return null;switch(this.type){case 0:this.decompressedData=this.compressedData;break;case 1:var a=(new zip.Inflater).append(util.str2Uint8Array(this.compressedData)),a=util.Uint8Array2str(a),a=openpgp_packet.read_packet(a,0,a.length);util.print_info("Decompressed packet [Type 1-ZIP]: "+a);this.decompressedData=a.data;break;case 2:8==this.compressedData.charCodeAt(0)%16?(a=this.compressedData.substring(0,this.compressedData.length-4),a=s2r(a).replace(/\n/g,""),a=JXG.decompress(a), +a=openpgp_packet.read_packet(a,0,a.length),util.print_info("Decompressed packet [Type 2-ZLIB]: "+a),this.decompressedData=a.data):util.print_error("Compression algorithm ZLIB only supports DEFLATE compression method.");break;case 3:util.print_error("Compression algorithm BZip2 [BZ2] is not implemented.");break;default:util.print_error("Compression algorithm unknown :"+this.type)}util.print_debug("decompressed:"+util.hexstrdump(this.decompressedData));return this.decompressedData};this.write_packet= function(a,b){this.decompressedData=b;if(null==a)this.type=1;var c=String.fromCharCode(this.type)+this.compress(this.type);return openpgp_packet.write_packet_header(8,c.length)+c}} function openpgp_packet_userid(){this.tagType=13;this.certificationSignatures=[];this.certificationRevocationSignatures=[];this.revocationSignatures=[];this.parentNode=null;this.hasCertificationRevocationSignature=function(a){for(var b=0;be.length;)e="0"+e;b.push(" "+e);f++;0==f%32&&b.push("\n ")}return b.join("")};this.hexstrdump=function(a){if(null==a)return"";for(var b=[],c=a.length,d=0,e;de.length;)e= "0"+e;b.push(""+e)}return b.join("")};this.hex2bin=function(a){for(var b="",c=0;ce.length;)e="0"+e;b.push(""+e)}return b.join("")};this.str2bin=function(a){for(var b=[],c=0;c

'+ +function(a){for(var b=new Uint8Array(new ArrayBuffer(a.length)),c=0;c

'+ a.replace(/\n/g,"
")+"

"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('

'+a.replace(/\n/g,"
")+"

"))};this.print_error=function(a){a=openpgp_encoding_html_encode(a);showMessages('

ERROR:\t'+ a.replace(/\n/g,"
")+"

")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('

INFO:\t'+a.replace(/\n/g,"
")+"

")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('

WARNING:\t'+ a.replace(/\n/g,"
")+"

")};this.getLeftNBits=function(a,b){var c=b%8;return 0==c?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-c)/8+1),8-c)};this.shiftRight=function(a,b){var c=util.str2bin(a);if(0!=b%8)for(var d=c.length-1;0<=d;d--)c[d]>>=b%8,0s&&(r=s);x[0]=r;for(x=1<(x-=e[q]))return w;if(0>(x-=e[s]))return w;e[s]+=x;k[1]=q=0;U=1;for(z=2;0!==--s;)k[z]=q+=e[U],z++,U++;U=s=0;do{if(0!==(q=b[c+U]))p[k[q]++]=s;U++}while(++sy+r;){c++;y+=r;V=ga-y;V=V>r?r:V;if((l=1<<(q=u-y))>b+1)if(l-=b+1,z=u,qba)return w;g[c]=z=o[0];o[0]+=V;0!==c?(k[c]=s,f[0]=q,f[1]=r,q=s>>>y-r,f[2]=z-g[c-1]-q,Q.set(f,3*(g[c-1]+q))):t[0]=z}f[1]=u-y;U>=d?f[0]=192:p[U]p[U]?0:96,f[2]=p[U++]):(f[0]=O[p[U]-Ea]+16+64,f[2]=j[p[U++]-Ea]);l=1<>>y;q>>=1)s^=q;s^=q;for(q=(1<h;h++)f[h]=0;g.set(e.subarray(0,W),0);k.set(e.subarray(0,W+1),0)}var c,d,e,f,g,k;this.inflate_trees_bits=function(e,f,h,g,k){b(19);c[0]=0;e=a(e,0,19,19,null,null,h,f,g,c,d);if(e==w)k.msg="oversubscribed dynamic bit lengths tree";else if(e==v||0===f[0])k.msg="incomplete dynamic bit lengths tree", -e=w;return e};this.inflate_trees_dynamic=function(e,f,g,k,j,O,t,x,Q){b(288);c[0]=0;O=a(g,0,e,257,ma,la,O,k,x,c,d);if(O!=h||0===k[0]){if(O==w)Q.msg="oversubscribed literal/length tree";else if(O!=C)Q.msg="incomplete literal/length tree",O=w;return O}b(288);O=a(g,e,f,0,ia,ja,t,j,x,c,d);if(O!=h||0===j[0]&&257p;)E--,o|=(u.read_byte(T++)&255)<>=R[Y+1],p-=R[Y+1],q.window[P++]=R[Y+2],qa--;else{do{o>>=R[Y+1];p-=R[Y+1];if(0!==(K&16)){K&=15;M=R[Y+2]+(o&y[K]);o>>=K;for(p-=K;15>p;)E--,o|=(u.read_byte(T++)&255)<>=R[Y+1],p-=R[Y+1],0!==(K&16)){for(K&=15;p>=K;p-=K;qa-=M;if(P>=m)m=P-m,0P-m?(q.window[P++]=q.window[m++],q.window[P++]=q.window[m++]):(q.window.set(q.window.subarray(m,m+2),P),P+=2,m+=2),M-=2;else{m=P-m;do m+=q.end;while(0>m);K=q.end-m;if(M>K){M-=K;if(0P-m){do q.window[P++]=q.window[m++];while(0!==--K)}else q.window.set(q.window.subarray(m,m+K),P),P+=K;m=0}}if(0P-m){do q.window[P++]=q.window[m++];while(0!==--M)}else q.window.set(q.window.subarray(m,m+M),P),P+=M;break}else if(0===(K& -64))m+=R[Y+2],m+=o&y[K],Y=3*(na+m),K=R[Y];else{u.msg="invalid distance code";M=u.avail_in-E;M=p>>3>3:M;E+=M;T-=M;p-=M<<3;q.bitb=o;q.bitk=p;u.avail_in=E;u.total_in+=T-u.next_in_index;u.next_in_index=T;q.write=P;N=w;break a}while(1);break}if(0===(K&64)){if(m+=R[Y+2],m+=o&y[K],Y=3*(na+m),0===(K=R[Y])){o>>=R[Y+1];p-=R[Y+1];q.window[P++]=R[Y+2];qa--;break}}else{if(0!==(K&32)){M=u.avail_in-E;M=p>>3>3:M;E+=M;T-=M;p-=M<<3;q.bitb=o;q.bitk=p;u.avail_in=E;u.total_in+=T-u.next_in_index;u.next_in_index= -T;q.write=P;N=k;break a}u.msg="invalid literal/length code";M=u.avail_in-E;M=p>>3>3:M;E+=M;T-=M;p-=M<<3;q.bitb=o;q.bitk=p;u.avail_in=E;u.total_in+=T-u.next_in_index;u.next_in_index=T;q.write=P;N=w;break a}}while(1)}}while(258<=qa&&10<=E);M=u.avail_in-E;M=p>>3>3:M;E+=M;T-=M;p-=M<<3;q.bitb=o;q.bitk=p;u.avail_in=E;u.total_in+=T-u.next_in_index;u.next_in_index=T;q.write=P;N=h}s=x.next_in_index;q=x.avail_in;A=t.bitb;B=t.bitk;u=t.write;K=u>>=c[o+1];B-=c[o+1];p=c[o];if(0===p){f=c[o+2];a=O;break}if(0!==(p&16)){g=p&15;b=c[o+2];a=oa;break}if(0===(p&64)){e=p;d=o/3+c[o+2];break}if(0!==(p&32)){a=Q;break}a=U;x.msg="invalid literal/length code";N=w;t.bitb=A;t.bitk=B;x.avail_in=q;x.total_in+=s-x.next_in_index;x.next_in_index= -s;t.write=u;return t.inflate_flush(x,N);case oa:for(o=g;B>=o;B-=o;e=z;c=C;d=D;a=ea;case ea:for(o=e;B>=c[o+1];B-=c[o+ -1];p=c[o];if(0!==(p&16)){g=p&15;j=c[o+2];a=aa;break}if(0===(p&64)){e=p;d=o/3+c[o+2];break}a=U;x.msg="invalid distance code";N=w;t.bitb=A;t.bitk=B;x.avail_in=q;x.total_in+=s-x.next_in_index;x.next_in_index=s;t.write=u;return t.inflate_flush(x,N);case aa:for(o=g;B>=o;B-=o;a=pa;case pa:for(o=u-j;0>o;)o+=t.end;for(;0!== -b;){if(0===K&&(u==t.end&&0!==t.read&&(u=0,K=ua.avail_out)c=a.avail_out;0!==c&&b==v&&(b=h);a.avail_out-=c;a.total_out+=c;a.next_out.set(e.window.subarray(f,f+c),d);d+=c;f+=c;if(f==e.end){f=0;if(e.write==e.end)e.write=0;c=e.write-f;if(c>a.avail_out)c=a.avail_out;0!==c&&b==v&&(b=h);a.avail_out-= -c;a.total_out+=c;a.next_out.set(e.window.subarray(f,f+c),d);d+=c;f+=c}a.next_out_index=d;e.read=f;return b};e.proc=function(a,c){var d,o,p,A,B,s,q;A=a.next_in_index;B=a.avail_in;o=e.bitb;p=e.bitk;s=e.write;for(q=sp;){if(0!==B)c=h;else return e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);B--;o|=(a.read_byte(A++)&255)<>>1){case 0:o>>>=3;p-=3;d=p&7;o>>>=d; -p-=d;f=na;break;case 1:d=[];var u=[],v=[[]],V=[[]];b.inflate_trees_fixed(d,u,v,V,a);ga.init(d[0],u[0],v[0],0,V[0],0,a);o>>>=3;p-=3;f=Da;break;case 2:o>>>=3;p-=3;f=Ca;break;case 3:return o>>>=3,p-=3,f=ha,a.msg="invalid block type",c=w,e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c)}break;case na:for(;32>p;){if(0!==B)c=h;else return e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a, -c);B--;o|=(a.read_byte(A++)&255)<>>16&65535)!=(o&65535))return f=ha,a.msg="invalid stored block lengths",c=w,e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);g=o&65535;o=p=0;f=0!==g?qa:0!==m?z:R;break;case qa:if(0===B||0===q&&(s==e.end&&0!==e.read&&(s=0,q=sB&&(d=B);d>q&&(d=q);e.window.set(a.read_buf(A,d),s);A+=d;B-=d;s+=d;q-=d;if(0!==(g-=d))break;f=0!==m?z:R;break;case Ca:for(;14>p;){if(0!==B)c=h;else return e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);B--;o|=(a.read_byte(A++)&255)<>5&31))return f=ha,a.msg="too many length or distance symbols", -c=w,e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);d=258+(d&31)+(d>>5&31);if(!Q||Q.length>>=14;p-=14;O=0;f=Ga;case Ga:for(;O<4+(j>>>10);){for(;3>p;){if(0!==B)c=h;else return e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);B--;o|=(a.read_byte(A++)&255)<>>=3;p-=3}for(;19>O;)Q[ua[O++]]=0;r[0]=7;d=D.inflate_trees_bits(Q, -r,U,C,a);if(d!=h)return c=d,c==w&&(Q=null,f=ha),e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);O=0;f=T;case T:for(;;){d=j;if(!(O<258+(d&31)+(d>>5&31)))break;for(d=r[0];pv)o>>>=d,p-=d,Q[O++]=v;else{q=18==v? -7:v-14;for(u=18==v?11:3;p>>=d;p-=d;u+=o&y[q];o>>>=q;p-=q;q=O;d=j;if(q+u>258+(d&31)+(d>>5&31)||16==v&&1>q)return Q=null,f=ha,a.msg="invalid bit length repeat",c=w,e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);v=16==v?Q[q-1]:0;do Q[q++]=v;while(0!==--u);O=q}}U[0]= --1;q=[];u=[];v=[];V=[];q[0]=9;u[0]=6;d=j;d=D.inflate_trees_dynamic(257+(d&31),1+(d>>5&31),Q,q,u,v,V,C,a);if(d!=h)return d==w&&(Q=null,f=ha),c=d,e.bitb=o,e.bitk=p,a.avail_in=B,a.total_in+=A-a.next_in_index,a.next_in_index=A,e.write=s,e.inflate_flush(a,c);ga.init(q[0],u[0],C,v[0],C,V[0],a);f=Da;case Da:e.bitb=o;e.bitk=p;a.avail_in=B;a.total_in+=A-a.next_in_index;a.next_in_index=A;e.write=s;if((c=ga.proc(e,a,c))!=k)return e.inflate_flush(a,c);c=h;ga.free(a);A=a.next_in_index;B=a.avail_in;o=e.bitb;p= -e.bitk;s=e.write;q=se||15>4)+8>a.istate.wbits){a.istate.mode=ka;a.msg="invalid window size";a.istate.marker=5;break}a.istate.mode=ca;case ca:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;d=a.read_byte(a.next_in_index++)&255;if(0!==((a.istate.method<<8)+d)%31){a.istate.mode=ka;a.msg="incorrect header check";a.istate.marker=5;break}if(0===(d&da)){a.istate.mode=ra;break}a.istate.mode=xa;case xa:if(0===a.avail_in)return c;c=b;a.avail_in--; -a.total_in++;a.istate.need=(a.read_byte(a.next_in_index++)&255)<<24&4278190080;a.istate.mode=ya;case ya:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.read_byte(a.next_in_index++)&255)<<16&16711680;a.istate.mode=za;case za:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.read_byte(a.next_in_index++)&255)<<8&65280;a.istate.mode=Aa;case Aa:if(0===a.avail_in)return c;a.avail_in--;a.total_in++;a.istate.need+=a.read_byte(a.next_in_index++)&255;a.istate.mode= -sa;return j;case sa:return a.istate.mode=ka,a.msg="need dictionary",a.istate.marker=0,l;case ra:c=a.istate.blocks.proc(a,c);if(c==w){a.istate.mode=ka;a.istate.marker=0;break}c==h&&(c=b);if(c!=k)return c;a.istate.blocks.reset(a,a.istate.was);a.istate.mode=Ba;case Ba:return k;case ka:return w;default:return l}};b.inflateSetDictionary=function(a,b,c){var d=0,e=c;if(!a||!a.istate||a.istate.mode!=sa)return l;e>=1<e;)b.read_byte(d)==r[e]?e++:e=0!==b.read_byte(d)?0:4-e,d++,c--;b.total_in+=d-b.next_in_index;b.next_in_index=d;b.avail_in=c;b.istate.marker=e;if(4!=e)return w;c=b.total_in;d=b.total_out;a(b);b.total_in=c;b.total_out=d;b.istate.mode=ra;return h};b.inflateSyncPoint=function(a){return!a||!a.istate|| -!a.istate.blocks?l:a.istate.blocks.sync_point()}}function f(){}function g(){var a=new f,b=fa,c=new Uint8Array(512),d=!1;a.inflateInit();a.next_out=c;this.append=function(e,f){var g,j=[],O=0,Q=0,l=0,r;if(0!==e.length){a.next_in_index=0;a.next_in=e;a.avail_in=e.length;do{a.next_out_index=0;a.avail_out=512;if(0===a.avail_in&&!d)a.next_in_index=0,d=!0;g=a.inflate(b);if(d&&g==v)return-1;if(g!=h&&g!=k)throw"inflating: "+a.msg;if((d||g==k)&&a.avail_out==e.length)return-1;a.next_out_index&&(512==a.next_out_index? -j.push(new Uint8Array(c)):j.push(new Uint8Array(c.subarray(0,a.next_out_index))));l+=a.next_out_index;if(f&&0>=1;0==da&&(da=b(),a=da&1,da=da>>1|128);return a}function d(b){for(var a=0,d=b;d--;)a=a<<1|c();b&&(a=ga[a]>>8-b);return a}function e(b){na++;o[z++]=b;l.push(String.fromCharCode(b));32768==z&&(z=0)}function f(){this.b1=this.b0=0;this.jump=null;this.jumppos=-1}function g(){for(;;){if(ha[T]>=sa)return-1;if(O[ha[T]]==T)return ha[T]++;ha[T]++}}function h(){var b=aa[ia],a;p&&document.write("
len:"+ +T+" treepos:"+ia);if(17==T)return-1;ia++;T++;a=g();p&&document.write("
IsPat "+a);if(0<=a)b.b0=a,p&&document.write("
b0 "+b.b0);else if(b.b0=32768,p&&document.write("
b0 "+b.b0),h())return-1;a=g();if(0<=a)b.b1=a,p&&document.write("
b1 "+b.b1),b.jump=null;else if(b.b1=32768,p&&document.write("
b1 "+b.b1),b.jump=aa[ia],b.jumppos=ia,h())return-1;T--;return 0}function k(b,a,c,d){p&&document.write("currentTree "+b+" numval "+a+" lengths "+c+" show "+d);aa=b;ia=0;O=c;sa=a;for(b=0;17>b;b++)ha[b]= +0;T=0;if(h())return p&&alert("invalid huffman tree\n"),-1;if(p){document.write("
Tree: "+aa.length);for(b=0;32>b;b++)document.write("Places["+b+"].b0="+aa[b].b0+"
"),document.write("Places["+b+"].b1="+aa[b].b1+"
")}return 0}function j(b){for(var a,d,e=0,f=b[e];;)if(a=c(),p&&document.write("b="+a),a){if(!(f.b1&32768))return p&&document.write("ret1"),f.b1;f=f.jump;a=b.length;for(d=0;d>1,23g)e(g);else if(256==g)break;else{var M;g-=257;m=d(N[g])+la[g];g=ga[d(5)]>>3;8g;g++)u[g]=0;for(g=0;gdistanceTree");for(g=0;g"+K[g].b0+" "+K[g].b1+" "+K[g].jump+" "+K[g].jumppos)}m= +h+M;E=0;var Z=-1;for(p&&document.write("
n="+m+" bits: "+P+"
");E"+Z+" i:"+E+" decode: "+g+" bits "+P+"
"),16>g)u[E++]=g;else if(16==g){var l;g=3+d(2);if(E+g>m)return z=0,1;for(l=E?u[E-1]:0;g--;)u[E++]=l}else{g=17==g?3+d(3):11+d(7);if(E+g>m)return z=0,1;for(;g--;)u[E++]=0}m=ca.length;for(E=0;EliteralTree");;)if(g=j(ca),256<=g){g-=256;if(0==g)break;g--;m=d(N[g])+la[g];g=j(K);8>2,c=(c&3)<<4|d>>4,g=(d&15)<<2|e>>6,h=e&63,isNaN(d)?g=h=64:isNaN(e)&&(h=64),b.push([this._keyStr.charAt(f),this._keyStr.charAt(c),this._keyStr.charAt(g),this._keyStr.charAt(h)].join(""));return b.join("")},decode:function(a,b){for(var c=[],d,e,f,g,h, +k=0,a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");k>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|h,c.push(String.fromCharCode(d)),64!=g&&c.push(String.fromCharCode(e)),64!=h&&c.push(String.fromCharCode(f));c=c.join("");b&&(c=JXG.Util.Base64._utf8_decode(c));return c},_utf8_encode:function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;cd?b+=String.fromCharCode(d):(127d?b+=String.fromCharCode(d>>6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&63|128))}return b},_utf8_decode:function(a){for(var b=[],c=0,d=0,e=0,f=0;cd?(b.push(String.fromCharCode(d)),c++):191d?(e=a.charCodeAt(c+1),b.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=a.charCodeAt(c+1),f=a.charCodeAt(c+2),b.push(String.fromCharCode((d&15)<<12| +(e&63)<<6|f&63)),c+=3);return b.join("")},_destrip:function(a,b){var c=[],d,e,f=[];null==b&&(b=76);a.replace(/ /g,"");d=a.length/b;for(e=0;ed?(b.push(String.fromCharCode(d)),c++):191d?(e=a.charCodeAt(c+1),b.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=a.charCodeAt(c+1),f=a.charCodeAt(c+2),b.push(String.fromCharCode((d&15)<<12|(e&63)<<6|f&63)),c+=3);return b.join("")}; +JXG.Util.genUUID=function(){for(var a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),b=Array(36),c=0,d,e=0;36>e;e++)8==e||13==e||18==e||23==e?b[e]="-":14==e?b[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,b[e]=a[19==e?d&3|8:d]);return b.join("")};(function(a){a.zip={useWebWorkers:!1}})(this); +(function(a){function b(){function a(b,c,d,Ca,j,P,w,E,m,q,r){var M,p,v,s,x,t,Z,A,ca,W;Z=0;v=d;do e[b[c+Z]]++,Z++,v--;while(0!==v);if(e[0]==d)return w[0]=-1,E[0]=0,h;t=E[0];for(s=1;s<=N&&!(0!==e[s]);s++);x=s;tv&&(t=v);E[0]=t;for(E=1<(E-=e[s]))return u;if(0>(E-=e[v]))return u;e[v]+=E;k[1]=s=0;Z=1;for(A=2;0!==--v;)k[A]=s+=e[Z],A++,Z++;Z=v=0;do{if(0!==(s=b[c+Z]))r[k[s]++]=v;Z++}while(++vca+t;){c++;ca+=t;W=p-ca;W=W>t?t:W;if((M=1<<(s=x-ca))>b+1)if(M-=b+1,A=x,sY)return u;g[c]=A=q[0];q[0]+=W;0!==c?(k[c]=v,f[0]=s,f[1]=t,s=v>>>ca-t,f[2]=A-g[c-1]-s,m.set(f,3*(g[c-1]+s))):w[0]=A}f[1]=x-ca;Z>=d?f[0]=192:r[Z]r[Z]?0:96,f[2]=r[Z++]):(f[0]=P[r[Z]-Ca]+16+64,f[2]=j[r[Z++]-Ca]);M=1<>>ca;s>>=1)v^=s;v^=s;for(s=(1<h;h++)f[h]=0;g.set(e.subarray(0,N),0);k.set(e.subarray(0,N+1),0)}var c,d,e,f,g,k;this.inflate_trees_bits=function(e,f,g,h,k){b(19);c[0]=0;e=a(e,0,19,19,null,null,g,f,h,c,d);if(e==u)k.msg="oversubscribed dynamic bit lengths tree";else if(e==l||0===f[0])k.msg="incomplete dynamic bit lengths tree", +e=u;return e};this.inflate_trees_dynamic=function(e,f,g,k,j,P,w,E,m){b(288);c[0]=0;P=a(g,0,e,257,ma,na,P,k,E,c,d);if(P!=h||0===k[0]){if(P==u)m.msg="oversubscribed literal/length tree";else if(P!=C)m.msg="incomplete literal/length tree",P=u;return P}b(288);P=a(g,e,f,0,ga,la,w,j,E,c,d);if(P!=h||0===j[0]&&257r;)aa--,q|=(x.read_byte(T++)&255)<>=D[N+1],r-=D[N+1],s.window[O++]=D[N+2],Q--;else{do{q>>=D[N+1];r-=D[N+1];if(0!==(o&16)){o&=15;R=D[N+2]+(q&p[o]);q>>=o;for(r-=o;15>r;)aa--,q|=(x.read_byte(T++)&255)<>=D[N+1],r-=D[N+1],0!==(o&16)){for(o&=15;r>=o;r-=o;Q-=R;if(O>=K)K=O-K,0O-K?(s.window[O++]=s.window[K++],s.window[O++]=s.window[K++]):(s.window.set(s.window.subarray(K,K+2),O),O+=2,K+=2),R-=2;else{K=O-K;do K+=s.end;while(0>K);o=s.end-K;if(R>o){R-=o;if(0O-K){do s.window[O++]=s.window[K++];while(0!==--o)}else s.window.set(s.window.subarray(K,K+o),O),O+=o;K=0}}if(0O-K){do s.window[O++]=s.window[K++];while(0!==--R)}else s.window.set(s.window.subarray(K,K+R),O),O+=R;break}else if(0===(o& +64))K+=D[N+2],K+=q&p[o],N=3*(ia+K),o=D[N];else{x.msg="invalid distance code";R=x.avail_in-aa;R=r>>3>3:R;aa+=R;T-=R;r-=R<<3;s.bitb=q;s.bitk=r;x.avail_in=aa;x.total_in+=T-x.next_in_index;x.next_in_index=T;s.write=O;V=u;break a}while(1);break}if(0===(o&64)){if(K+=D[N+2],K+=q&p[o],N=3*(ia+K),0===(o=D[N])){q>>=D[N+1];r-=D[N+1];s.window[O++]=D[N+2];Q--;break}}else{if(0!==(o&32)){R=x.avail_in-aa;R=r>>3>3:R;aa+=R;T-=R;r-=R<<3;s.bitb=q;s.bitk=r;x.avail_in=aa;x.total_in+=T-x.next_in_index;x.next_in_index= +T;s.write=O;V=k;break a}x.msg="invalid literal/length code";R=x.avail_in-aa;R=r>>3>3:R;aa+=R;T-=R;r-=R<<3;s.bitb=q;s.bitk=r;x.avail_in=aa;x.total_in+=T-x.next_in_index;x.next_in_index=T;s.write=O;V=u;break a}}while(1)}}while(258<=Q&&10<=aa);R=x.avail_in-aa;R=r>>3>3:R;aa+=R;T-=R;r-=R<<3;s.bitb=q;s.bitk=r;x.avail_in=aa;x.total_in+=T-x.next_in_index;x.next_in_index=T;s.write=O;V=h}v=y.next_in_index;s=y.avail_in;U=w.bitb;B=w.bitk;x=w.write;o=x>>=c[q+1];B-=c[q+1];r=c[q];if(0===r){f=c[q+2];a=P;break}if(0!==(r&16)){g=r&15;b=c[q+2];a=pa;break}if(0===(r&64)){e=r;d=q/3+c[q+2];break}if(0!==(r&32)){a=E;break}a=Z;y.msg="invalid literal/length code";V=u;w.bitb=U;w.bitk=B;y.avail_in=s;y.total_in+=v-y.next_in_index;y.next_in_index= +v;w.write=x;return w.inflate_flush(y,V);case pa:for(q=g;B>=q;B-=q;e=A;c=z;d=C;a=ea;case ea:for(q=e;B>=c[q+1];B-=c[q+ +1];r=c[q];if(0!==(r&16)){g=r&15;j=c[q+2];a=fa;break}if(0===(r&64)){e=r;d=q/3+c[q+2];break}a=Z;y.msg="invalid distance code";V=u;w.bitb=U;w.bitk=B;y.avail_in=s;y.total_in+=v-y.next_in_index;y.next_in_index=v;w.write=x;return w.inflate_flush(y,V);case fa:for(q=g;B>=q;B-=q;a=da;case da:for(q=x-j;0>q;)q+=w.end;for(;0!== +b;){if(0===o&&(x==w.end&&0!==w.read&&(x=0,o=xa.avail_out)c=a.avail_out;0!==c&&b==l&&(b=h);a.avail_out-=c;a.total_out+=c;a.next_out.set(e.window.subarray(f,f+c),d);d+=c;f+=c;if(f==e.end){f=0;if(e.write==e.end)e.write=0;c=e.write-f;if(c>a.avail_out)c=a.avail_out;0!==c&&b==l&&(b=h);a.avail_out-= +c;a.total_out+=c;a.next_out.set(e.window.subarray(f,f+c),d);d+=c;f+=c}a.next_out_index=d;e.read=f;return b};e.proc=function(a,c){var d,q,r,l,B,v,s;l=a.next_in_index;B=a.avail_in;q=e.bitb;r=e.bitk;v=e.write;for(s=vr;){if(0!==B)c=h;else return e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);B--;q|=(a.read_byte(l++)&255)<>>1){case 0:q>>>=3;r-=3;d=r&7;q>>>=d; +r-=d;f=ia;break;case 1:d=[];var x=[],W=[[]],D=[[]];b.inflate_trees_fixed(d,x,W,D,a);o.init(d[0],x[0],W[0],0,D[0],0,a);q>>>=3;r-=3;f=sa;break;case 2:q>>>=3;r-=3;f=T;break;case 3:return q>>>=3,r-=3,f=ra,a.msg="invalid block type",c=u,e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c)}break;case ia:for(;32>r;){if(0!==B)c=h;else return e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c); +B--;q|=(a.read_byte(l++)&255)<>>16&65535)!=(q&65535))return f=ra,a.msg="invalid stored block lengths",c=u,e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);g=q&65535;q=r=0;f=0!==g?aa:0!==Z?A:K;break;case aa:if(0===B||0===s&&(v==e.end&&0!==e.read&&(v=0,s=vB&&(d=B);d>s&&(d=s);e.window.set(a.read_buf(l,d),v);l+=d;B-=d;v+=d;s-=d;if(0!==(g-=d))break;f=0!==Z?A:K;break;case T:for(;14>r;){if(0!==B)c=h;else return e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);B--;q|=(a.read_byte(l++)&255)<>5&31))return f=ra,a.msg="too many length or distance symbols", +c=u,e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);d=258+(d&31)+(d>>5&31);if(!E||E.length>>=14;r-=14;P=0;f=ha;case ha:for(;P<4+(j>>>10);){for(;3>r;){if(0!==B)c=h;else return e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);B--;q|=(a.read_byte(l++)&255)<>>=3;r-=3}for(;19>P;)E[ca[P++]]=0;M[0]=7;d=C.inflate_trees_bits(E, +M,t,z,a);if(d!=h)return c=d,c==u&&(E=null,f=ra),e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);P=0;f=O;case O:for(;;){d=j;if(!(P<258+(d&31)+(d>>5&31)))break;for(d=M[0];rW)q>>>=d,r-=d,E[P++]=W;else{s=18==W? +7:W-14;for(x=18==W?11:3;r>>=d;r-=d;x+=q&p[s];q>>>=s;r-=s;s=P;d=j;if(s+x>258+(d&31)+(d>>5&31)||16==W&&1>s)return E=null,f=ra,a.msg="invalid bit length repeat",c=u,e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);W=16==W?E[s-1]:0;do E[s++]=W;while(0!==--x);P=s}}t[0]= +-1;s=[];x=[];W=[];D=[];s[0]=9;x[0]=6;d=j;d=C.inflate_trees_dynamic(257+(d&31),1+(d>>5&31),E,s,x,W,D,z,a);if(d!=h)return d==u&&(E=null,f=ra),c=d,e.bitb=q,e.bitk=r,a.avail_in=B,a.total_in+=l-a.next_in_index,a.next_in_index=l,e.write=v,e.inflate_flush(a,c);o.init(s[0],x[0],z,W[0],z,D[0],a);f=sa;case sa:e.bitb=q;e.bitk=r;a.avail_in=B;a.total_in+=l-a.next_in_index;a.next_in_index=l;e.write=v;if((c=o.proc(e,a,c))!=k)return e.inflate_flush(a,c);c=h;o.free(a);l=a.next_in_index;B=a.avail_in;q=e.bitb;r=e.bitk; +v=e.write;s=ve||15>4)+8>a.istate.wbits){a.istate.mode=oa;a.msg="invalid window size";a.istate.marker=5;break}a.istate.mode=ka;case ka:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;d=a.read_byte(a.next_in_index++)&255;if(0!==((a.istate.method<<8)+d)%31){a.istate.mode=oa;a.msg="incorrect header check";a.istate.marker=5;break}if(0===(d&ja)){a.istate.mode=qa;break}a.istate.mode=wa;case wa:if(0===a.avail_in)return c;c=b;a.avail_in--; +a.total_in++;a.istate.need=(a.read_byte(a.next_in_index++)&255)<<24&4278190080;a.istate.mode=xa;case xa:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.read_byte(a.next_in_index++)&255)<<16&16711680;a.istate.mode=ya;case ya:if(0===a.avail_in)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.read_byte(a.next_in_index++)&255)<<8&65280;a.istate.mode=za;case za:if(0===a.avail_in)return c;a.avail_in--;a.total_in++;a.istate.need+=a.read_byte(a.next_in_index++)&255;a.istate.mode= +ta;return j;case ta:return a.istate.mode=oa,a.msg="need dictionary",a.istate.marker=0,m;case qa:c=a.istate.blocks.proc(a,c);if(c==u){a.istate.mode=oa;a.istate.marker=0;break}c==h&&(c=b);if(c!=k)return c;a.istate.blocks.reset(a,a.istate.was);a.istate.mode=Aa;case Aa:return k;case oa:return u;default:return m}};b.inflateSetDictionary=function(a,b,c){var d=0,e=c;if(!a||!a.istate||a.istate.mode!=ta)return m;e>=1<e;)b.read_byte(d)==t[e]?e++:e=0!==b.read_byte(d)?0:4-e,d++,c--;b.total_in+=d-b.next_in_index;b.next_in_index=d;b.avail_in=c;b.istate.marker=e;if(4!=e)return u;c=b.total_in;d=b.total_out;a(b);b.total_in=c;b.total_out=d;b.istate.mode=qa;return h};b.inflateSyncPoint=function(a){return!a||!a.istate|| +!a.istate.blocks?m:a.istate.blocks.sync_point()}}function f(){}function g(){var a=new f,b=Q,c=new Uint8Array(512),d=!1;a.inflateInit();a.next_out=c;this.append=function(e,f){var g,j=[],P=0,E=0,m=0,M;if(0!==e.length){a.next_in_index=0;a.next_in=e;a.avail_in=e.length;do{a.next_out_index=0;a.avail_out=512;if(0===a.avail_in&&!d)a.next_in_index=0,d=!0;g=a.inflate(b);if(d&&g==l)return-1;if(g!=h&&g!=k)throw"inflating: "+a.msg;if((d||g==k)&&a.avail_out==e.length)return-1;a.next_out_index&&(512==a.next_out_index? +j.push(new Uint8Array(c)):j.push(new Uint8Array(c.subarray(0,a.next_out_index))));m+=a.next_out_index;if(f&&0=this.t)b.t=0;else{var d=a%this.DB,e=this.DB-d,f=(1<>d;for(var g=c+1;g>d;0>=this.DB;if(a.t>=this.DB;d+=this.s}else{for(d+=this.s;c>=this.DB;d-=a.s}b.s=0>d?-1:0;-1>d?b[c++]=this.DV+d:0=b.DV)a[c+b.t]-=b.DV,a[c+b.t+1]=1}0=d.t)){var e=this.abs();if(e.t>this.F2:0),j=this.FV/k,k=(1<g&&BigInteger.ZERO.subTo(c,c)}}}}function bnMod(a){var b=nbi();this.abs().divRemTo(a,null,b);0>this.s&&0=d.t)){var e=this.abs();if(e.t>this.F2:0),j=this.FV/k,k=(1<g&&BigInteger.ZERO.subTo(c,c)}}}}function bnMod(a){var b=nbi();this.abs().divRemTo(a,null,b);0>this.s&&0a.s||0<=a.compareTo(this.m)?a.mod(this.m):a}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo; function bnpInvDigit(){if(1>this.t)return 0;var a=this[0];if(0==(a&1))return 0;var b=a&3,b=b*(2-(a&15)*b)&15,b=b*(2-(a&255)*b)&255,b=b*(2-((a&65535)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV;return 0>15;this.um=(1<a.s&&0a.s||a.t>2*this.m.t)return a.mod(this.m);if(0>a.compareTo(this.m))return a;var b=nbi();a.copyTo(b);this.reduce(b);return b}function barrettRevert(a){return a} function barrettReduce(a){a.drShiftTo(this.m.t-1,this.r2);if(a.t>this.m.t+1)a.t=this.m.t+1,a.clamp();this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);for(this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);0>a.compareTo(this.r2);)a.dAddOffset(1,this.m.t+1);for(a.subTo(this.r2,a);0<=a.compareTo(this.m);)a.subTo(this.m,a)}function barrettSqrTo(a,b){a.squareTo(b);this.reduce(b)}function barrettMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}Barrett.prototype.convert=barrettConvert; Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo; -function bnModPow(a,b){var c=a.bitLength(),d,e=nbv(1),f;if(0>=c)return e;d=18>c?1:48>c?3:144>c?4:768>c?5:6;f=8>c?new Classic(b):b.isEven()?new Barrett(b):new Montgomery(b);var g=[],h=3,k=d-1,j=(1<=k?w=a[l]>>c-k&j:(w=(a[l]&(1<>this.DB+c-k));for(h=d;0==(w&1);)w>>=1,--h;if(0>(c-=h))c+=this.DB,--l;if(C)g[w].copyTo(e), -C=!1;else{for(;1--c&&(c=this.DB-1,--l)}return f.revert(e)} +function bnModPow(a,b){var c=a.bitLength(),d,e=nbv(1),f;if(0>=c)return e;d=18>c?1:48>c?3:144>c?4:768>c?5:6;f=8>c?new Classic(b):b.isEven()?new Barrett(b):new Montgomery(b);var g=[],h=3,k=d-1,j=(1<=k?u=a[m]>>c-k&j:(u=(a[m]&(1<>this.DB+c-k));for(h=d;0==(u&1);)u>>=1,--h;if(0>(c-=h))c+=this.DB,--m;if(C)g[u].copyTo(e), +C=!1;else{for(;1--c&&(c=this.DB-1,--m)}return f.revert(e)} function bnGCD(a){var b=0>this.s?this.negate():this.clone(),a=0>a.s?a.negate():a.clone();if(0>b.compareTo(a))var c=b,b=a,a=c;var c=b.getLowestSetBit(),d=a.getLowestSetBit();if(0>d)return b;c=a)return 0;var b=this.DV%a,c=0>this.s?a-1:0;if(0>>4^m)&252645135;m^=f;D^=f<<4;f=(D>>>16^m)&65535;m^=f;D^=f<<16;f=(m>>>2^D)&858993459;D^=f;m^=f<<2;f=(m>>>8^D)&16711935;D^=f;m^=f<<8;f=(D>>>1^m)&1431655765;m^=f;D^=f<<1;D=D<<1|D>>>31;m=m<<1|m>>>31;for(ba=0;ba>>4|m<<28)^a[e+1],f=D,D=m,m=f^(h[fa>>>24&63]|j[fa>>> -16&63]|w[fa>>>8&63]|v[fa&63]|g[E>>>24&63]|k[E>>>16&63]|l[E>>>8&63]|C[E&63]);f=D;D=m;m=f}D=D>>>1|D<<31;m=m>>>1|m<<31;f=(D>>>1^m)&1431655765;m^=f;D^=f<<1;f=(m>>>8^D)&16711935;D^=f;m^=f<<8;f=(m>>>2^D)&858993459;D^=f;m^=f<<2;f=(D>>>16^m)&65535;m^=f;D^=f<<16;f=(D>>>4^m)&252645135;m^=f;D^=f<<4;1==d&&(c?(la=D,ja=m):(D^=ia,m^=W));tempresult+=String.fromCharCode(D>>>24,D>>>16&255,D>>>8&255,D&255,m>>>24,m>>>16&255,m>>>8&255,m&255);ea+=8;512==ea&&(result+=tempresult,tempresult="",ea=0)}result+=tempresult;return result= +69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],l=[268439616,4096,262144,268701760,268435456, +268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696],p=0,Y,Q,D,o,z,ma,na,ga,la,N,L,ba,pa=b.length,ea=0, +fa=32==a.length?3:9;ma=3==fa?c?[0,32,2]:[30,-2,-2]:c?[0,32,2,62,30,-2,64,96,2]:[94,62,-2,32,64,2,30,-2,-2];2==f?b+=" ":1==f?(f=8-pa%8,b+=String.fromCharCode(f,f,f,f,f,f,f,f),8==f&&(pa+=8)):f||(b+="\x00\x00\x00\x00\x00\x00\x00\x00");tempresult=result="";1==d&&(na=e.charCodeAt(p++)<<24|e.charCodeAt(p++)<<16|e.charCodeAt(p++)<<8|e.charCodeAt(p++),la=e.charCodeAt(p++)<<24|e.charCodeAt(p++)<<16|e.charCodeAt(p++)<<8|e.charCodeAt(p++),p=0);for(;p>>4^z)&252645135;z^=f;o^=f<<4;f=(o>>>16^z)&65535;z^=f;o^=f<<16;f=(z>>>2^o)&858993459;o^=f;z^=f<<2;f=(z>>>8^o)&16711935;o^=f;z^=f<<8;f=(o>>>1^z)&1431655765;z^=f;o^=f<<1;o=o<<1|o>>>31;z=z<<1|z>>>31;for(Y=0;Y>>4|z<<28)^a[e+1],f=o,o=z,z=f^(h[Q>>>24&63]|j[Q>>>16& +63]|u[Q>>>8&63]|l[Q&63]|g[D>>>24&63]|k[D>>>16&63]|m[D>>>8&63]|C[D&63]);f=o;o=z;z=f}o=o>>>1|o<<31;z=z>>>1|z<<31;f=(o>>>1^z)&1431655765;z^=f;o^=f<<1;f=(z>>>8^o)&16711935;o^=f;z^=f<<8;f=(z>>>2^o)&858993459;o^=f;z^=f<<2;f=(o>>>16^z)&65535;z^=f;o^=f<<16;f=(o>>>4^z)&252645135;z^=f;o^=f<<4;1==d&&(c?(na=o,la=z):(o^=ga,z^=N));tempresult+=String.fromCharCode(o>>>24,o>>>16&255,o>>>8&255,o&255,z>>>24,z>>>16&255,z>>>8&255,z&255);ea+=8;512==ea&&(result+=tempresult,tempresult="",ea=0)}result+=tempresult;return result= result.replace(/\0*$/g,"")} function des_createKeys(a){pc2bytes0=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964];pc2bytes1=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697];pc2bytes2=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272];pc2bytes3=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952, 139264,2236416,134356992,136454144];pc2bytes4=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256];pc2bytes5=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488];pc2bytes6=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746];pc2bytes7=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032, @@ -284,14 +306,14 @@ right^=k;left^=k<<4;k=(right>>>-16^left)&65535;left^=k;right^=k<<-16;k=(left>>>2 1|left>>>27,right=right<<1|right>>>27),left&=-15,right&=-15,e=pc2bytes0[left>>>28]|pc2bytes1[left>>>24&15]|pc2bytes2[left>>>20&15]|pc2bytes3[left>>>16&15]|pc2bytes4[left>>>12&15]|pc2bytes5[left>>>8&15]|pc2bytes6[left>>>4&15],f=pc2bytes7[right>>>28]|pc2bytes8[right>>>24&15]|pc2bytes9[right>>>20&15]|pc2bytes10[right>>>16&15]|pc2bytes11[right>>>12&15]|pc2bytes12[right>>>8&15]|pc2bytes13[right>>>4&15],k=(f>>>16^e)&65535,c[h++]=e^k,c[h++]=f^k<<16}return c} function cast5_encrypt(a,b){var c=new openpgp_symenc_cast5;c.setKey(util.str2bin(b));return c.encrypt(a)} function openpgp_symenc_cast5(){function a(a,b,c){a=b+a;c=a<>>32-c;return(f[0][c>>>24]^f[1][c>>>16&255])-f[2][c>>>8&255]+f[3][c&255]}function b(a,b,c){a^=b;c=a<>>32-c;return f[0][c>>>24]-f[1][c>>>16&255]+f[2][c>>>8&255]^f[3][c&255]}function c(a,b,c){a=b-a;c=a<>>32-c;return(f[0][c>>>24]+f[1][c>>>16&255]^f[2][c>>>8&255])-f[3][c&255]}this.BlockSize=8;this.KeySize=16;this.setKey=function(a){this.masking=Array(16);this.rotate=Array(16);this.reset();if(a.length==this.KeySize)this.keySchedule(a); -else return util.print_error("cast5.js: CAST-128: keys must be 16 bytes"),!1;return!0};this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0};this.getBlockSize=function(){return BlockSize};this.encrypt=function(d){var e=Array(d.length);for(i=0;i>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>>16&255;e[i+6]=f>>>8&255;e[i+7]=f&255}return e};this.decrypt=function(d){var e=Array(d.length);for(i=0;i>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>16&255;e[i+6]=f>>8&255;e[i+7]=f&255}return e};var d=Array(4);d[0]=Array(4);d[0][0]=[4,0,13,15,12,14,8];d[0][1]=[5,2,16,18,17,19,10];d[0][2]=[6,3,23,22,21,20,9];d[0][3]=[7,1,26,25,27,24,11];d[1]=Array(4);d[1][0]=[0, +else return util.print_error("cast5.js: CAST-128: keys must be 16 bytes"),!1;return!0};this.reset=function(){for(var a=0;16>a;a++)this.masking[a]=0,this.rotate[a]=0};this.getBlockSize=function(){return BlockSize};this.encrypt=function(d){var e=Array(d.length);for(i=0;i>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>>16&255;e[i+6]=f>>>8&255;e[i+7]=f&255}return e};this.decrypt=function(d){var e=Array(d.length);for(i=0;i>>24&255;e[i+1]=j>>>16&255;e[i+2]=j>>>8&255;e[i+3]=j&255;e[i+4]=f>>>24&255;e[i+5]=f>>16&255;e[i+6]=f>>8&255;e[i+7]=f&255}return e};var d=Array(4);d[0]=Array(4);d[0][0]=[4,0,13,15,12,14,8];d[0][1]=[5,2,16,18,17,19,10];d[0][2]=[6,3,23,22,21,20,9];d[0][3]=[7,1,26,25,27,24,11];d[1]=Array(4);d[1][0]=[0, 6,21,23,20,22,16];d[1][1]=[1,4,0,2,1,3,18];d[1][2]=[2,5,7,6,5,4,17];d[1][3]=[3,7,10,9,11,8,19];d[2]=Array(4);d[2][0]=[4,0,13,15,12,14,8];d[2][1]=[5,2,16,18,17,19,10];d[2][2]=[6,3,23,22,21,20,9];d[2][3]=[7,1,26,25,27,24,11];d[3]=Array(4);d[3][0]=[0,6,21,23,20,22,16];d[3][1]=[1,4,0,2,1,3,18];d[3][2]=[2,5,7,6,5,4,17];d[3][3]=[3,7,10,9,11,8,19];var e=Array(4);e[0]=Array(4);e[0][0]=[24,25,23,22,18];e[0][1]=[26,27,21,20,22];e[0][2]=[28,29,19,18,25];e[0][3]=[30,31,17,16,28];e[1]=Array(4);e[1][0]=[3,2,12, -13,8];e[1][1]=[1,0,14,15,13];e[1][2]=[7,6,8,9,3];e[1][3]=[5,4,10,11,7];e[2]=Array(4);e[2][0]=[19,18,28,29,25];e[2][1]=[17,16,30,31,28];e[2][2]=[23,22,24,25,18];e[2][3]=[21,20,26,27,22];e[3]=Array(4);e[3][0]=[8,9,7,6,3];e[3][1]=[10,11,5,4,7];e[3][2]=[12,13,3,2,8];e[3][3]=[14,15,1,0,13];this.keySchedule=function(a){for(var b=Array(8),c=Array(32),j=0;4>j;j++){var l=4*j;b[j]=a[l]<<24|a[l+1]<<16|a[l+2]<<8|a[l+3]}for(var a=[6,7,4,5],w=j=0;2>w;w++)for(var C=0;4>C;C++){for(l=0;4>l;l++){var v=d[C][l],y=b[v[1]], -y=y^f[4][b[v[2]>>>2]>>>24-8*(v[2]&3)&255],y=y^f[5][b[v[3]>>>2]>>>24-8*(v[3]&3)&255],y=y^f[6][b[v[4]>>>2]>>>24-8*(v[4]&3)&255],y=y^f[7][b[v[5]>>>2]>>>24-8*(v[5]&3)&255],y=y^f[a[l]][b[v[6]>>>2]>>>24-8*(v[6]&3)&255];b[v[0]]=y}for(l=0;4>l;l++)v=e[C][l],y=f[4][b[v[0]>>>2]>>>24-8*(v[0]&3)&255],y^=f[5][b[v[1]>>>2]>>>24-8*(v[1]&3)&255],y^=f[6][b[v[2]>>>2]>>>24-8*(v[2]&3)&255],y^=f[7][b[v[3]>>>2]>>>24-8*(v[3]&3)&255],y^=f[4+l][b[v[4]>>>2]>>>24-8*(v[4]&3)&255],c[j]=y,j++}for(j=0;16>j;j++)this.masking[j]=c[j], +13,8];e[1][1]=[1,0,14,15,13];e[1][2]=[7,6,8,9,3];e[1][3]=[5,4,10,11,7];e[2]=Array(4);e[2][0]=[19,18,28,29,25];e[2][1]=[17,16,30,31,28];e[2][2]=[23,22,24,25,18];e[2][3]=[21,20,26,27,22];e[3]=Array(4);e[3][0]=[8,9,7,6,3];e[3][1]=[10,11,5,4,7];e[3][2]=[12,13,3,2,8];e[3][3]=[14,15,1,0,13];this.keySchedule=function(a){for(var b=Array(8),c=Array(32),j=0;4>j;j++){var m=4*j;b[j]=a[m]<<24|a[m+1]<<16|a[m+2]<<8|a[m+3]}for(var a=[6,7,4,5],u=j=0;2>u;u++)for(var C=0;4>C;C++){for(m=0;4>m;m++){var l=d[C][m],p=b[l[1]], +p=p^f[4][b[l[2]>>>2]>>>24-8*(l[2]&3)&255],p=p^f[5][b[l[3]>>>2]>>>24-8*(l[3]&3)&255],p=p^f[6][b[l[4]>>>2]>>>24-8*(l[4]&3)&255],p=p^f[7][b[l[5]>>>2]>>>24-8*(l[5]&3)&255],p=p^f[a[m]][b[l[6]>>>2]>>>24-8*(l[6]&3)&255];b[l[0]]=p}for(m=0;4>m;m++)l=e[C][m],p=f[4][b[l[0]>>>2]>>>24-8*(l[0]&3)&255],p^=f[5][b[l[1]>>>2]>>>24-8*(l[1]&3)&255],p^=f[6][b[l[2]>>>2]>>>24-8*(l[2]&3)&255],p^=f[7][b[l[3]>>>2]>>>24-8*(l[3]&3)&255],p^=f[4+m][b[l[4]>>>2]>>>24-8*(l[4]&3)&255],c[j]=p,j++}for(j=0;16>j;j++)this.masking[j]=c[j], this.rotate[j]=c[16+j]&31};var f=Array(8);f[0]=[821772500,2678128395,1810681135,1059425402,505495343,2617265619,1610868032,3483355465,3218386727,2294005173,3791863952,2563806837,1852023008,365126098,3269944861,584384398,677919599,3229601881,4280515016,2002735330,1136869587,3744433750,2289869850,2731719981,2714362070,879511577,1639411079,575934255,717107937,2857637483,576097850,2731753936,1725645E3,2810460463,5111599,767152862,2543075244,1251459544,1383482551,3052681127,3089939183,3612463449,1878520045, 1510570527,2189125840,2431448366,582008916,3163445557,1265446783,1354458274,3529918736,3202711853,3073581712,3912963487,3029263377,1275016285,4249207360,2905708351,3304509486,1442611557,3585198765,2712415662,2731849581,3248163920,2283946226,208555832,2766454743,1331405426,1447828783,3315356441,3108627284,2957404670,2981538698,3339933917,1669711173,286233437,1465092821,1782121619,3862771680,710211251,980974943,1651941557,430374111,2051154026,704238805,4128970897,3144820574,2857402727,948965521,3333752299, 2227686284,718756367,2269778983,2731643755,718440111,2857816721,3616097120,1113355533,2478022182,410092745,1811985197,1944238868,2696854588,1415722873,1682284203,1060277122,1998114690,1503841958,82706478,2315155686,1068173648,845149890,2167947013,1768146376,1993038550,3566826697,3390574031,940016341,3355073782,2328040721,904371731,1205506512,4094660742,2816623006,825647681,85914773,2857843460,1249926541,1417871568,3287612,3211054559,3126306446,1975924523,1353700161,2814456437,2438597621,1800716203, @@ -337,14 +359,14 @@ f[2]=[2381300288,637164959,3952098751,3893414151,1197506559,916448331,2350892612 4066861423,3242773476,2421326174,1581322155,3028952165,786071460,3900391652,3918438532,1485433313,4023619836,3708277595,3678951060,953673138,1467089153,1930354364,1533292819,2492563023,1346121658,1685000834,1965281866,3765933717,4190206607,2052792609,3515332758,690371149,3125873887,2180283551,2903598061,3933952357,436236910,289419410,14314871,1242357089,2904507907,1616633776,2666382180,585885352,3471299210,2699507360,1432659641,277164553,3354103607,770115018,2303809295,3741942315,3177781868,2853364978, 2269453327,3774259834,987383833,1290892879,225909803,1741533526,890078084,1496906255,1111072499,916028167,243534141,1252605537,2204162171,531204876,290011180,3916834213,102027703,237315147,209093447,1486785922,220223953,2758195998,4175039106,82940208,3127791296,2569425252,518464269,1353887104,3941492737,2377294467,3935040926]}function TFencrypt(a,b){var c=[].concat(a),d=createTwofish();d.open(util.str2bin(b),0);c=d.encrypt(c,0);d.close();return c}var MAXINT=4294967295; function rotb(a,b){return(a<>>8-b)&255}function rotw(a,b){return(a<>>32-b)&MAXINT}function getW(a,b){return a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24}function setW(a,b,c){a.splice(b,4,c&255,c>>>8&255,c>>>16&255,c>>>24&255)}function setWInv(a,b,c){a.splice(b,4,c>>>24&255,c>>>16&255,c>>>8&255,c&255)}function getB(a,b){return a>>>8*b&255}function getNrBits(a){for(var b=0;0>>=1;return b}function getMask(a){return(1<d;d++)e=c>>>24,c=c<<8&MAXINT|a>>>24,a=a<<8&MAXINT,f=e<<1,e&128&&(f^=333),c^=e^f<<16,f^=e>>>1,e&1&&(f^=166),c^=f<<24|f<<8;return c}function d(a,b){var c,e,f;c=b>>4;e=b&15;f=m[a][c^ -e];c=ma[a][ja[e]^W[c]];return ia[a][ja[c]^W[f]]<<4|la[a][f^c]}function e(a,b){var c=getB(a,0),d=getB(a,1),f=getB(a,2),g=getB(a,3);switch(fa){case 4:c=L[1][c]^getB(b[3],0),d=L[0][d]^getB(b[3],1),f=L[0][f]^getB(b[3],2),g=L[1][g]^getB(b[3],3);case 3:c=L[1][c]^getB(b[2],0),d=L[1][d]^getB(b[2],1),f=L[0][f]^getB(b[2],2),g=L[0][g]^getB(b[2],3);case 2:c=L[0][L[0][c]^getB(b[1],0)]^getB(b[0],0),d=L[0][L[1][d]^getB(b[1],1)]^getB(b[0],1),f=L[1][L[0][f]^getB(b[1],2)]^getB(b[0],2),g=L[1][L[1][g]^getB(b[1],3)]^ -getB(b[0],3)}return Z[0][c]^Z[1][d]^Z[2][f]^Z[3][g]}c=a;var w,C,v,y;v=[];y=[];var ba=[],fa,E=[],D,m=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],ma=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],la=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],ia=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],ja=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],W=[0,9,2,11,4,13,6,15, -8,1,10,3,12,5,14,7],L=[[],[]],Z=[[],[],[],[]];c=c.slice(0,32);for(a=c.length;16!=a&&24!=a&&32!=a;)c[a++]=0;for(a=0;a>2]=getW(c,a);for(a=0;256>a;a++)L[0][a]=d(0,a),L[1][a]=d(1,a);for(a=0;256>a;a++)w=L[1][a],C=w^w>>2^[0,90,180,238][w&3],D=w^w>>1^w>>2^[0,238,180,90][w&3],Z[0][a]=w+(C<<8)+(D<<16)+(D<<24),Z[2][a]=C+(D<<8)+(w<<16)+(D<<24),w=L[0][a],C=w^w>>2^[0,90,180,238][w&3],D=w^w>>1^w>>2^[0,238,180,90][w&3],Z[1][a]=D+(D<<8)+(C<<16)+(w<<24),Z[3][a]=C+(w<<8)+(D<<16)+(C<<24);fa=ba.length/ -2;for(a=0;aa;a+=2)w=16843009*a,C=w+16843009,w=e(w,v),C=rotw(e(C,y),8),f[a]=w+C&MAXINT,f[a+1]=rotw(w+2*C,9);for(a=0;256>a;a++)switch(w=C=v=y=a,fa){case 4:w=L[1][w]^getB(E[3],0),C=L[0][C]^getB(E[3],1),v=L[0][v]^getB(E[3],2),y=L[1][y]^getB(E[3],3);case 3:w=L[1][w]^getB(E[2],0),C=L[1][C]^getB(E[2],1),v=L[0][v]^getB(E[2],2),y=L[0][y]^getB(E[2],3);case 2:g[0][a]=Z[0][L[0][L[0][w]^getB(E[1],0)]^getB(E[0],0)],g[1][a]=Z[1][L[0][L[1][C]^ -getB(E[1],1)]^getB(E[0],1)],g[2][a]=Z[2][L[1][L[0][v]^getB(E[1],2)]^getB(E[0],2)],g[3][a]=Z[3][L[1][L[1][y]^getB(E[1],3)]^getB(E[0],3)]}},close:function(){f=[];g=[[],[],[],[]]},encrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[0],getW(d,e+4)^f[1],getW(d,e+8)^f[2],getW(d,e+12)^f[3]],l=0;8>l;l++){var w=l,C=j,v=a(C[0]),y=b(C[1]);C[2]=rotw(C[2]^v+y+f[4*w+8]&MAXINT,31);C[3]=rotw(C[3],1)^v+2*y+f[4*w+9]&MAXINT;v=a(C[2]);y=b(C[3]);C[0]=rotw(C[0]^v+y+f[4*w+10]&MAXINT,31);C[1]=rotw(C[1],1)^v+2*y+f[4*w+11]& -MAXINT}setW(d,e,j[2]^f[4]);setW(d,e+4,j[3]^f[5]);setW(d,e+8,j[0]^f[6]);setW(d,e+12,j[1]^f[7]);e+=16;return d},decrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[4],getW(d,e+4)^f[5],getW(d,e+8)^f[6],getW(d,e+12)^f[7]],l=7;0<=l;l--){var w=l,C=j,v=a(C[0]),y=b(C[1]);C[2]=rotw(C[2],1)^v+y+f[4*w+10]&MAXINT;C[3]=rotw(C[3]^v+2*y+f[4*w+11]&MAXINT,31);v=a(C[2]);y=b(C[3]);C[0]=rotw(C[0],1)^v+y+f[4*w+8]&MAXINT;C[1]=rotw(C[1]^v+2*y+f[4*w+9]&MAXINT,31)}setW(d,e,j[2]^f[0]);setW(d,e+4,j[3]^f[1]);setW(d,e+8,j[0]^ -f[2]);setW(d,e+12,j[1]^f[3]);e+=16},finalize:function(){return d}}}function Blowfish(){}Blowfish.prototype.BLOCKSIZE=8; +function createTwofish(){function a(a){return g[0][getB(a,0)]^g[1][getB(a,1)]^g[2][getB(a,2)]^g[3][getB(a,3)]}function b(a){return g[0][getB(a,3)]^g[1][getB(a,0)]^g[2][getB(a,1)]^g[3][getB(a,2)]}var c=null,d=null,e=-1,f=[],g=[[],[],[],[]];return{name:"twofish",blocksize:16,open:function(a){function b(a,c){var d,e,f;for(d=0;8>d;d++)e=c>>>24,c=c<<8&MAXINT|a>>>24,a=a<<8&MAXINT,f=e<<1,e&128&&(f^=333),c^=e^f<<16,f^=e>>>1,e&1&&(f^=166),c^=f<<24|f<<8;return c}function d(a,b){var c,e,f;c=b>>4;e=b&15;f=z[a][c^ +e];c=ma[a][la[e]^N[c]];return ga[a][la[c]^N[f]]<<4|na[a][f^c]}function e(a,b){var c=getB(a,0),d=getB(a,1),f=getB(a,2),g=getB(a,3);switch(Q){case 4:c=L[1][c]^getB(b[3],0),d=L[0][d]^getB(b[3],1),f=L[0][f]^getB(b[3],2),g=L[1][g]^getB(b[3],3);case 3:c=L[1][c]^getB(b[2],0),d=L[1][d]^getB(b[2],1),f=L[0][f]^getB(b[2],2),g=L[0][g]^getB(b[2],3);case 2:c=L[0][L[0][c]^getB(b[1],0)]^getB(b[0],0),d=L[0][L[1][d]^getB(b[1],1)]^getB(b[0],1),f=L[1][L[0][f]^getB(b[1],2)]^getB(b[0],2),g=L[1][L[1][g]^getB(b[1],3)]^getB(b[0], +3)}return ba[0][c]^ba[1][d]^ba[2][f]^ba[3][g]}c=a;var u,C,l,p;l=[];p=[];var Y=[],Q,D=[],o,z=[[8,1,7,13,6,15,3,2,0,11,5,9,14,12,10,4],[2,8,11,13,15,7,6,14,3,1,9,4,0,10,12,5]],ma=[[14,12,11,8,1,2,3,5,15,4,10,6,7,0,9,13],[1,14,2,11,4,12,3,7,6,13,10,5,15,9,0,8]],na=[[11,10,5,14,6,13,9,0,12,8,15,3,2,4,7,1],[4,12,7,5,1,6,9,10,0,14,13,8,2,11,3,15]],ga=[[13,7,15,4,1,2,6,14,9,11,3,0,8,5,12,10],[11,9,5,1,12,3,13,14,6,4,7,15,2,0,8,10]],la=[0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15],N=[0,9,2,11,4,13,6,15,8,1,10, +3,12,5,14,7],L=[[],[]],ba=[[],[],[],[]];c=c.slice(0,32);for(a=c.length;16!=a&&24!=a&&32!=a;)c[a++]=0;for(a=0;a>2]=getW(c,a);for(a=0;256>a;a++)L[0][a]=d(0,a),L[1][a]=d(1,a);for(a=0;256>a;a++)u=L[1][a],C=u^u>>2^[0,90,180,238][u&3],o=u^u>>1^u>>2^[0,238,180,90][u&3],ba[0][a]=u+(C<<8)+(o<<16)+(o<<24),ba[2][a]=C+(o<<8)+(u<<16)+(o<<24),u=L[0][a],C=u^u>>2^[0,90,180,238][u&3],o=u^u>>1^u>>2^[0,238,180,90][u&3],ba[1][a]=o+(o<<8)+(C<<16)+(u<<24),ba[3][a]=C+(u<<8)+(o<<16)+(C<<24);Q=Y.length/ +2;for(a=0;aa;a+=2)u=16843009*a,C=u+16843009,u=e(u,l),C=rotw(e(C,p),8),f[a]=u+C&MAXINT,f[a+1]=rotw(u+2*C,9);for(a=0;256>a;a++)switch(u=C=l=p=a,Q){case 4:u=L[1][u]^getB(D[3],0),C=L[0][C]^getB(D[3],1),l=L[0][l]^getB(D[3],2),p=L[1][p]^getB(D[3],3);case 3:u=L[1][u]^getB(D[2],0),C=L[1][C]^getB(D[2],1),l=L[0][l]^getB(D[2],2),p=L[0][p]^getB(D[2],3);case 2:g[0][a]=ba[0][L[0][L[0][u]^getB(D[1],0)]^getB(D[0],0)],g[1][a]=ba[1][L[0][L[1][C]^getB(D[1], +1)]^getB(D[0],1)],g[2][a]=ba[2][L[1][L[0][l]^getB(D[1],2)]^getB(D[0],2)],g[3][a]=ba[3][L[1][L[1][p]^getB(D[1],3)]^getB(D[0],3)]}},close:function(){f=[];g=[[],[],[],[]]},encrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[0],getW(d,e+4)^f[1],getW(d,e+8)^f[2],getW(d,e+12)^f[3]],m=0;8>m;m++){var u=m,C=j,l=a(C[0]),p=b(C[1]);C[2]=rotw(C[2]^l+p+f[4*u+8]&MAXINT,31);C[3]=rotw(C[3],1)^l+2*p+f[4*u+9]&MAXINT;l=a(C[2]);p=b(C[3]);C[0]=rotw(C[0]^l+p+f[4*u+10]&MAXINT,31);C[1]=rotw(C[1],1)^l+2*p+f[4*u+11]&MAXINT}setW(d, +e,j[2]^f[4]);setW(d,e+4,j[3]^f[5]);setW(d,e+8,j[0]^f[6]);setW(d,e+12,j[1]^f[7]);e+=16;return d},decrypt:function(c,g){d=c;e=g;for(var j=[getW(d,e)^f[4],getW(d,e+4)^f[5],getW(d,e+8)^f[6],getW(d,e+12)^f[7]],m=7;0<=m;m--){var u=m,C=j,l=a(C[0]),p=b(C[1]);C[2]=rotw(C[2],1)^l+p+f[4*u+10]&MAXINT;C[3]=rotw(C[3]^l+2*p+f[4*u+11]&MAXINT,31);l=a(C[2]);p=b(C[3]);C[0]=rotw(C[0],1)^l+p+f[4*u+8]&MAXINT;C[1]=rotw(C[1]^l+2*p+f[4*u+9]&MAXINT,31)}setW(d,e,j[2]^f[0]);setW(d,e+4,j[3]^f[1]);setW(d,e+8,j[0]^f[2]);setW(d, +e+12,j[1]^f[3]);e+=16},finalize:function(){return d}}}function Blowfish(){}Blowfish.prototype.BLOCKSIZE=8; Blowfish.prototype.SBOXES=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110, 2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150, 2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882, @@ -399,7 +421,7 @@ var Rcon=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53, function B3(a){return a>>24&255}function F1(a,b,c,d){return B1(T1[a&255])|B1(T1[b>>8&255])<<8|B1(T1[c>>16&255])<<16|B1(T1[d>>>24])<<24}function packBytes(a){var b,c,d=a.length,e=Array(d/4);if(a&&!(d%4)){for(b=0,c=0;cc;d++,c++)f[a][c]=k[d];4==c&&(a++,c=0)}for(;ac;d++,c++)f[a][c]=k[d];4==c&&(a++,c=0)}}this.rounds=e;this.rk=f;return this} -function AESencrypt(a,b){var c,d,e,f,g,h=packBytes(a),k=b.rounds,j=h[0],l=h[1],w=h[2];g=h[3];for(c=0;c>8&255]^T3[f>>16&255]^T4[g>>>24],l=T1[e&255]^T2[f>>8&255]^T3[g>>16&255]^T4[d>>>24],w=T1[f&255]^T2[g>>8&255]^T3[d>>16&255]^T4[e>>>24],g=T1[g&255]^T2[d>>8&255]^T3[e>>16&255]^T4[f>>>24];c=k-1;d=j^b.rk[c][0];e=l^b.rk[c][1];f=w^b.rk[c][2];g^=b.rk[c][3];h[0]=F1(d,e,f,g)^b.rk[k][0];h[1]=F1(e,f,g,d)^b.rk[k][1];h[2]=F1(f, +function AESencrypt(a,b){var c,d,e,f,g,h=packBytes(a),k=b.rounds,j=h[0],m=h[1],u=h[2];g=h[3];for(c=0;c>8&255]^T3[f>>16&255]^T4[g>>>24],m=T1[e&255]^T2[f>>8&255]^T3[g>>16&255]^T4[d>>>24],u=T1[f&255]^T2[g>>8&255]^T3[d>>16&255]^T4[e>>>24],g=T1[g&255]^T2[d>>8&255]^T3[e>>16&255]^T4[f>>>24];c=k-1;d=j^b.rk[c][0];e=m^b.rk[c][1];f=u^b.rk[c][2];g^=b.rk[c][3];h[0]=F1(d,e,f,g)^b.rk[k][0];h[1]=F1(e,f,g,d)^b.rk[k][1];h[2]=F1(f, g,d,e)^b.rk[k][2];h[3]=F1(g,d,e,f)^b.rk[k][3];return unpackBytes(h)} function openpgp_cfb_encrypt(a,b,c,d,e,f){var g=Array(d),h=Array(d),a=a+a.charAt(d-2)+a.charAt(d-1);util.print_debug("prefixrandom:"+util.hexstrdump(a));for(var k="",j=0;jb*g;){for(var k=a(f,c),f=d.substring(g*b+0,g*b+b+0),e=0;e>5]|=(a.charCodeAt(d/8)&255)<<24-d%32;return b},c=function(a){var b=[],c=a.length,d,e;for(d=0;d>3]|=e<<24-4*(d%8)}return b},d=function(a){var b="",c=4*a.length,d,e;for(d=0;d>2]>>8*(3-d%4),b+="0123456789abcdef".charAt(e>>4&15)+"0123456789abcdef".charAt(e&15);return b},e=function(a){var b= "",c=4*a.length,d,e,f;for(d=0;d>2]>>8*(3-d%4)&255)<<16|(a[d+1>>2]>>8*(3-(d+1)%4)&255)<<8|a[d+2>>2]>>8*(3-(d+2)%4)&255;for(e=0;4>e;e+=1)b=8*d+6*e<=32*a.length?b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(f>>6*(3-e)&63):b+""}return b},f=function(a){for(var b="",c=0;c<32*a.length;c+=8)b+=String.fromCharCode(a[c>>5]>>>24-c%32&255);return b},g=function(a,b){return a<>>32-b},h=function(a,b){return a>>>b|a<<32-b},k=function(b,c){return 32>=c?new a(b.highOrder>>> -c|b.lowOrder<<32-c,b.lowOrder>>>c|b.highOrder<<32-c):new a(b.lowOrder>>>c|b.highOrder<<32-c,b.highOrder>>>c|b.lowOrder<<32-c)},j=function(b,c){return 32>=c?new a(b.highOrder>>>c,b.lowOrder>>>c|b.highOrder<<32-c):new a(0,b.highOrder<<32-c)},l=function(a,b,c){return a&b^~a&c},w=function(b,c,d){return new a(b.highOrder&c.highOrder^~b.highOrder&d.highOrder,b.lowOrder&c.lowOrder^~b.lowOrder&d.lowOrder)},C=function(a,b,c){return a&b^a&c^b&c},v=function(b,c,d){return new a(b.highOrder&c.highOrder^b.highOrder& -d.highOrder^c.highOrder&d.highOrder,b.lowOrder&c.lowOrder^b.lowOrder&d.lowOrder^c.lowOrder&d.lowOrder)},y=function(a){return h(a,2)^h(a,13)^h(a,22)},ba=function(b){var c=k(b,28),d=k(b,34),b=k(b,39);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},fa=function(a){return h(a,6)^h(a,11)^h(a,25)},E=function(b){var c=k(b,14),d=k(b,18),b=k(b,41);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},D=function(a){return h(a,7)^h(a,18)^a>>>3}, -m=function(b){var c=k(b,1),d=k(b,8),b=j(b,7);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},ma=function(a){return h(a,17)^h(a,19)^a>>>10},la=function(b){var c=k(b,19),d=k(b,61),b=j(b,6);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},ia=function(a,b){var c=(a&65535)+(b&65535);return((a>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535},ja=function(a,b,c,d){var e=(a&65535)+(b&65535)+(c&65535)+(d&65535);return((a>>>16)+(b>>>16)+(c>>> -16)+(d>>>16)+(e>>>16)&65535)<<16|e&65535},W=function(a,b,c,d,e){var f=(a&65535)+(b&65535)+(c&65535)+(d&65535)+(e&65535);return((a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16)&65535)<<16|f&65535},L=function(b,c){var d,e,f;d=(b.lowOrder&65535)+(c.lowOrder&65535);e=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d>>>16);f=(e&65535)<<16|d&65535;d=(b.highOrder&65535)+(c.highOrder&65535)+(e>>>16);e=(b.highOrder>>>16)+(c.highOrder>>>16)+(d>>>16);return new a((e&65535)<<16|d&65535,f)},Z=function(b,c,d,e){var f, -g,h;f=(b.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&65535);g=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);h=(g&65535)<<16|f&65535;f=(b.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(g>>>16);g=(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);return new a((g&65535)<<16|f&65535,h)},oa=function(b,c,d,e,f){var g,h,j;g=(b.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder& -65535)+(f.lowOrder&65535);h=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f.lowOrder>>>16)+(g>>>16);j=(h&65535)<<16|g&65535;g=(b.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(f.highOrder&65535)+(h>>>16);h=(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f.highOrder>>>16)+(g>>>16);return new a((h&65535)<<16|g&65535,j)},ea=function(a,b){var c=[],d,e,f,h,j,k,l,m,w,z=[1732584193,4023233417,2562383102,271733878,3285377520], -v=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708, -2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[b>>5]|=128<<24-b%32;a[(b+65>>9<<4)+15]=b;w=a.length;for(l=0;lm;m+=1)c[m]= -16>m?a[m+l]:g(c[m-3]^c[m-8]^c[m-14]^c[m-16],1),k=20>m?W(g(d,5),e&f^~e&h,j,v[m],c[m]):40>m?W(g(d,5),e^f^h,j,v[m],c[m]):60>m?W(g(d,5),C(e,f,h),j,v[m],c[m]):W(g(d,5),e^f^h,j,v[m],c[m]),j=h,h=f,f=g(e,30),e=d,d=k;z[0]=ia(d,z[0]);z[1]=ia(e,z[1]);z[2]=ia(f,z[2]);z[3]=ia(h,z[3]);z[4]=ia(j,z[4])}return z},aa=function(b,c,d){var e,f,g,h,j,k,aa,T,ea,z,va,ha,da,pa,wa,ca,xa,ya,za,Aa,sa,ra,Ba,ka,r,ta,V=[],Fa;if("SHA-224"===d||"SHA-256"===d)va=64,e=(c+65>>9<<4)+15,pa=16,wa=1,r=Number,ca=ia,xa=ja,ya=W,za=D,Aa=ma, -sa=y,ra=fa,ka=C,Ba=l,ta=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817, -3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],z="SHA-224"===d?[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]:[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];else if("SHA-384"===d||"SHA-512"===d)va=80,e=(c+128>>10<<5)+31,pa=32,wa=2,r=a,ca=L,xa=Z,ya=oa,za=m,Aa=la, -sa=ba,ra=E,ka=v,Ba=w,ta=[new r(1116352408,3609767458),new r(1899447441,602891725),new r(3049323471,3964484399),new r(3921009573,2173295548),new r(961987163,4081628472),new r(1508970993,3053834265),new r(2453635748,2937671579),new r(2870763221,3664609560),new r(3624381080,2734883394),new r(310598401,1164996542),new r(607225278,1323610764),new r(1426881987,3590304994),new r(1925078388,4068182383),new r(2162078206,991336113),new r(2614888103,633803317),new r(3248222580,3479774868),new r(3835390401,2666613458), -new r(4022224774,944711139),new r(264347078,2341262773),new r(604807628,2007800933),new r(770255983,1495990901),new r(1249150122,1856431235),new r(1555081692,3175218132),new r(1996064986,2198950837),new r(2554220882,3999719339),new r(2821834349,766784016),new r(2952996808,2566594879),new r(3210313671,3203337956),new r(3336571891,1034457026),new r(3584528711,2466948901),new r(113926993,3758326383),new r(338241895,168717936),new r(666307205,1188179964),new r(773529912,1546045734),new r(1294757372,1522805485), -new r(1396182291,2643833823),new r(1695183700,2343527390),new r(1986661051,1014477480),new r(2177026350,1206759142),new r(2456956037,344077627),new r(2730485921,1290863460),new r(2820302411,3158454273),new r(3259730800,3505952657),new r(3345764771,106217008),new r(3516065817,3606008344),new r(3600352804,1432725776),new r(4094571909,1467031594),new r(275423344,851169720),new r(430227734,3100823752),new r(506948616,1363258195),new r(659060556,3750685593),new r(883997877,3785050280),new r(958139571, -3318307427),new r(1322822218,3812723403),new r(1537002063,2003034995),new r(1747873779,3602036899),new r(1955562222,1575990012),new r(2024104815,1125592928),new r(2227730452,2716904306),new r(2361852424,442776044),new r(2428436474,593698344),new r(2756734187,3733110249),new r(3204031479,2999351573),new r(3329325298,3815920427),new r(3391569614,3928383900),new r(3515267271,566280711),new r(3940187606,3454069534),new r(4118630271,4000239992),new r(116418474,1914138554),new r(174292421,2731055270),new r(289380356, -3203993006),new r(460393269,320620315),new r(685471733,587496836),new r(852142971,1086792851),new r(1017036298,365543100),new r(1126000580,2618297676),new r(1288033470,3409855158),new r(1501505948,4234509866),new r(1607167915,987167468),new r(1816402316,1246189591)],z="SHA-384"===d?[new r(3418070365,3238371032),new r(1654270250,914150663),new r(2438529370,812702999),new r(355462360,4144912697),new r(1731405415,4290775857),new r(41048885895,1750603025),new r(3675008525,1694076839),new r(1203062813, -3204075428)]:[new r(1779033703,4089235720),new r(3144134277,2227873595),new r(1013904242,4271175723),new r(2773480762,1595750129),new r(1359893119,2917565137),new r(2600822924,725511199),new r(528734635,4215389547),new r(1541459225,327033209)];b[c>>5]|=128<<24-c%32;b[e]=c;Fa=b.length;for(ha=0;hada?new r(b[da*wa+ha],b[da*wa+ha+1]):xa(Aa(V[da-2]),V[da-7],za(V[da-15]),V[da-16]),T=ya(aa,ra(h),Ba(h,j,k), -ta[da],V[da]),ea=ca(sa(c),ka(c,e,f)),aa=k,k=j,j=h,h=ca(g,T),g=f,f=e,e=c,c=ca(T,ea);z[0]=ca(c,z[0]);z[1]=ca(e,z[1]);z[2]=ca(f,z[2]);z[3]=ca(g,z[3]);z[4]=ca(h,z[4]);z[5]=ca(j,z[5]);z[6]=ca(k,z[6]);z[7]=ca(aa,z[7])}switch(d){case "SHA-224":return[z[0],z[1],z[2],z[3],z[4],z[5],z[6]];case "SHA-256":return z;case "SHA-384":return[z[0].highOrder,z[0].lowOrder,z[1].highOrder,z[1].lowOrder,z[2].highOrder,z[2].lowOrder,z[3].highOrder,z[3].lowOrder,z[4].highOrder,z[4].lowOrder,z[5].highOrder,z[5].lowOrder]; -case "SHA-512":return[z[0].highOrder,z[0].lowOrder,z[1].highOrder,z[1].lowOrder,z[2].highOrder,z[2].lowOrder,z[3].highOrder,z[3].lowOrder,z[4].highOrder,z[4].lowOrder,z[5].highOrder,z[5].lowOrder,z[6].highOrder,z[6].lowOrder,z[7].highOrder,z[7].lowOrder];default:return[]}},pa=function(a,d){this.strToHash=this.strBinLen=this.sha512=this.sha384=this.sha256=this.sha224=this.sha1=null;if("HEX"===d){if(0!==a.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=4*a.length;this.strToHash=c(a)}else if("ASCII"=== -d||"undefined"===typeof d)this.strBinLen=8*a.length,this.strToHash=b(a);else return"UNKNOWN TEXT INPUT TYPE"};pa.prototype={getHash:function(a,b){var c=null,g=this.strToHash.slice();switch(b){case "HEX":c=d;break;case "B64":c=e;break;case "ASCII":c=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case "SHA-1":if(null===this.sha1)this.sha1=ea(g,this.strBinLen);return c(this.sha1);case "SHA-224":if(null===this.sha224)this.sha224=aa(g,this.strBinLen,a);return c(this.sha224);case "SHA-256":if(null=== -this.sha256)this.sha256=aa(g,this.strBinLen,a);return c(this.sha256);case "SHA-384":if(null===this.sha384)this.sha384=aa(g,this.strBinLen,a);return c(this.sha384);case "SHA-512":if(null===this.sha512)this.sha512=aa(g,this.strBinLen,a);return c(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,g,h,j){var k,l,m,w,v;l=[];var y=[];switch(j){case "HEX":j=d;break;case "B64":j=e;break;case "ASCII":j=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(h){case "SHA-1":k=64;v=160;break; -case "SHA-224":k=64;v=224;break;case "SHA-256":k=64;v=256;break;case "SHA-384":k=128;v=384;break;case "SHA-512":k=128;v=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===g){if(0!==a.length%2)return"KEY MUST BE IN BYTE INCREMENTS";g=c(a);w=4*a.length}else if("ASCII"===g)g=b(a),w=8*a.length;else return"UNKNOWN KEY INPUT TYPE";a=8*k;m=k/4-1;kw/8&&(g[m]&=4294967040);for(k=0;k<=m;k+=1)l[k]=g[k]^909522486,y[k]=g[k]^1549556828;"SHA-1"===h? -(l=ea(l.concat(this.strToHash),a+this.strBinLen),l=ea(y.concat(l),a+v)):(l=aa(l.concat(this.strToHash),a+this.strBinLen,h),l=aa(y.concat(l),a+v,h));return j(l)}};return pa}();function str_sha1(a){return(new jsSHA(a,"ASCII")).getHash("SHA-1","ASCII")}function str_sha224(a){return(new jsSHA(a,"ASCII")).getHash("SHA-224","ASCII")}function str_sha256(a){return(new jsSHA(a,"ASCII")).getHash("SHA-256","ASCII")}function str_sha384(a){return(new jsSHA(a,"ASCII")).getHash("SHA-384","ASCII")} +c|b.lowOrder<<32-c,b.lowOrder>>>c|b.highOrder<<32-c):new a(b.lowOrder>>>c|b.highOrder<<32-c,b.highOrder>>>c|b.lowOrder<<32-c)},j=function(b,c){return 32>=c?new a(b.highOrder>>>c,b.lowOrder>>>c|b.highOrder<<32-c):new a(0,b.highOrder<<32-c)},m=function(a,b,c){return a&b^~a&c},u=function(b,c,d){return new a(b.highOrder&c.highOrder^~b.highOrder&d.highOrder,b.lowOrder&c.lowOrder^~b.lowOrder&d.lowOrder)},C=function(a,b,c){return a&b^a&c^b&c},l=function(b,c,d){return new a(b.highOrder&c.highOrder^b.highOrder& +d.highOrder^c.highOrder&d.highOrder,b.lowOrder&c.lowOrder^b.lowOrder&d.lowOrder^c.lowOrder&d.lowOrder)},p=function(a){return h(a,2)^h(a,13)^h(a,22)},Y=function(b){var c=k(b,28),d=k(b,34),b=k(b,39);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},Q=function(a){return h(a,6)^h(a,11)^h(a,25)},D=function(b){var c=k(b,14),d=k(b,18),b=k(b,41);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},o=function(a){return h(a,7)^h(a,18)^a>>>3}, +z=function(b){var c=k(b,1),d=k(b,8),b=j(b,7);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},ma=function(a){return h(a,17)^h(a,19)^a>>>10},na=function(b){var c=k(b,19),d=k(b,61),b=j(b,6);return new a(c.highOrder^d.highOrder^b.highOrder,c.lowOrder^d.lowOrder^b.lowOrder)},ga=function(a,b){var c=(a&65535)+(b&65535);return((a>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535},la=function(a,b,c,d){var e=(a&65535)+(b&65535)+(c&65535)+(d&65535);return((a>>>16)+(b>>>16)+(c>>> +16)+(d>>>16)+(e>>>16)&65535)<<16|e&65535},N=function(a,b,c,d,e){var f=(a&65535)+(b&65535)+(c&65535)+(d&65535)+(e&65535);return((a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16)&65535)<<16|f&65535},L=function(b,c){var d,e,f;d=(b.lowOrder&65535)+(c.lowOrder&65535);e=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d>>>16);f=(e&65535)<<16|d&65535;d=(b.highOrder&65535)+(c.highOrder&65535)+(e>>>16);e=(b.highOrder>>>16)+(c.highOrder>>>16)+(d>>>16);return new a((e&65535)<<16|d&65535,f)},ba=function(b,c,d,e){var f, +g,h;f=(b.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder&65535);g=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);h=(g&65535)<<16|f&65535;f=(b.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(g>>>16);g=(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);return new a((g&65535)<<16|f&65535,h)},pa=function(b,c,d,e,f){var g,h,j;g=(b.lowOrder&65535)+(c.lowOrder&65535)+(d.lowOrder&65535)+(e.lowOrder& +65535)+(f.lowOrder&65535);h=(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f.lowOrder>>>16)+(g>>>16);j=(h&65535)<<16|g&65535;g=(b.highOrder&65535)+(c.highOrder&65535)+(d.highOrder&65535)+(e.highOrder&65535)+(f.highOrder&65535)+(h>>>16);h=(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f.highOrder>>>16)+(g>>>16);return new a((h&65535)<<16|g&65535,j)},ea=function(a,b){var c=[],d,e,f,h,j,k,m,l,p,o=[1732584193,4023233417,2562383102,271733878,3285377520], +u=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708, +2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];a[b>>5]|=128<<24-b%32;a[(b+65>>9<<4)+15]=b;p=a.length;for(m=0;ml;l+=1)c[l]= +16>l?a[l+m]:g(c[l-3]^c[l-8]^c[l-14]^c[l-16],1),k=20>l?N(g(d,5),e&f^~e&h,j,u[l],c[l]):40>l?N(g(d,5),e^f^h,j,u[l],c[l]):60>l?N(g(d,5),C(e,f,h),j,u[l],c[l]):N(g(d,5),e^f^h,j,u[l],c[l]),j=h,h=f,f=g(e,30),e=d,d=k;o[0]=ga(d,o[0]);o[1]=ga(e,o[1]);o[2]=ga(f,o[2]);o[3]=ga(h,o[3]);o[4]=ga(j,o[4])}return o},fa=function(b,c,d){var e,f,g,h,j,k,ha,O,fa,A,ea,da,ja,Ba,va,ka,wa,xa,ya,za,ta,qa,Aa,oa,t,ua,W=[],Ea;if("SHA-224"===d||"SHA-256"===d)ea=64,e=(c+65>>9<<4)+15,Ba=16,va=1,t=Number,ka=ga,wa=la,xa=N,ya=o,za=ma, +ta=p,qa=Q,oa=C,Aa=m,ua=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817, +3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],A="SHA-224"===d?[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]:[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];else if("SHA-384"===d||"SHA-512"===d)ea=80,e=(c+128>>10<<5)+31,Ba=32,va=2,t=a,ka=L,wa=ba,xa=pa,ya=z,za=na, +ta=Y,qa=D,oa=l,Aa=u,ua=[new t(1116352408,3609767458),new t(1899447441,602891725),new t(3049323471,3964484399),new t(3921009573,2173295548),new t(961987163,4081628472),new t(1508970993,3053834265),new t(2453635748,2937671579),new t(2870763221,3664609560),new t(3624381080,2734883394),new t(310598401,1164996542),new t(607225278,1323610764),new t(1426881987,3590304994),new t(1925078388,4068182383),new t(2162078206,991336113),new t(2614888103,633803317),new t(3248222580,3479774868),new t(3835390401,2666613458), +new t(4022224774,944711139),new t(264347078,2341262773),new t(604807628,2007800933),new t(770255983,1495990901),new t(1249150122,1856431235),new t(1555081692,3175218132),new t(1996064986,2198950837),new t(2554220882,3999719339),new t(2821834349,766784016),new t(2952996808,2566594879),new t(3210313671,3203337956),new t(3336571891,1034457026),new t(3584528711,2466948901),new t(113926993,3758326383),new t(338241895,168717936),new t(666307205,1188179964),new t(773529912,1546045734),new t(1294757372,1522805485), +new t(1396182291,2643833823),new t(1695183700,2343527390),new t(1986661051,1014477480),new t(2177026350,1206759142),new t(2456956037,344077627),new t(2730485921,1290863460),new t(2820302411,3158454273),new t(3259730800,3505952657),new t(3345764771,106217008),new t(3516065817,3606008344),new t(3600352804,1432725776),new t(4094571909,1467031594),new t(275423344,851169720),new t(430227734,3100823752),new t(506948616,1363258195),new t(659060556,3750685593),new t(883997877,3785050280),new t(958139571, +3318307427),new t(1322822218,3812723403),new t(1537002063,2003034995),new t(1747873779,3602036899),new t(1955562222,1575990012),new t(2024104815,1125592928),new t(2227730452,2716904306),new t(2361852424,442776044),new t(2428436474,593698344),new t(2756734187,3733110249),new t(3204031479,2999351573),new t(3329325298,3815920427),new t(3391569614,3928383900),new t(3515267271,566280711),new t(3940187606,3454069534),new t(4118630271,4000239992),new t(116418474,1914138554),new t(174292421,2731055270),new t(289380356, +3203993006),new t(460393269,320620315),new t(685471733,587496836),new t(852142971,1086792851),new t(1017036298,365543100),new t(1126000580,2618297676),new t(1288033470,3409855158),new t(1501505948,4234509866),new t(1607167915,987167468),new t(1816402316,1246189591)],A="SHA-384"===d?[new t(3418070365,3238371032),new t(1654270250,914150663),new t(2438529370,812702999),new t(355462360,4144912697),new t(1731405415,4290775857),new t(41048885895,1750603025),new t(3675008525,1694076839),new t(1203062813, +3204075428)]:[new t(1779033703,4089235720),new t(3144134277,2227873595),new t(1013904242,4271175723),new t(2773480762,1595750129),new t(1359893119,2917565137),new t(2600822924,725511199),new t(528734635,4215389547),new t(1541459225,327033209)];b[c>>5]|=128<<24-c%32;b[e]=c;Ea=b.length;for(da=0;daja?new t(b[ja*va+da],b[ja*va+da+1]):wa(za(W[ja-2]),W[ja-7],ya(W[ja-15]),W[ja-16]),O=xa(ha,qa(h),Aa(h,j,k), +ua[ja],W[ja]),fa=ka(ta(c),oa(c,e,f)),ha=k,k=j,j=h,h=ka(g,O),g=f,f=e,e=c,c=ka(O,fa);A[0]=ka(c,A[0]);A[1]=ka(e,A[1]);A[2]=ka(f,A[2]);A[3]=ka(g,A[3]);A[4]=ka(h,A[4]);A[5]=ka(j,A[5]);A[6]=ka(k,A[6]);A[7]=ka(ha,A[7])}switch(d){case "SHA-224":return[A[0],A[1],A[2],A[3],A[4],A[5],A[6]];case "SHA-256":return A;case "SHA-384":return[A[0].highOrder,A[0].lowOrder,A[1].highOrder,A[1].lowOrder,A[2].highOrder,A[2].lowOrder,A[3].highOrder,A[3].lowOrder,A[4].highOrder,A[4].lowOrder,A[5].highOrder,A[5].lowOrder]; +case "SHA-512":return[A[0].highOrder,A[0].lowOrder,A[1].highOrder,A[1].lowOrder,A[2].highOrder,A[2].lowOrder,A[3].highOrder,A[3].lowOrder,A[4].highOrder,A[4].lowOrder,A[5].highOrder,A[5].lowOrder,A[6].highOrder,A[6].lowOrder,A[7].highOrder,A[7].lowOrder];default:return[]}},da=function(a,d){this.strToHash=this.strBinLen=this.sha512=this.sha384=this.sha256=this.sha224=this.sha1=null;if("HEX"===d){if(0!==a.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=4*a.length;this.strToHash=c(a)}else if("ASCII"=== +d||"undefined"===typeof d)this.strBinLen=8*a.length,this.strToHash=b(a);else return"UNKNOWN TEXT INPUT TYPE"};da.prototype={getHash:function(a,b){var c=null,g=this.strToHash.slice();switch(b){case "HEX":c=d;break;case "B64":c=e;break;case "ASCII":c=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case "SHA-1":if(null===this.sha1)this.sha1=ea(g,this.strBinLen);return c(this.sha1);case "SHA-224":if(null===this.sha224)this.sha224=fa(g,this.strBinLen,a);return c(this.sha224);case "SHA-256":if(null=== +this.sha256)this.sha256=fa(g,this.strBinLen,a);return c(this.sha256);case "SHA-384":if(null===this.sha384)this.sha384=fa(g,this.strBinLen,a);return c(this.sha384);case "SHA-512":if(null===this.sha512)this.sha512=fa(g,this.strBinLen,a);return c(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,g,h,j){var k,l,m,o,p;l=[];var u=[];switch(j){case "HEX":j=d;break;case "B64":j=e;break;case "ASCII":j=f;break;default:return"FORMAT NOT RECOGNIZED"}switch(h){case "SHA-1":k=64;p=160;break; +case "SHA-224":k=64;p=224;break;case "SHA-256":k=64;p=256;break;case "SHA-384":k=128;p=384;break;case "SHA-512":k=128;p=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===g){if(0!==a.length%2)return"KEY MUST BE IN BYTE INCREMENTS";g=c(a);o=4*a.length}else if("ASCII"===g)g=b(a),o=8*a.length;else return"UNKNOWN KEY INPUT TYPE";a=8*k;m=k/4-1;ko/8&&(g[m]&=4294967040);for(k=0;k<=m;k+=1)l[k]=g[k]^909522486,u[k]=g[k]^1549556828;"SHA-1"===h? +(l=ea(l.concat(this.strToHash),a+this.strBinLen),l=ea(u.concat(l),a+p)):(l=fa(l.concat(this.strToHash),a+this.strBinLen,h),l=fa(u.concat(l),a+p,h));return j(l)}};return da}();function str_sha1(a){return(new jsSHA(a,"ASCII")).getHash("SHA-1","ASCII")}function str_sha224(a){return(new jsSHA(a,"ASCII")).getHash("SHA-224","ASCII")}function str_sha256(a){return(new jsSHA(a,"ASCII")).getHash("SHA-256","ASCII")}function str_sha384(a){return(new jsSHA(a,"ASCII")).getHash("SHA-384","ASCII")} function str_sha512(a){return(new jsSHA(a,"ASCII")).getHash("SHA-512","ASCII")}var RMDsize=160,X=[];function ROL(a,b){return new Number(a<>>32-b)}function F(a,b,c){return new Number(a^b^c)}function G(a,b,c){return new Number(a&b|~a&c)}function H(a,b,c){return new Number((a|~b)^c)}function I(a,b,c){return new Number(a&c|b&~c)}function J(a,b,c){return new Number(a^(b|~c))} function mixOneRound(a,b,c,d,e,f,g,h){switch(h){case 0:a+=F(b,c,d)+f+0;break;case 1:a+=G(b,c,d)+f+1518500249;break;case 2:a+=H(b,c,d)+f+1859775393;break;case 3:a+=I(b,c,d)+f+2400959708;break;case 4:a+=J(b,c,d)+f+2840853838;break;case 5:a+=J(b,c,d)+f+1352829926;break;case 6:a+=I(b,c,d)+f+1548603684;break;case 7:a+=H(b,c,d)+f+1836072691;break;case 8:a+=G(b,c,d)+f+2053994217;break;case 9:a+=F(b,c,d)+f+0;break;default:document.write("Bogus round number")}a=ROL(a,g)+e;c=ROL(c,10);h=[];h[0]=a&4294967295; h[1]=b&4294967295;h[2]=c&4294967295;h[3]=d&4294967295;h[4]=e&4294967295;h[5]=f;h[6]=g;return h}function MDinit(a){a[0]=1732584193;a[1]=4023233417;a[2]=2562383102;a[3]=271733878;a[4]=3285377520} diff --git a/src/compression/zlib/jsxcompressor.js b/src/compression/zlib/jsxcompressor.js new file mode 100644 index 00000000..e213e88e --- /dev/null +++ b/src/compression/zlib/jsxcompressor.js @@ -0,0 +1,1212 @@ +JXG = {exists: (function(undefined){return function(v){return !(v===undefined || v===null);}})()}; +JXG.decompress = function(str) {return unescape((new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(str))).unzip()[0][0]);}; +/* + Copyright 2008-2012 + Matthias Ehmann, + Michael Gerhaeuser, + Carsten Miller, + Bianca Valentin, + Alfred Wassermann, + Peter Wilfahrt + + This file is part of JSXGraph. + + Dual licensed under the Apache License Version 2.0, or LGPL Version 3 licenses. + + You should have received a copy of the GNU Lesser General Public License + along with JSXCompressor. If not, see . + + You should have received a copy of the Apache License along with JSXCompressor. + If not, see . + +*/ + +/** + * @fileoverview Utilities for uncompressing and base64 decoding + */ + +/** + * @class Util class + * Class for gunzipping, unzipping and base64 decoding of files. + * It is used for reading GEONExT, Geogebra and Intergeo files. + * + * Only Huffman codes are decoded in gunzip. + * The code is based on the source code for gunzip.c by Pasi Ojala + * @see http://www.cs.tut.fi/~albert/Dev/gunzip/gunzip.c + * @see http://www.cs.tut.fi/~albert + */ +JXG.Util = {}; + +/** + * Unzip zip files + */ +JXG.Util.Unzip = function (barray){ + var outputArr = [], + output = "", + debug = false, + gpflags, + files = 0, + unzipped = [], + crc, + buf32k = new Array(32768), + bIdx = 0, + modeZIP=false, + + CRC, SIZE, + + bitReverse = [ + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff + ], + + cplens = [ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 + ], + + cplext = [ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 + ], /* 99==invalid */ + + cpdist = [ + 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, + 0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, + 0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, + 0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001 + ], + + cpdext = [ + 0, 0, 0, 0, 1, 1, 2, 2, + 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13 + ], + + border = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], + + bA = barray, + + bytepos=0, + bitpos=0, + bb = 1, + bits=0, + + NAMEMAX = 256, + + nameBuf = [], + + fileout; + + function readByte(){ + bits+=8; + if (bytepos"); + return bA[bytepos++]; + } else + return -1; + }; + + function byteAlign(){ + bb = 1; + }; + + function readBit(){ + var carry; + bits++; + carry = (bb & 1); + bb >>= 1; + if (bb==0){ + bb = readByte(); + carry = (bb & 1); + bb = (bb>>1) | 0x80; + } + return carry; + }; + + function readBits(a) { + var res = 0, + i = a; + + while(i--) { + res = (res<<1) | readBit(); + } + if(a) { + res = bitReverse[res]>>(8-a); + } + return res; + }; + + function flushBuffer(){ + //document.write('FLUSHBUFFER:'+buf32k); + bIdx = 0; + }; + function addBuffer(a){ + SIZE++; + //CRC=updcrc(a,crc); + buf32k[bIdx++] = a; + outputArr.push(String.fromCharCode(a)); + //output+=String.fromCharCode(a); + if(bIdx==0x8000){ + //document.write('ADDBUFFER:'+buf32k); + bIdx=0; + } + }; + + function HufNode() { + this.b0=0; + this.b1=0; + this.jump = null; + this.jumppos = -1; + }; + + var LITERALS = 288; + + var literalTree = new Array(LITERALS); + var distanceTree = new Array(32); + var treepos=0; + var Places = null; + var Places2 = null; + + var impDistanceTree = new Array(64); + var impLengthTree = new Array(64); + + var len = 0; + var fpos = new Array(17); + fpos[0]=0; + var flens; + var fmax; + + function IsPat() { + while (1) { + if (fpos[len] >= fmax) + return -1; + if (flens[fpos[len]] == len) + return fpos[len]++; + fpos[len]++; + } + }; + + function Rec() { + var curplace = Places[treepos]; + var tmp; + if (debug) + document.write("
len:"+len+" treepos:"+treepos); + if(len==17) { //war 17 + return -1; + } + treepos++; + len++; + + tmp = IsPat(); + if (debug) + document.write("
IsPat "+tmp); + if(tmp >= 0) { + curplace.b0 = tmp; /* leaf cell for 0-bit */ + if (debug) + document.write("
b0 "+curplace.b0); + } else { + /* Not a Leaf cell */ + curplace.b0 = 0x8000; + if (debug) + document.write("
b0 "+curplace.b0); + if(Rec()) + return -1; + } + tmp = IsPat(); + if(tmp >= 0) { + curplace.b1 = tmp; /* leaf cell for 1-bit */ + if (debug) + document.write("
b1 "+curplace.b1); + curplace.jump = null; /* Just for the display routine */ + } else { + /* Not a Leaf cell */ + curplace.b1 = 0x8000; + if (debug) + document.write("
b1 "+curplace.b1); + curplace.jump = Places[treepos]; + curplace.jumppos = treepos; + if(Rec()) + return -1; + } + len--; + return 0; + }; + + function CreateTree(currentTree, numval, lengths, show) { + var i; + /* Create the Huffman decode tree/table */ + //document.write("
createtree
"); + if (debug) + document.write("currentTree "+currentTree+" numval "+numval+" lengths "+lengths+" show "+show); + Places = currentTree; + treepos=0; + flens = lengths; + fmax = numval; + for (i=0;i<17;i++) + fpos[i] = 0; + len = 0; + if(Rec()) { + //fprintf(stderr, "invalid huffman tree\n"); + if (debug) + alert("invalid huffman tree\n"); + return -1; + } + if (debug){ + document.write('
Tree: '+Places.length); + for (var a=0;a<32;a++){ + document.write("Places["+a+"].b0="+Places[a].b0+"
"); + document.write("Places["+a+"].b1="+Places[a].b1+"
"); + } + } + + /*if(show) { + var tmp; + for(tmp=currentTree;tmpjump?tmp->jump-currentTree:0,(tmp->jump?tmp->jump-currentTree:0)*6+0xcf0); + if(!(tmp.b0 & 0x8000)) { + //fprintf(stdout, " 0x%03x (%c)", tmp->b0,(tmp->b0<256 && isprint(tmp->b0))?tmp->b0:'�'); + } + if(!(tmp.b1 & 0x8000)) { + if((tmp.b0 & 0x8000)) + fprintf(stdout, " "); + fprintf(stdout, " 0x%03x (%c)", tmp->b1,(tmp->b1<256 && isprint(tmp->b1))?tmp->b1:'�'); + } + fprintf(stdout, "\n"); + } + }*/ + return 0; + }; + + function DecodeValue(currentTree) { + var len, i, + xtreepos=0, + X = currentTree[xtreepos], + b; + + /* decode one symbol of the data */ + while(1) { + b=readBit(); + if (debug) + document.write("b="+b); + if(b) { + if(!(X.b1 & 0x8000)){ + if (debug) + document.write("ret1"); + return X.b1; /* If leaf node, return data */ + } + X = X.jump; + len = currentTree.length; + for (i=0;i>1); + if(j > 23) { + j = (j<<1) | readBit(); /* 48..255 */ + + if(j > 199) { /* 200..255 */ + j -= 128; /* 72..127 */ + j = (j<<1) | readBit(); /* 144..255 << */ + } else { /* 48..199 */ + j -= 48; /* 0..151 */ + if(j > 143) { + j = j+136; /* 280..287 << */ + /* 0..143 << */ + } + } + } else { /* 0..23 */ + j += 256; /* 256..279 << */ + } + if(j < 256) { + addBuffer(j); + //document.write("out:"+String.fromCharCode(j)); + /*fprintf(errfp, "@%d %02x\n", SIZE, j);*/ + } else if(j == 256) { + /* EOF */ + break; + } else { + var len, dist; + + j -= 256 + 1; /* bytes + EOF */ + len = readBits(cplext[j]) + cplens[j]; + + j = bitReverse[readBits(5)]>>3; + if(cpdext[j] > 8) { + dist = readBits(8); + dist |= (readBits(cpdext[j]-8)<<8); + } else { + dist = readBits(cpdext[j]); + } + dist += cpdist[j]; + + /*fprintf(errfp, "@%d (l%02x,d%04x)\n", SIZE, len, dist);*/ + for(j=0;jparam: "+literalCodes+" "+distCodes+" "+lenCodes+"
"); + for(j=0; j<19; j++) { + ll[j] = 0; + } + + // Get the decode tree code lengths + + //document.write("
"); + for(j=0; jll:'+ll); + len = distanceTree.length; + for (i=0; idistanceTree"); + for(var a=0;a"+distanceTree[a].b0+" "+distanceTree[a].b1+" "+distanceTree[a].jump+" "+distanceTree[a].jumppos); + /*if (distanceTree[a].jumppos!=-1) + document.write(" "+distanceTree[a].jump.b0+" "+distanceTree[a].jump.b1); + */ + } + } + //document.write('
tree created'); + + //read in literal and distance code lengths + n = literalCodes + distCodes; + i = 0; + var z=-1; + if (debug) + document.write("
n="+n+" bits: "+bits+"
"); + while(i < n) { + z++; + j = DecodeValue(distanceTree); + if (debug) + document.write("
"+z+" i:"+i+" decode: "+j+" bits "+bits+"
"); + if(j<16) { // length of code in bits (0..15) + ll[i++] = j; + } else if(j==16) { // repeat last length 3 to 6 times + var l; + j = 3 + readBits(2); + if(i+j > n) { + flushBuffer(); + return 1; + } + l = i ? ll[i-1] : 0; + while(j--) { + ll[i++] = l; + } + } else { + if(j==17) { // 3 to 10 zero length codes + j = 3 + readBits(3); + } else { // j == 18: 11 to 138 zero length codes + j = 11 + readBits(7); + } + if(i+j > n) { + flushBuffer(); + return 1; + } + while(j--) { + ll[i++] = 0; + } + } + } + /*for(j=0; jliteralTree"); + while(1) { + j = DecodeValue(literalTree); + if(j >= 256) { // In C64: if carry set + var len, dist; + j -= 256; + if(j == 0) { + // EOF + break; + } + j--; + len = readBits(cplext[j]) + cplens[j]; + + j = DecodeValue(distanceTree); + if(cpdext[j] > 8) { + dist = readBits(8); + dist |= (readBits(cpdext[j]-8)<<8); + } else { + dist = readBits(cpdext[j]); + } + dist += cpdist[j]; + while(len--) { + var c = buf32k[(bIdx - dist) & 0x7fff]; + addBuffer(c); + } + } else { + addBuffer(j); + } + } + } + } while(!last); + flushBuffer(); + + byteAlign(); + return 0; +}; + +JXG.Util.Unzip.prototype.unzipFile = function(name) { + var i; + this.unzip(); + //alert(unzipped[0][1]); + for (i=0;i"); + } + */ + //alert(bA); + nextFile(); + return unzipped; + }; + + function nextFile(){ + if (debug) + alert("NEXTFILE"); + outputArr = []; + var tmp = []; + modeZIP = false; + tmp[0] = readByte(); + tmp[1] = readByte(); + if (debug) + alert("type: "+tmp[0]+" "+tmp[1]); + if (tmp[0] == parseInt("78",16) && tmp[1] == parseInt("da",16)){ //GZIP + if (debug) + alert("GEONExT-GZIP"); + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "geonext.gxt"; + files++; + } + if (tmp[0] == parseInt("78",16) && tmp[1] == parseInt("9c",16)){ //ZLIB + if (debug) + alert("ZLIB"); + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "ZLIB"; + files++; + } + if (tmp[0] == parseInt("1f",16) && tmp[1] == parseInt("8b",16)){ //GZIP + if (debug) + alert("GZIP"); + //DeflateLoop(); + skipdir(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = "file"; + files++; + } + if (tmp[0] == parseInt("50",16) && tmp[1] == parseInt("4b",16)){ //ZIP + modeZIP = true; + tmp[2] = readByte(); + tmp[3] = readByte(); + if (tmp[2] == parseInt("3",16) && tmp[3] == parseInt("4",16)){ + //MODE_ZIP + tmp[0] = readByte(); + tmp[1] = readByte(); + if (debug) + alert("ZIP-Version: "+tmp[1]+" "+tmp[0]/10+"."+tmp[0]%10); + + gpflags = readByte(); + gpflags |= (readByte()<<8); + if (debug) + alert("gpflags: "+gpflags); + + var method = readByte(); + method |= (readByte()<<8); + if (debug) + alert("method: "+method); + + readByte(); + readByte(); + readByte(); + readByte(); + + var crc = readByte(); + crc |= (readByte()<<8); + crc |= (readByte()<<16); + crc |= (readByte()<<24); + + var compSize = readByte(); + compSize |= (readByte()<<8); + compSize |= (readByte()<<16); + compSize |= (readByte()<<24); + + var size = readByte(); + size |= (readByte()<<8); + size |= (readByte()<<16); + size |= (readByte()<<24); + + if (debug) + alert("local CRC: "+crc+"\nlocal Size: "+size+"\nlocal CompSize: "+compSize); + + var filelen = readByte(); + filelen |= (readByte()<<8); + + var extralen = readByte(); + extralen |= (readByte()<<8); + + if (debug) + alert("filelen "+filelen); + i = 0; + nameBuf = []; + while (filelen--){ + var c = readByte(); + if (c == "/" | c ==":"){ + i = 0; + } else if (i < NAMEMAX-1) + nameBuf[i++] = String.fromCharCode(c); + } + if (debug) + alert("nameBuf: "+nameBuf); + + //nameBuf[i] = "\0"; + if (!fileout) + fileout = nameBuf; + + var i = 0; + while (i < extralen){ + c = readByte(); + i++; + } + + CRC = 0xffffffff; + SIZE = 0; + + if (size = 0 && fileOut.charAt(fileout.length-1)=="/"){ + //skipdir + if (debug) + alert("skipdir"); + } + if (method == 8){ + DeflateLoop(); + if (debug) + alert(outputArr.join('')); + unzipped[files] = new Array(2); + unzipped[files][0] = outputArr.join(''); + unzipped[files][1] = nameBuf.join(''); + files++; + //return outputArr.join(''); + } + skipdir(); + } + } + }; + +function skipdir(){ + var crc, + tmp = [], + compSize, size, os, i, c; + + if ((gpflags & 8)) { + tmp[0] = readByte(); + tmp[1] = readByte(); + tmp[2] = readByte(); + tmp[3] = readByte(); + + if (tmp[0] == parseInt("50",16) && + tmp[1] == parseInt("4b",16) && + tmp[2] == parseInt("07",16) && + tmp[3] == parseInt("08",16)) + { + crc = readByte(); + crc |= (readByte()<<8); + crc |= (readByte()<<16); + crc |= (readByte()<<24); + } else { + crc = tmp[0] | (tmp[1]<<8) | (tmp[2]<<16) | (tmp[3]<<24); + } + + compSize = readByte(); + compSize |= (readByte()<<8); + compSize |= (readByte()<<16); + compSize |= (readByte()<<24); + + size = readByte(); + size |= (readByte()<<8); + size |= (readByte()<<16); + size |= (readByte()<<24); + + if (debug) + alert("CRC:"); + } + + if (modeZIP) + nextFile(); + + tmp[0] = readByte(); + if (tmp[0] != 8) { + if (debug) + alert("Unknown compression method!"); + return 0; + } + + gpflags = readByte(); + if (debug){ + if ((gpflags & ~(parseInt("1f",16)))) + alert("Unknown flags set!"); + } + + readByte(); + readByte(); + readByte(); + readByte(); + + readByte(); + os = readByte(); + + if ((gpflags & 4)){ + tmp[0] = readByte(); + tmp[2] = readByte(); + len = tmp[0] + 256*tmp[1]; + if (debug) + alert("Extra field size: "+len); + for (i=0;ihttp://www.webtoolkit.info/ +*/ +JXG.Util.Base64 = { + + // private property + _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", + + // public method for encoding + encode : function (input) { + var output = [], + chr1, chr2, chr3, enc1, enc2, enc3, enc4, + i = 0; + + input = JXG.Util.Base64._utf8_encode(input); + + while (i < input.length) { + + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output.push([this._keyStr.charAt(enc1), + this._keyStr.charAt(enc2), + this._keyStr.charAt(enc3), + this._keyStr.charAt(enc4)].join('')); + } + + return output.join(''); + }, + + // public method for decoding + decode : function (input, utf8) { + var output = [], + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + + enc1 = this._keyStr.indexOf(input.charAt(i++)); + enc2 = this._keyStr.indexOf(input.charAt(i++)); + enc3 = this._keyStr.indexOf(input.charAt(i++)); + enc4 = this._keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output.push(String.fromCharCode(chr1)); + + if (enc3 != 64) { + output.push(String.fromCharCode(chr2)); + } + if (enc4 != 64) { + output.push(String.fromCharCode(chr3)); + } + } + + output = output.join(''); + + if (utf8) { + output = JXG.Util.Base64._utf8_decode(output); + } + return output; + + }, + + // private method for UTF-8 encoding + _utf8_encode : function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }, + + // private method for UTF-8 decoding + _utf8_decode : function (utftext) { + var string = [], + i = 0, + c = 0, c2 = 0, c3 = 0; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + if (c < 128) { + string.push(String.fromCharCode(c)); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string.push(String.fromCharCode(((c & 31) << 6) | (c2 & 63))); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))); + i += 3; + } + } + return string.join(''); + }, + + _destrip: function (stripped, wrap){ + var lines = [], lineno, i, + destripped = []; + + if (wrap==null) + wrap = 76; + + stripped.replace(/ /g, ""); + lineno = stripped.length / wrap; + for (i = 0; i < lineno; i++) + lines[i]=stripped.substr(i * wrap, wrap); + if (lineno != stripped.length / wrap) + lines[lines.length]=stripped.substr(lineno * wrap, stripped.length-(lineno * wrap)); + + for (i = 0; i < lines.length; i++) + destripped.push(lines[i]); + return destripped.join('\n'); + }, + + decodeAsArray: function (input){ + var dec = this.decode(input), + ar = [], i; + for (i=0;i255){ + switch (c) { + case 8364: c=128; + break; + case 8218: c=130; + break; + case 402: c=131; + break; + case 8222: c=132; + break; + case 8230: c=133; + break; + case 8224: c=134; + break; + case 8225: c=135; + break; + case 710: c=136; + break; + case 8240: c=137; + break; + case 352: c=138; + break; + case 8249: c=139; + break; + case 338: c=140; + break; + case 381: c=142; + break; + case 8216: c=145; + break; + case 8217: c=146; + break; + case 8220: c=147; + break; + case 8221: c=148; + break; + case 8226: c=149; + break; + case 8211: c=150; + break; + case 8212: c=151; + break; + case 732: c=152; + break; + case 8482: c=153; + break; + case 353: c=154; + break; + case 8250: c=155; + break; + case 339: c=156; + break; + case 382: c=158; + break; + case 376: c=159; + break; + default: + break; + } + } + return c; +}; + +/** + * Decoding string into utf-8 + * @param {String} string to decode + * @return {String} utf8 decoded string + */ +JXG.Util.utf8Decode = function(utftext) { + var string = []; + var i = 0; + var c = 0, c1 = 0, c2 = 0, c3; + if (!JXG.exists(utftext)) return ''; + + while ( i < utftext.length ) { + c = utftext.charCodeAt(i); + + if (c < 128) { + string.push(String.fromCharCode(c)); + i++; + } else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string.push(String.fromCharCode(((c & 31) << 6) | (c2 & 63))); + i += 2; + } else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))); + i += 3; + } + }; + return string.join(''); +}; + +/** + * Generate a random uuid. + * http://www.broofa.com + * mailto:robert@broofa.com + * + * Copyright (c) 2010 Robert Kieffer + * Dual licensed under the MIT and GPL licenses. + * + * EXAMPLES: + * >>> Math.uuid() + * "92329D39-6F5C-4520-ABFC-AAB64544E172" + */ +JXG.Util.genUUID = function() { + // Private array of chars to use + var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''), + uuid = new Array(36), rnd=0, r; + + for (var i = 0; i < 36; i++) { + if (i==8 || i==13 || i==18 || i==23) { + uuid[i] = '-'; + } else if (i==14) { + uuid[i] = '4'; + } else { + if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0; + r = rnd & 0xf; + rnd = rnd >> 4; + uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; + } + } + + return uuid.join(''); +}; + diff --git a/src/packet/openpgp.packet.compressed.js b/src/packet/openpgp.packet.compressed.js index d941333c..d58f22b1 100644 --- a/src/packet/openpgp.packet.compressed.js +++ b/src/packet/openpgp.packet.compressed.js @@ -68,22 +68,21 @@ function openpgp_packet_compressed() { this.decompressedData = packet.data; break; case 2: // - ZLIB [RFC1950] - // TODO: This is pretty hacky. Not fully utilizing ZLIB (ADLER-32). No real JS implementations out there for this? - var compressionMethod = this.compressedData.charCodeAt(0)%0x10; //RFC 1950. Bits 0-3 Compression Method - //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size. - //2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary (how is this defined). Basic checksum, and compression level. - if(compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951 - var inflater = new zip.Inflater(); - var output = inflater.append(util.str2Uint8Array(this.compressedData.substring(2,this.compressedData.length-4))); - var outputString = util.Uint8Array2str(output); - //TODO check ADLER32 checksum - var packet = openpgp_packet.read_packet(outputString,0,outputString.length); - util.print_info('Decompressed packet [Type 2-ZLIB]: ' + packet); - this.decompressedData = packet.data; - } - else{ - util.print_error("Compression algorithm ZLIB is not fully implemented."); - } + var compressionMethod = this.compressedData.charCodeAt(0) % 0x10; //RFC 1950. Bits 0-3 Compression Method + //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size. + //2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary (how is this defined). Basic checksum, and compression level. + if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951 + // remove 4 bytes ADLER32 checksum from the end + var compData = this.compressedData.substring(0, this.compressedData.length - 4); + var radix = s2r(compData).replace(/\n/g,""); + var outputString = JXG.decompress(radix); + //TODO check ADLER32 checksum + var packet = openpgp_packet.read_packet(outputString, 0, outputString.length); + util.print_info('Decompressed packet [Type 2-ZLIB]: ' + packet); + this.decompressedData = packet.data; + } else { + util.print_error("Compression algorithm ZLIB only supports DEFLATE compression method."); + } break; case 3: // - BZip2 [BZ2] // TODO: need to implement this diff --git a/test/encryption.html b/test/encryption.html index 1247f166..1bb29751 100644 --- a/test/encryption.html +++ b/test/encryption.html @@ -26,6 +26,7 @@ +