update copyright notice on lzstring

This commit is contained in:
jude 2023-05-02 14:39:05 +01:00
parent b59ced8fa6
commit e53a4405bc
4 changed files with 25 additions and 321 deletions

BIN
code.zip Normal file

Binary file not shown.

View File

@ -1,320 +1,24 @@
/** /**
* Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net> * MIT License
* This work is free. You can redistribute it and/or modify it
* under the terms of the WTFPL, Version 2
* For more information see LICENSE.txt or http://www.wtfpl.net/
* *
* For more information, the home page: * Copyright (c) 2013 pieroxy
* http://pieroxy.net/blog/pages/lz-string/testing.html *
* * Permission is hereby granted, free of charge, to any person obtaining a copy
* LZ-based compression algorithm, version 1.4.5 * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
var LZString = (function () { var LZString=function(){var r=String.fromCharCode,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",e={};function t(r,o){if(!e[r]){e[r]={};for(var n=0;n<r.length;n++)e[r][r.charAt(n)]=n}return e[r][o]}var i={compressToBase64:function(r){if(null==r)return"";var n=i._compress(r,6,function(r){return o.charAt(r)});switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(r){return null==r?"":""==r?null:i._decompress(r.length,32,function(n){return t(o,r.charAt(n))})},compressToUTF16:function(o){return null==o?"":i._compress(o,15,function(o){return r(o+32)})+" "},decompressFromUTF16:function(r){return null==r?"":""==r?null:i._decompress(r.length,16384,function(o){return r.charCodeAt(o)-32})},compressToUint8Array:function(r){for(var o=i.compress(r),n=new Uint8Array(2*o.length),e=0,t=o.length;e<t;e++){var s=o.charCodeAt(e);n[2*e]=s>>>8,n[2*e+1]=s%256}return n},decompressFromUint8Array:function(o){if(null==o)return i.decompress(o);for(var n=new Array(o.length/2),e=0,t=n.length;e<t;e++)n[e]=256*o[2*e]+o[2*e+1];var s=[];return n.forEach(function(o){s.push(r(o))}),i.decompress(s.join(""))},compressToEncodedURIComponent:function(r){return null==r?"":i._compress(r,6,function(r){return n.charAt(r)})},decompressFromEncodedURIComponent:function(r){return null==r?"":""==r?null:(r=r.replace(/ /g,"+"),i._decompress(r.length,32,function(o){return t(n,r.charAt(o))}))},compress:function(o){return i._compress(o,16,function(o){return r(o)})},_compress:function(r,o,n){if(null==r)return"";var e,t,i,s={},u={},a="",p="",c="",l=2,f=3,h=2,d=[],m=0,v=0;for(i=0;i<r.length;i+=1)if(a=r.charAt(i),Object.prototype.hasOwnProperty.call(s,a)||(s[a]=f++,u[a]=!0),p=c+a,Object.prototype.hasOwnProperty.call(s,p))c=p;else{if(Object.prototype.hasOwnProperty.call(u,c)){if(c.charCodeAt(0)<256){for(e=0;e<h;e++)m<<=1,v==o-1?(v=0,d.push(n(m)),m=0):v++;for(t=c.charCodeAt(0),e=0;e<8;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;e<h;e++)m=m<<1|t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=c.charCodeAt(0),e=0;e<16;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[c]}else for(t=s[c],e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++),s[p]=f++,c=String(a)}if(""!==c){if(Object.prototype.hasOwnProperty.call(u,c)){if(c.charCodeAt(0)<256){for(e=0;e<h;e++)m<<=1,v==o-1?(v=0,d.push(n(m)),m=0):v++;for(t=c.charCodeAt(0),e=0;e<8;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;e<h;e++)m=m<<1|t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=c.charCodeAt(0),e=0;e<16;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[c]}else for(t=s[c],e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++)}for(t=2,e=0;e<h;e++)m=m<<1|1&t,v==o-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;for(;;){if(m<<=1,v==o-1){d.push(n(m));break}v++}return d.join("")},decompress:function(r){return null==r?"":""==r?null:i._decompress(r.length,32768,function(o){return r.charCodeAt(o)})},_decompress:function(o,n,e){var t,i,s,u,a,p,c,l=[],f=4,h=4,d=3,m="",v=[],g={val:e(0),position:n,index:1};for(t=0;t<3;t+=1)l[t]=t;for(s=0,a=Math.pow(2,2),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;switch(s){case 0:for(s=0,a=Math.pow(2,8),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;c=r(s);break;case 1:for(s=0,a=Math.pow(2,16),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;c=r(s);break;case 2:return""}for(l[3]=c,i=c,v.push(c);;){if(g.index>o)return"";for(s=0,a=Math.pow(2,d),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;switch(c=s){case 0:for(s=0,a=Math.pow(2,8),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;l[h++]=r(s),c=h-1,f--;break;case 1:for(s=0,a=Math.pow(2,16),p=1;p!=a;)u=g.val&g.position,g.position>>=1,0==g.position&&(g.position=n,g.val=e(g.index++)),s|=(u>0?1:0)*p,p<<=1;l[h++]=r(s),c=h-1,f--;break;case 2:return v.join("")}if(0==f&&(f=Math.pow(2,d),d++),l[c])m=l[c];else{if(c!==h)return null;m=i+i.charAt(0)}v.push(m),l[h++]=i+m.charAt(0),i=m,0==--f&&(f=Math.pow(2,d),d++)}}};return i}();"function"==typeof define&&define.amd?define(function(){return LZString}):"undefined"!=typeof module&&null!=module?module.exports=LZString:"undefined"!=typeof angular&&null!=angular&&angular.module("LZString",[]).factory("LZString",function(){return LZString});
var r = String.fromCharCode,
o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",
e = {};
function t(r, o) {
if (!e[r]) {
e[r] = {};
for (var n = 0; n < r.length; n++) e[r][r.charAt(n)] = n;
}
return e[r][o];
}
var i = {
compressToBase64: function (r) {
if (null == r) return "";
var n = i._compress(r, 6, function (r) {
return o.charAt(r);
});
switch (n.length % 4) {
default:
case 0:
return n;
case 1:
return n + "===";
case 2:
return n + "==";
case 3:
return n + "=";
}
},
decompressFromBase64: function (r) {
return null == r
? ""
: "" == r
? null
: i._decompress(r.length, 32, function (n) {
return t(o, r.charAt(n));
});
},
compressToUTF16: function (o) {
return null == o
? ""
: i._compress(o, 15, function (o) {
return r(o + 32);
}) + " ";
},
decompressFromUTF16: function (r) {
return null == r
? ""
: "" == r
? null
: i._decompress(r.length, 16384, function (o) {
return r.charCodeAt(o) - 32;
});
},
compressToUint8Array: function (r) {
for (
var o = i.compress(r),
n = new Uint8Array(2 * o.length),
e = 0,
t = o.length;
e < t;
e++
) {
var s = o.charCodeAt(e);
(n[2 * e] = s >>> 8), (n[2 * e + 1] = s % 256);
}
return n;
},
decompressFromUint8Array: function (o) {
if (null == o) return i.decompress(o);
for (var n = new Array(o.length / 2), e = 0, t = n.length; e < t; e++)
n[e] = 256 * o[2 * e] + o[2 * e + 1];
var s = [];
return (
n.forEach(function (o) {
s.push(r(o));
}),
i.decompress(s.join(""))
);
},
compressToEncodedURIComponent: function (r) {
return null == r
? ""
: i._compress(r, 6, function (r) {
return n.charAt(r);
});
},
decompressFromEncodedURIComponent: function (r) {
return null == r
? ""
: "" == r
? null
: ((r = r.replace(/ /g, "+")),
i._decompress(r.length, 32, function (o) {
return t(n, r.charAt(o));
}));
},
compress: function (o) {
return i._compress(o, 16, function (o) {
return r(o);
});
},
_compress: function (r, o, n) {
if (null == r) return "";
var e,
t,
i,
s = {},
u = {},
a = "",
p = "",
c = "",
l = 2,
f = 3,
h = 2,
d = [],
m = 0,
v = 0;
for (i = 0; i < r.length; i += 1)
if (
((a = r.charAt(i)),
Object.prototype.hasOwnProperty.call(s, a) ||
((s[a] = f++), (u[a] = !0)),
(p = c + a),
Object.prototype.hasOwnProperty.call(s, p))
)
c = p;
else {
if (Object.prototype.hasOwnProperty.call(u, c)) {
if (c.charCodeAt(0) < 256) {
for (e = 0; e < h; e++)
(m <<= 1),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++;
for (t = c.charCodeAt(0), e = 0; e < 8; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
} else {
for (t = 1, e = 0; e < h; e++)
(m = (m << 1) | t),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t = 0);
for (t = c.charCodeAt(0), e = 0; e < 16; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
}
0 == --l && ((l = Math.pow(2, h)), h++), delete u[c];
} else
for (t = s[c], e = 0; e < h; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
0 == --l && ((l = Math.pow(2, h)), h++),
(s[p] = f++),
(c = String(a));
}
if ("" !== c) {
if (Object.prototype.hasOwnProperty.call(u, c)) {
if (c.charCodeAt(0) < 256) {
for (e = 0; e < h; e++)
(m <<= 1),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++;
for (t = c.charCodeAt(0), e = 0; e < 8; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
} else {
for (t = 1, e = 0; e < h; e++)
(m = (m << 1) | t),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t = 0);
for (t = c.charCodeAt(0), e = 0; e < 16; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
}
0 == --l && ((l = Math.pow(2, h)), h++), delete u[c];
} else
for (t = s[c], e = 0; e < h; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
0 == --l && ((l = Math.pow(2, h)), h++);
}
for (t = 2, e = 0; e < h; e++)
(m = (m << 1) | (1 & t)),
v == o - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1);
for (;;) {
if (((m <<= 1), v == o - 1)) {
d.push(n(m));
break;
}
v++;
}
return d.join("");
},
decompress: function (r) {
return null == r
? ""
: "" == r
? null
: i._decompress(r.length, 32768, function (o) {
return r.charCodeAt(o);
});
},
_decompress: function (o, n, e) {
var t,
i,
s,
u,
a,
p,
c,
l = [],
f = 4,
h = 4,
d = 3,
m = "",
v = [],
g = { val: e(0), position: n, index: 1 };
for (t = 0; t < 3; t += 1) l[t] = t;
for (s = 0, a = Math.pow(2, 2), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position && ((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
switch (s) {
case 0:
for (s = 0, a = Math.pow(2, 8), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position && ((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
c = r(s);
break;
case 1:
for (s = 0, a = Math.pow(2, 16), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position && ((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
c = r(s);
break;
case 2:
return "";
}
for (l[3] = c, i = c, v.push(c); ; ) {
if (g.index > o) return "";
for (s = 0, a = Math.pow(2, d), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position && ((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
switch ((c = s)) {
case 0:
for (s = 0, a = Math.pow(2, 8), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position &&
((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
(l[h++] = r(s)), (c = h - 1), f--;
break;
case 1:
for (s = 0, a = Math.pow(2, 16), p = 1; p != a; )
(u = g.val & g.position),
(g.position >>= 1),
0 == g.position &&
((g.position = n), (g.val = e(g.index++))),
(s |= (u > 0 ? 1 : 0) * p),
(p <<= 1);
(l[h++] = r(s)), (c = h - 1), f--;
break;
case 2:
return v.join("");
}
if ((0 == f && ((f = Math.pow(2, d)), d++), l[c])) m = l[c];
else {
if (c !== h) return null;
m = i + i.charAt(0);
}
v.push(m),
(l[h++] = i + m.charAt(0)),
(i = m),
0 == --f && ((f = Math.pow(2, d)), d++);
}
},
};
return i;
})();
"function" == typeof define && define.amd
? define(function () {
return LZString;
})
: "undefined" != typeof module && null != module
? (module.exports = LZString)
: "undefined" != typeof angular &&
null != angular &&
angular.module("LZString", []).factory("LZString", function () {
return LZString;
});

Binary file not shown.

View File

@ -878,7 +878,7 @@ Validating $E(m)$ is done with the proof of zero. Then it remains to prove that
\end{enumerate} \end{enumerate}
\end{protocol} \end{protocol}
The downside of this proof over the BCDG proof \cite{bcdg1987} is that the time to perform and verify this proof grows linearly with $|m|$. However, in most cases $|m|$ should be "small": i.e, $|m| \leq 6$, as Risk unit counts rarely exceed 64 on a single region. The downside of this proof over the BCDG proof \cite{bcdg1987} is that the time to perform and verify this proof grows linearly with $|m|$. However, in most cases $|m|$ should be "small": i.e, $|m| \leq 6$, as Risk unit counts rarely exceed 64 on a single region. In fact, to prevent revealing additional information from the bit length, this protocol in practice will pad out numbers to a minimum of 8 bits, which in our application makes this protocol constant time.
Range proof is used in points (3), (4), and (5). In (3), this is to convince other players that the number of units is sufficient for the action. In (4), this is to show that the region is not totally depleted. In (5), this is to ensure the number of units being fortified is less than the strength of the region. All of these are performed using \hyperref[protocol4]{Protocol~\ref*{protocol4}} and by using the additive homomorphic property to subtract the lower range from $m$ first. Range proof is used in points (3), (4), and (5). In (3), this is to convince other players that the number of units is sufficient for the action. In (4), this is to show that the region is not totally depleted. In (5), this is to ensure the number of units being fortified is less than the strength of the region. All of these are performed using \hyperref[protocol4]{Protocol~\ref*{protocol4}} and by using the additive homomorphic property to subtract the lower range from $m$ first.
@ -1093,7 +1093,7 @@ The interactive proof of zero uses two Paillier ciphertexts (each size $2|n|$),
On the other hand, the non-interactive variant needs not communicate the challenge (as it is computed as a function of other variables). So the non-interactive proof size is $5|n|$. On the other hand, the non-interactive variant needs not communicate the challenge (as it is computed as a function of other variables). So the non-interactive proof size is $5|n|$.
The non-interactive \hyperref[protocol1]{Protocol~\ref*{protocol1}} requires multiple rounds. Assume that we use 48 rounds: this provides a good level of soundness, with a cheat probability of $\left(\frac{1}{2}\right)^{-48} \approx 3.6 \times 10^{-15}$. Additionally, assume that there are five regions to verify. Each prover round then requires five Paillier ciphertexts, and each verifier round five non-interactive proofs of zero plus some negligible amount of additional storage for the bijection. The non-interactive \hyperref[protocol1]{Protocol~\ref*{protocol1}} requires multiple rounds. Assume that we use 48 rounds: this provides a good level of soundness, with a cheat probability of $\left(\frac{1}{2}\right)^{-48} \approx 3.6 \times 10^{-15}$. Additionally, assume that there are five regions to verify. Each prover round then requires five Paillier ciphertexts, and each verifier round five non-interactive proofs of zero plus some negligible amount of additional storage for the bijection.
This results in a proof size of $(10|n| + 10|n|) \times 48 = 960|n|$. For key size $|n| = 2048$, this is $240kB$. This is a fairly reasonable size for memory and network, but risks exceeding what can be placed within a processor's cache, leading to potential slowdown during verification. This results in a proof size of $(10|n| + 10|n|) \times 48 = 960|n|$. For key size $|n| = 2048$, this is 240kB. This is a fairly reasonable size for memory and network, but risks exceeding what can be placed within a processor's cache, leading to potential slowdown during verification.
This could be overcome by reducing the number of rounds, which comes at the cost of increasing the probability of cheating. In a protocol designed to only facilitate a single game session, this may be acceptable to the parties involved. For example, reducing the number of rounds to 24 will increase the chance of cheating to $\left(\frac{1}{2}\right)^{-24} \approx 6.0 \times 10^{-8}$, but the size would reduce by approximately half. This could be overcome by reducing the number of rounds, which comes at the cost of increasing the probability of cheating. In a protocol designed to only facilitate a single game session, this may be acceptable to the parties involved. For example, reducing the number of rounds to 24 will increase the chance of cheating to $\left(\frac{1}{2}\right)^{-24} \approx 6.0 \times 10^{-8}$, but the size would reduce by approximately half.
@ -1103,7 +1103,7 @@ Each of these calculations is in an ideal situation without compression or signa
\textbf{Message format.} Another solution is to use a more compact message format, for example msgpack \cite{msgpack} (which also has native support for binary literals). \textbf{Message format.} Another solution is to use a more compact message format, for example msgpack \cite{msgpack} (which also has native support for binary literals).
\textbf{Smaller key size.} The size of ciphertexts depends directly on the size of the key. Using a smaller key will reduce the size of the ciphertexts linearly. \textbf{Smaller key size.} The size of ciphertexts depends directly on the size of the key. Using a shorter key will reduce the size of the ciphertexts linearly.
\subsection{Time complexity} \subsection{Time complexity}
@ -1293,7 +1293,7 @@ Using a language that can interact with the operating system would have further
The P2P implementation requires more processing power and more bandwidth on each peer than a client-server implementation would. This is the main limitation of the P2P implementation. The program ran in a reasonable time, using a reasonable amount of resources on the computers I had access to, but these are not representative of the majority of computers in use today. Using greater processing power increases power consumption, which is undesirable. In a client-server implementation, the power consumption should be lower than the P2P implementation presented as no processing time is spent validating proofs or using the Paillier cryptosystem, which is less efficient than the hybrid cryptosystems used in standard online communication. The P2P implementation requires more processing power and more bandwidth on each peer than a client-server implementation would. This is the main limitation of the P2P implementation. The program ran in a reasonable time, using a reasonable amount of resources on the computers I had access to, but these are not representative of the majority of computers in use today. Using greater processing power increases power consumption, which is undesirable. In a client-server implementation, the power consumption should be lower than the P2P implementation presented as no processing time is spent validating proofs or using the Paillier cryptosystem, which is less efficient than the hybrid cryptosystems used in standard online communication.
\emph{Final word count: 9,088} \emph{Final word count: 9,166}
\bibliography{Dissertation} \bibliography{Dissertation}