Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
xorcipher
(version: 0)
Comparing performance of:
encode vs decode
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var _a = [ Symbol(), Symbol(), Symbol(), Symbol(), Symbol(), String.fromCharCode, Math.floor, 'indexOf', 'charAt', 'charCodeAt', Symbol(), Symbol(), ], bdec = _a[0], benc = _a[1], keyc = _a[2], xore = _a[3], xord = _a[4], fcc = _a[5], mf = _a[6], io = _a[7], ca = _a[8], cca = _a[9], cdd = _a[10], dce = _a[11]; var XORCipher = /** @class */ (function () { function XORCipher() { var l = eval("new Array( 26 ).fill( 1 ).map( ( _, i ) => String.fromCharCode( 65 + i ) ).reverse().join('');"); var d = l.toLowerCase(); var i = eval("[...Array(20).keys()].reverse().join('');"); this.t = eval("'=/+" + i + d + l + "'.split('').reverse().join('')"); } // decode XORCipher.prototype[cdd] = function (key, data) { return this[xord](key, this[bdec](data)).join(''); }; // encode XORCipher.prototype[dce] = function (key, data) { return this[benc](this[xore](key, data)); }; XORCipher.prototype[benc] = function (data) { var o1, o2, o3, h1, h2, h3, h4, bits, r, i = 0, enc = ''; if (!data) { return data; } do { o1 = data[i++]; o2 = data[i++]; o3 = data[i++]; bits = o1 << 16 | o2 << 8 | o3; h1 = bits >> 18 & 0x3f; h2 = bits >> 12 & 0x3f; h3 = bits >> 6 & 0x3f; h4 = bits & 0x3f; var t = this.t; enc += "" + t[ca](h1) + t[ca](h2) + t[ca](h3) + t[ca](h4); } while (i < data.length); r = data.length % 3; return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); }; XORCipher.prototype[bdec] = function (data) { var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, result = []; if (!data) { return data; } data += ''; do { var t = this.t; h1 = t[io](data[ca](i++)); h2 = t[io](data[ca](i++)); h3 = t[io](data[ca](i++)); h4 = t[io](data[ca](i++)); bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; o1 = bits >> 16 & 0xff; o2 = bits >> 8 & 0xff; o3 = bits & 0xff; result.push(o1); if (h3 !== 64) { result.push(o2); if (h4 !== 64) { result.push(o3); } } } while (i < data.length); return result; }; XORCipher.prototype[keyc] = function (key, i) { return key[cca](mf(i % key.length)); }; XORCipher.prototype[xore] = function (key, data) { var result = [], index = 0; for (var _i = 0, data_1 = data; _i < data_1.length; _i++) { var val = data_1[_i]; var e = val[cca](0) ^ this[keyc](key, index); result.push(e); ++index; } return result; }; XORCipher.prototype[xord] = function (key, data) { var result = [], index = 0; for (var _i = 0, data_2 = data; _i < data_2.length; _i++) { var val = data_2[_i]; var e = fcc(val ^ this[keyc](key, index)); result.push(e); ++index; } return result; }; return XORCipher; }());
Tests:
encode
var z = new XORCipher(); var enc = z[dce]('test', 'jashka'); console.log('enc', enc);
decode
var z = new XORCipher(); var dec = z[cdd]('test', 'HgQAHB8E'); console.log('dec', dec);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
encode
decode
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **Benchmark Overview** The benchmark is for an XOR cipher encryption algorithm, which is a simple substitution cipher that uses bitwise XOR (exclusive OR) to encrypt and decrypt data. **Script Preparation Code** The script preparation code defines several variables: * `_a`: an array of functions (`bdec`, `benc`, `keyc`, `xore`, `fcc`, `mf`, `io`, `ca`, `cca`, `cdd`) that will be used in the benchmark. * `bdec` and `benc`: inverse encoding and decoding functions, respectively. * `keyc`: a function to perform key-dependent calculations. * `xore` and `xord`: XOR-based encryption and decryption functions, respectively. * `fcc`: a function to perform bitwise XOR operations with a fixed constant. **Benchmark Definition** The benchmark definition is represented as an array of two objects: 1. "encode": * Creates a new instance of the XORCipher class. * Calls the `dce` method on the instance to encrypt the string 'test' using the key 'test'. * Prints the resulting encrypted string to the console. 2. "decode": * Creates a new instance of the XORCipher class. * Calls the `cdd` method on the instance to decrypt the string 'HgQAHB8E' using the key 'test'. * Prints the resulting decrypted string to the console. **Latest Benchmark Results** The latest benchmark results show the execution counts for each test case: 1. "encode": * Chrome 67 (Desktop, Windows) with an execution count of 13,088. 2. "decode": * Chrome 67 (Desktop, Windows) with an execution count of 12,805. **Analysis** The benchmark measures the performance of the XOR cipher algorithm in terms of the number of executions per second. The results indicate that the encryption process is slightly faster than the decryption process. In terms of optimization opportunities, some potential avenues could be: * Using more efficient algorithms for key-dependent calculations (e.g., using tables or precomputed values). * Optimizing the `xore` and `xord` functions to reduce branching and improve cache locality. * Using SIMD instructions (e.g., SSE or AVX) to perform multiple operations simultaneously. Overall, the benchmark provides a basic understanding of the performance characteristics of the XOR cipher algorithm, which can be used as a starting point for further optimization efforts.
Related benchmarks:
Lodash _.some vs _.includes vs array.find
IndexOf vs Includes vs lodash includes vs dictionary with large array
lodash _.some vs Array.some
lodash xor / sets / includes perf
Comments
Confirm delete:
Do you really want to delete benchmark?