How to use rotr method in wpt

Best JavaScript code snippet using wpt

sha512.js

Source:sha512.js Github

copy

Full Screen

1/**2 * Secure Hash Algorithm with a 1024-bit block size implementation.3 *4 * This includes: SHA-512, SHA-384, SHA-512/224, and SHA-512/256. For5 * SHA-256 (block size 512 bits), see sha256.js.6 *7 * See FIPS 180-4 for details.8 *9 * @author Dave Longley10 *11 * Copyright (c) 2014-2015 Digital Bazaar, Inc.12 */13var forge = require('./forge');14require('./md');15require('./util');16var sha512 = module.exports = forge.sha512 = forge.sha512 || {};17// SHA-51218forge.md.sha512 = forge.md.algorithms.sha512 = sha512;19// SHA-38420var sha384 = forge.sha384 = forge.sha512.sha384 = forge.sha512.sha384 || {};21sha384.create = function() {22 return sha512.create('SHA-384');23};24forge.md.sha384 = forge.md.algorithms.sha384 = sha384;25// SHA-512/25626forge.sha512.sha256 = forge.sha512.sha256 || {27 create: function() {28 return sha512.create('SHA-512/256');29 }30};31forge.md['sha512/256'] = forge.md.algorithms['sha512/256'] =32 forge.sha512.sha256;33// SHA-512/22434forge.sha512.sha224 = forge.sha512.sha224 || {35 create: function() {36 return sha512.create('SHA-512/224');37 }38};39forge.md['sha512/224'] = forge.md.algorithms['sha512/224'] =40 forge.sha512.sha224;41/**42 * Creates a SHA-2 message digest object.43 *44 * @param algorithm the algorithm to use (SHA-512, SHA-384, SHA-512/224,45 * SHA-512/256).46 *47 * @return a message digest object.48 */49sha512.create = function(algorithm) {50 // do initialization as necessary51 if(!_initialized) {52 _init();53 }54 if(typeof algorithm === 'undefined') {55 algorithm = 'SHA-512';56 }57 if(!(algorithm in _states)) {58 throw new Error('Invalid SHA-512 algorithm: ' + algorithm);59 }60 // SHA-512 state contains eight 64-bit integers (each as two 32-bit ints)61 var _state = _states[algorithm];62 var _h = null;63 // input buffer64 var _input = forge.util.createBuffer();65 // used for 64-bit word storage66 var _w = new Array(80);67 for(var wi = 0; wi < 80; ++wi) {68 _w[wi] = new Array(2);69 }70 // determine digest length by algorithm name (default)71 var digestLength = 64;72 switch (algorithm) {73 case 'SHA-384':74 digestLength = 48;75 break;76 case 'SHA-512/256':77 digestLength = 32;78 break;79 case 'SHA-512/224':80 digestLength = 28;81 break;82 }83 // message digest object84 var md = {85 // SHA-512 => sha51286 algorithm: algorithm.replace('-', '').toLowerCase(),87 blockLength: 128,88 digestLength: digestLength,89 // 56-bit length of message so far (does not including padding)90 messageLength: 0,91 // true message length92 fullMessageLength: null,93 // size of message length in bytes94 messageLengthSize: 1695 };96 /**97 * Starts the digest.98 *99 * @return this digest object.100 */101 md.start = function() {102 // up to 56-bit message length for convenience103 md.messageLength = 0;104 // full message length (set md.messageLength128 for backwards-compatibility)105 md.fullMessageLength = md.messageLength128 = [];106 var int32s = md.messageLengthSize / 4;107 for(var i = 0; i < int32s; ++i) {108 md.fullMessageLength.push(0);109 }110 _input = forge.util.createBuffer();111 _h = new Array(_state.length);112 for(var i = 0; i < _state.length; ++i) {113 _h[i] = _state[i].slice(0);114 }115 return md;116 };117 // start digest automatically for first time118 md.start();119 /**120 * Updates the digest with the given message input. The given input can121 * treated as raw input (no encoding will be applied) or an encoding of122 * 'utf8' maybe given to encode the input using UTF-8.123 *124 * @param msg the message input to update with.125 * @param encoding the encoding to use (default: 'raw', other: 'utf8').126 *127 * @return this digest object.128 */129 md.update = function(msg, encoding) {130 if(encoding === 'utf8') {131 msg = forge.util.encodeUtf8(msg);132 }133 // update message length134 var len = msg.length;135 md.messageLength += len;136 len = [(len / 0x100000000) >>> 0, len >>> 0];137 for(var i = md.fullMessageLength.length - 1; i >= 0; --i) {138 md.fullMessageLength[i] += len[1];139 len[1] = len[0] + ((md.fullMessageLength[i] / 0x100000000) >>> 0);140 md.fullMessageLength[i] = md.fullMessageLength[i] >>> 0;141 len[0] = ((len[1] / 0x100000000) >>> 0);142 }143 // add bytes to input buffer144 _input.putBytes(msg);145 // process bytes146 _update(_h, _w, _input);147 // compact input buffer every 2K or if empty148 if(_input.read > 2048 || _input.length() === 0) {149 _input.compact();150 }151 return md;152 };153 /**154 * Produces the digest.155 *156 * @return a byte buffer containing the digest value.157 */158 md.digest = function() {159 /* Note: Here we copy the remaining bytes in the input buffer and160 add the appropriate SHA-512 padding. Then we do the final update161 on a copy of the state so that if the user wants to get162 intermediate digests they can do so. */163 /* Determine the number of bytes that must be added to the message164 to ensure its length is congruent to 896 mod 1024. In other words,165 the data to be digested must be a multiple of 1024 bits (or 128 bytes).166 This data includes the message, some padding, and the length of the167 message. Since the length of the message will be encoded as 16 bytes (128168 bits), that means that the last segment of the data must have 112 bytes169 (896 bits) of message and padding. Therefore, the length of the message170 plus the padding must be congruent to 896 mod 1024 because171 1024 - 128 = 896.172 In order to fill up the message length it must be filled with173 padding that begins with 1 bit followed by all 0 bits. Padding174 must *always* be present, so if the message length is already175 congruent to 896 mod 1024, then 1024 padding bits must be added. */176 var finalBlock = forge.util.createBuffer();177 finalBlock.putBytes(_input.bytes());178 // compute remaining size to be digested (include message length size)179 var remaining = (180 md.fullMessageLength[md.fullMessageLength.length - 1] +181 md.messageLengthSize);182 // add padding for overflow blockSize - overflow183 // _padding starts with 1 byte with first bit is set (byte value 128), then184 // there may be up to (blockSize - 1) other pad bytes185 var overflow = remaining & (md.blockLength - 1);186 finalBlock.putBytes(_padding.substr(0, md.blockLength - overflow));187 // serialize message length in bits in big-endian order; since length188 // is stored in bytes we multiply by 8 and add carry from next int189 var next, carry;190 var bits = md.fullMessageLength[0] * 8;191 for(var i = 0; i < md.fullMessageLength.length - 1; ++i) {192 next = md.fullMessageLength[i + 1] * 8;193 carry = (next / 0x100000000) >>> 0;194 bits += carry;195 finalBlock.putInt32(bits >>> 0);196 bits = next >>> 0;197 }198 finalBlock.putInt32(bits);199 var h = new Array(_h.length);200 for(var i = 0; i < _h.length; ++i) {201 h[i] = _h[i].slice(0);202 }203 _update(h, _w, finalBlock);204 var rval = forge.util.createBuffer();205 var hlen;206 if(algorithm === 'SHA-512') {207 hlen = h.length;208 } else if(algorithm === 'SHA-384') {209 hlen = h.length - 2;210 } else {211 hlen = h.length - 4;212 }213 for(var i = 0; i < hlen; ++i) {214 rval.putInt32(h[i][0]);215 if(i !== hlen - 1 || algorithm !== 'SHA-512/224') {216 rval.putInt32(h[i][1]);217 }218 }219 return rval;220 };221 return md;222};223// sha-512 padding bytes not initialized yet224var _padding = null;225var _initialized = false;226// table of constants227var _k = null;228// initial hash states229var _states = null;230/**231 * Initializes the constant tables.232 */233function _init() {234 // create padding235 _padding = String.fromCharCode(128);236 _padding += forge.util.fillString(String.fromCharCode(0x00), 128);237 // create K table for SHA-512238 _k = [239 [0x428a2f98, 0xd728ae22], [0x71374491, 0x23ef65cd],240 [0xb5c0fbcf, 0xec4d3b2f], [0xe9b5dba5, 0x8189dbbc],241 [0x3956c25b, 0xf348b538], [0x59f111f1, 0xb605d019],242 [0x923f82a4, 0xaf194f9b], [0xab1c5ed5, 0xda6d8118],243 [0xd807aa98, 0xa3030242], [0x12835b01, 0x45706fbe],244 [0x243185be, 0x4ee4b28c], [0x550c7dc3, 0xd5ffb4e2],245 [0x72be5d74, 0xf27b896f], [0x80deb1fe, 0x3b1696b1],246 [0x9bdc06a7, 0x25c71235], [0xc19bf174, 0xcf692694],247 [0xe49b69c1, 0x9ef14ad2], [0xefbe4786, 0x384f25e3],248 [0x0fc19dc6, 0x8b8cd5b5], [0x240ca1cc, 0x77ac9c65],249 [0x2de92c6f, 0x592b0275], [0x4a7484aa, 0x6ea6e483],250 [0x5cb0a9dc, 0xbd41fbd4], [0x76f988da, 0x831153b5],251 [0x983e5152, 0xee66dfab], [0xa831c66d, 0x2db43210],252 [0xb00327c8, 0x98fb213f], [0xbf597fc7, 0xbeef0ee4],253 [0xc6e00bf3, 0x3da88fc2], [0xd5a79147, 0x930aa725],254 [0x06ca6351, 0xe003826f], [0x14292967, 0x0a0e6e70],255 [0x27b70a85, 0x46d22ffc], [0x2e1b2138, 0x5c26c926],256 [0x4d2c6dfc, 0x5ac42aed], [0x53380d13, 0x9d95b3df],257 [0x650a7354, 0x8baf63de], [0x766a0abb, 0x3c77b2a8],258 [0x81c2c92e, 0x47edaee6], [0x92722c85, 0x1482353b],259 [0xa2bfe8a1, 0x4cf10364], [0xa81a664b, 0xbc423001],260 [0xc24b8b70, 0xd0f89791], [0xc76c51a3, 0x0654be30],261 [0xd192e819, 0xd6ef5218], [0xd6990624, 0x5565a910],262 [0xf40e3585, 0x5771202a], [0x106aa070, 0x32bbd1b8],263 [0x19a4c116, 0xb8d2d0c8], [0x1e376c08, 0x5141ab53],264 [0x2748774c, 0xdf8eeb99], [0x34b0bcb5, 0xe19b48a8],265 [0x391c0cb3, 0xc5c95a63], [0x4ed8aa4a, 0xe3418acb],266 [0x5b9cca4f, 0x7763e373], [0x682e6ff3, 0xd6b2b8a3],267 [0x748f82ee, 0x5defb2fc], [0x78a5636f, 0x43172f60],268 [0x84c87814, 0xa1f0ab72], [0x8cc70208, 0x1a6439ec],269 [0x90befffa, 0x23631e28], [0xa4506ceb, 0xde82bde9],270 [0xbef9a3f7, 0xb2c67915], [0xc67178f2, 0xe372532b],271 [0xca273ece, 0xea26619c], [0xd186b8c7, 0x21c0c207],272 [0xeada7dd6, 0xcde0eb1e], [0xf57d4f7f, 0xee6ed178],273 [0x06f067aa, 0x72176fba], [0x0a637dc5, 0xa2c898a6],274 [0x113f9804, 0xbef90dae], [0x1b710b35, 0x131c471b],275 [0x28db77f5, 0x23047d84], [0x32caab7b, 0x40c72493],276 [0x3c9ebe0a, 0x15c9bebc], [0x431d67c4, 0x9c100d4c],277 [0x4cc5d4be, 0xcb3e42b6], [0x597f299c, 0xfc657e2a],278 [0x5fcb6fab, 0x3ad6faec], [0x6c44198c, 0x4a475817]279 ];280 // initial hash states281 _states = {};282 _states['SHA-512'] = [283 [0x6a09e667, 0xf3bcc908],284 [0xbb67ae85, 0x84caa73b],285 [0x3c6ef372, 0xfe94f82b],286 [0xa54ff53a, 0x5f1d36f1],287 [0x510e527f, 0xade682d1],288 [0x9b05688c, 0x2b3e6c1f],289 [0x1f83d9ab, 0xfb41bd6b],290 [0x5be0cd19, 0x137e2179]291 ];292 _states['SHA-384'] = [293 [0xcbbb9d5d, 0xc1059ed8],294 [0x629a292a, 0x367cd507],295 [0x9159015a, 0x3070dd17],296 [0x152fecd8, 0xf70e5939],297 [0x67332667, 0xffc00b31],298 [0x8eb44a87, 0x68581511],299 [0xdb0c2e0d, 0x64f98fa7],300 [0x47b5481d, 0xbefa4fa4]301 ];302 _states['SHA-512/256'] = [303 [0x22312194, 0xFC2BF72C],304 [0x9F555FA3, 0xC84C64C2],305 [0x2393B86B, 0x6F53B151],306 [0x96387719, 0x5940EABD],307 [0x96283EE2, 0xA88EFFE3],308 [0xBE5E1E25, 0x53863992],309 [0x2B0199FC, 0x2C85B8AA],310 [0x0EB72DDC, 0x81C52CA2]311 ];312 _states['SHA-512/224'] = [313 [0x8C3D37C8, 0x19544DA2],314 [0x73E19966, 0x89DCD4D6],315 [0x1DFAB7AE, 0x32FF9C82],316 [0x679DD514, 0x582F9FCF],317 [0x0F6D2B69, 0x7BD44DA8],318 [0x77E36F73, 0x04C48942],319 [0x3F9D85A8, 0x6A1D36C8],320 [0x1112E6AD, 0x91D692A1]321 ];322 // now initialized323 _initialized = true;324}325/**326 * Updates a SHA-512 state with the given byte buffer.327 *328 * @param s the SHA-512 state to update.329 * @param w the array to use to store words.330 * @param bytes the byte buffer to update with.331 */332function _update(s, w, bytes) {333 // consume 512 bit (128 byte) chunks334 var t1_hi, t1_lo;335 var t2_hi, t2_lo;336 var s0_hi, s0_lo;337 var s1_hi, s1_lo;338 var ch_hi, ch_lo;339 var maj_hi, maj_lo;340 var a_hi, a_lo;341 var b_hi, b_lo;342 var c_hi, c_lo;343 var d_hi, d_lo;344 var e_hi, e_lo;345 var f_hi, f_lo;346 var g_hi, g_lo;347 var h_hi, h_lo;348 var i, hi, lo, w2, w7, w15, w16;349 var len = bytes.length();350 while(len >= 128) {351 // the w array will be populated with sixteen 64-bit big-endian words352 // and then extended into 64 64-bit words according to SHA-512353 for(i = 0; i < 16; ++i) {354 w[i][0] = bytes.getInt32() >>> 0;355 w[i][1] = bytes.getInt32() >>> 0;356 }357 for(; i < 80; ++i) {358 // for word 2 words ago: ROTR 19(x) ^ ROTR 61(x) ^ SHR 6(x)359 w2 = w[i - 2];360 hi = w2[0];361 lo = w2[1];362 // high bits363 t1_hi = (364 ((hi >>> 19) | (lo << 13)) ^ // ROTR 19365 ((lo >>> 29) | (hi << 3)) ^ // ROTR 61/(swap + ROTR 29)366 (hi >>> 6)) >>> 0; // SHR 6367 // low bits368 t1_lo = (369 ((hi << 13) | (lo >>> 19)) ^ // ROTR 19370 ((lo << 3) | (hi >>> 29)) ^ // ROTR 61/(swap + ROTR 29)371 ((hi << 26) | (lo >>> 6))) >>> 0; // SHR 6372 // for word 15 words ago: ROTR 1(x) ^ ROTR 8(x) ^ SHR 7(x)373 w15 = w[i - 15];374 hi = w15[0];375 lo = w15[1];376 // high bits377 t2_hi = (378 ((hi >>> 1) | (lo << 31)) ^ // ROTR 1379 ((hi >>> 8) | (lo << 24)) ^ // ROTR 8380 (hi >>> 7)) >>> 0; // SHR 7381 // low bits382 t2_lo = (383 ((hi << 31) | (lo >>> 1)) ^ // ROTR 1384 ((hi << 24) | (lo >>> 8)) ^ // ROTR 8385 ((hi << 25) | (lo >>> 7))) >>> 0; // SHR 7386 // sum(t1, word 7 ago, t2, word 16 ago) modulo 2^64 (carry lo overflow)387 w7 = w[i - 7];388 w16 = w[i - 16];389 lo = (t1_lo + w7[1] + t2_lo + w16[1]);390 w[i][0] = (t1_hi + w7[0] + t2_hi + w16[0] +391 ((lo / 0x100000000) >>> 0)) >>> 0;392 w[i][1] = lo >>> 0;393 }394 // initialize hash value for this chunk395 a_hi = s[0][0];396 a_lo = s[0][1];397 b_hi = s[1][0];398 b_lo = s[1][1];399 c_hi = s[2][0];400 c_lo = s[2][1];401 d_hi = s[3][0];402 d_lo = s[3][1];403 e_hi = s[4][0];404 e_lo = s[4][1];405 f_hi = s[5][0];406 f_lo = s[5][1];407 g_hi = s[6][0];408 g_lo = s[6][1];409 h_hi = s[7][0];410 h_lo = s[7][1];411 // round function412 for(i = 0; i < 80; ++i) {413 // Sum1(e) = ROTR 14(e) ^ ROTR 18(e) ^ ROTR 41(e)414 s1_hi = (415 ((e_hi >>> 14) | (e_lo << 18)) ^ // ROTR 14416 ((e_hi >>> 18) | (e_lo << 14)) ^ // ROTR 18417 ((e_lo >>> 9) | (e_hi << 23))) >>> 0; // ROTR 41/(swap + ROTR 9)418 s1_lo = (419 ((e_hi << 18) | (e_lo >>> 14)) ^ // ROTR 14420 ((e_hi << 14) | (e_lo >>> 18)) ^ // ROTR 18421 ((e_lo << 23) | (e_hi >>> 9))) >>> 0; // ROTR 41/(swap + ROTR 9)422 // Ch(e, f, g) (optimized the same way as SHA-1)423 ch_hi = (g_hi ^ (e_hi & (f_hi ^ g_hi))) >>> 0;424 ch_lo = (g_lo ^ (e_lo & (f_lo ^ g_lo))) >>> 0;425 // Sum0(a) = ROTR 28(a) ^ ROTR 34(a) ^ ROTR 39(a)426 s0_hi = (427 ((a_hi >>> 28) | (a_lo << 4)) ^ // ROTR 28428 ((a_lo >>> 2) | (a_hi << 30)) ^ // ROTR 34/(swap + ROTR 2)429 ((a_lo >>> 7) | (a_hi << 25))) >>> 0; // ROTR 39/(swap + ROTR 7)430 s0_lo = (431 ((a_hi << 4) | (a_lo >>> 28)) ^ // ROTR 28432 ((a_lo << 30) | (a_hi >>> 2)) ^ // ROTR 34/(swap + ROTR 2)433 ((a_lo << 25) | (a_hi >>> 7))) >>> 0; // ROTR 39/(swap + ROTR 7)434 // Maj(a, b, c) (optimized the same way as SHA-1)435 maj_hi = ((a_hi & b_hi) | (c_hi & (a_hi ^ b_hi))) >>> 0;436 maj_lo = ((a_lo & b_lo) | (c_lo & (a_lo ^ b_lo))) >>> 0;437 // main algorithm438 // t1 = (h + s1 + ch + _k[i] + _w[i]) modulo 2^64 (carry lo overflow)439 lo = (h_lo + s1_lo + ch_lo + _k[i][1] + w[i][1]);440 t1_hi = (h_hi + s1_hi + ch_hi + _k[i][0] + w[i][0] +441 ((lo / 0x100000000) >>> 0)) >>> 0;442 t1_lo = lo >>> 0;443 // t2 = s0 + maj modulo 2^64 (carry lo overflow)444 lo = s0_lo + maj_lo;445 t2_hi = (s0_hi + maj_hi + ((lo / 0x100000000) >>> 0)) >>> 0;446 t2_lo = lo >>> 0;447 h_hi = g_hi;448 h_lo = g_lo;449 g_hi = f_hi;450 g_lo = f_lo;451 f_hi = e_hi;452 f_lo = e_lo;453 // e = (d + t1) modulo 2^64 (carry lo overflow)454 lo = d_lo + t1_lo;455 e_hi = (d_hi + t1_hi + ((lo / 0x100000000) >>> 0)) >>> 0;456 e_lo = lo >>> 0;457 d_hi = c_hi;458 d_lo = c_lo;459 c_hi = b_hi;460 c_lo = b_lo;461 b_hi = a_hi;462 b_lo = a_lo;463 // a = (t1 + t2) modulo 2^64 (carry lo overflow)464 lo = t1_lo + t2_lo;465 a_hi = (t1_hi + t2_hi + ((lo / 0x100000000) >>> 0)) >>> 0;466 a_lo = lo >>> 0;467 }468 // update hash state (additional modulo 2^64)469 lo = s[0][1] + a_lo;470 s[0][0] = (s[0][0] + a_hi + ((lo / 0x100000000) >>> 0)) >>> 0;471 s[0][1] = lo >>> 0;472 lo = s[1][1] + b_lo;473 s[1][0] = (s[1][0] + b_hi + ((lo / 0x100000000) >>> 0)) >>> 0;474 s[1][1] = lo >>> 0;475 lo = s[2][1] + c_lo;476 s[2][0] = (s[2][0] + c_hi + ((lo / 0x100000000) >>> 0)) >>> 0;477 s[2][1] = lo >>> 0;478 lo = s[3][1] + d_lo;479 s[3][0] = (s[3][0] + d_hi + ((lo / 0x100000000) >>> 0)) >>> 0;480 s[3][1] = lo >>> 0;481 lo = s[4][1] + e_lo;482 s[4][0] = (s[4][0] + e_hi + ((lo / 0x100000000) >>> 0)) >>> 0;483 s[4][1] = lo >>> 0;484 lo = s[5][1] + f_lo;485 s[5][0] = (s[5][0] + f_hi + ((lo / 0x100000000) >>> 0)) >>> 0;486 s[5][1] = lo >>> 0;487 lo = s[6][1] + g_lo;488 s[6][0] = (s[6][0] + g_hi + ((lo / 0x100000000) >>> 0)) >>> 0;489 s[6][1] = lo >>> 0;490 lo = s[7][1] + h_lo;491 s[7][0] = (s[7][0] + h_hi + ((lo / 0x100000000) >>> 0)) >>> 0;492 s[7][1] = lo >>> 0;493 len -= 128;494 }...

Full Screen

Full Screen

SHA256.js

Source:SHA256.js Github

copy

Full Screen

1(function () {2 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */3 /* SHA-256 implementation in JavaScript (c) Chris Veness 2005-2009 */4 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */5 function sha256Hash(msg) {6 // constants [§4.2.2]7 var K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,8 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,9 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,10 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,11 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,12 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,13 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,14 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];15 // initial hash value [§5.3.1]16 var H = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];17 // PREPROCESSING 18 msg += String.fromCharCode(0x80); // add trailing '1' bit (+ 0's padding) to string [§5.1.1]19 // convert string msg into 512-bit/16-integer blocks arrays of ints [§5.2.1]20 var l = msg.length / 4 + 2; // length (in 32-bit integers) of msg + ‘1’ + appended length21 var N = Math.ceil(l / 16); // number of 16-integer-blocks required to hold 'l' ints22 var M = new Array(N);23 for (var i = 0; i < N; i++) {24 M[i] = new Array(16);25 for (var j = 0; j < 16; j++) { // encode 4 chars per integer, big-endian encoding26 M[i][j] = (msg.charCodeAt(i * 64 + j * 4) << 24) | (msg.charCodeAt(i * 64 + j * 4 + 1) << 16) |27 (msg.charCodeAt(i * 64 + j * 4 + 2) << 8) | (msg.charCodeAt(i * 64 + j * 4 + 3));28 } // note running off the end of msg is ok 'cos bitwise ops on NaN return 029 }30 // add length (in bits) into final pair of 32-bit integers (big-endian) [§5.1.1]31 // note: most significant word would be (len-1)*8 >>> 32, but since JS converts32 // bitwise-op args to 32 bits, we need to simulate this by arithmetic operators33 M[N - 1][14] = ((msg.length - 1) * 8) / Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14])34 M[N - 1][15] = ((msg.length - 1) * 8) & 0xffffffff;35 // HASH COMPUTATION [§6.1.2]36 var W = new Array(64); var a, b, c, d, e, f, g, h;37 for (var i = 0; i < N; i++) {38 // 1 - prepare message schedule 'W'39 for (var t = 0; t < 16; t++) W[t] = M[i][t];40 for (var t = 16; t < 64; t++) W[t] = (sigma1(W[t - 2]) + W[t - 7] + sigma0(W[t - 15]) + W[t - 16]) & 0xffffffff;41 // 2 - initialise five working variables a, b, c, d, e with previous hash value42 a = H[0]; b = H[1]; c = H[2]; d = H[3]; e = H[4]; f = H[5]; g = H[6]; h = H[7];43 // 3 - main loop (note 'addition modulo 2^32')44 for (var t = 0; t < 64; t++) {45 var T1 = h + Sigma1(e) + Ch(e, f, g) + K[t] + W[t];46 var T2 = Sigma0(a) + Maj(a, b, c);47 h = g;48 g = f;49 f = e;50 e = (d + T1) & 0xffffffff;51 d = c;52 c = b;53 b = a;54 a = (T1 + T2) & 0xffffffff;55 }56 // 4 - compute the new intermediate hash value (note 'addition modulo 2^32')57 H[0] = (H[0] + a) & 0xffffffff;58 H[1] = (H[1] + b) & 0xffffffff;59 H[2] = (H[2] + c) & 0xffffffff;60 H[3] = (H[3] + d) & 0xffffffff;61 H[4] = (H[4] + e) & 0xffffffff;62 H[5] = (H[5] + f) & 0xffffffff;63 H[6] = (H[6] + g) & 0xffffffff;64 H[7] = (H[7] + h) & 0xffffffff;65 }66 return H[0].toHexStr() + H[1].toHexStr() + H[2].toHexStr() + H[3].toHexStr() +67 H[4].toHexStr() + H[5].toHexStr() + H[6].toHexStr() + H[7].toHexStr();68 }69 function ROTR(n, x) { return (x >>> n) | (x << (32 - n)); }70 function Sigma0(x) { return ROTR(2, x) ^ ROTR(13, x) ^ ROTR(22, x); }71 function Sigma1(x) { return ROTR(6, x) ^ ROTR(11, x) ^ ROTR(25, x); }72 function sigma0(x) { return ROTR(7, x) ^ ROTR(18, x) ^ (x >>> 3); }73 function sigma1(x) { return ROTR(17, x) ^ ROTR(19, x) ^ (x >>> 10); }74 function Ch(x, y, z) { return (x & y) ^ (~x & z); }75 function Maj(x, y, z) { return (x & y) ^ (x & z) ^ (y & z); }76 //77 // extend Number class with a tailored hex-string method 78 // (note toString(16) is implementation-dependant, and 79 // in IE returns signed numbers when used on full words)80 //81 Number.prototype.toHexStr = function () {82 var s = "", v;83 for (var i = 7; i >= 0; i--) { v = (this >>> (i * 4)) & 0xf; s += v.toString(16); }84 return s;85 }86 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */87 _.mixin({88 sha256: function (val) {89 return sha256Hash(val);90 }91 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var readline = require('readline');4var rl = readline.createInterface({5 input: fs.createReadStream('test.txt')6});7rl.on('line', function (line) {8 wptools.page(line).get(function(err, page) {9 console.log(page.data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools')2wptools.page('Barack Obama').then(function(page) {3 return page.rotr()4}).then(function(data) {5 console.log(data)6})7var wptools = require('wptools')8wptools.page('Barack Obama').then(function(page) {9 return page.rotr()10}).then(function(data) {11 console.log(data)12})13var wptools = require('wptools')14wptools.page('Barack Obama').then(function(page) {15 return page.rotr()16}).then(function(data) {17 console.log(data)18})19var wptools = require('wptools')20wptools.page('Barack Obama').then(function(page) {21 return page.rotr()22}).then(function(data) {23 console.log(data)24})25var wptools = require('wptools')26wptools.page('Barack Obama').then(function(page) {27 return page.rotr()28}).then(function(data) {29 console.log(data)30})

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein')3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein')8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein')13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein')18page.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein')23page.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein')28page.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein')33page.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein')38page.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein')43page.get(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools('Barack Obama').rotr().get(function(err, data){3 console.log(data);4});5var wptools = require('wptools');6wptools('Barack Obama').rotr().get(function(err, data){7 console.log(data);8});9var wptools = require('wptools');10wptools('Barack Obama').rotr().get(function(err, data){11 console.log(data);12});13var wptools = require('wptools');14wptools('Barack Obama').rotr().get(function(err, data){15 console.log(data);16});17var wptools = require('wptools');18wptools('Barack Obama').rotr().get(function(err, data){19 console.log(data);20});21var wptools = require('wptools');22wptools('Barack Obama').rotr().get(function(err, data){23 console.log(data);24});25var wptools = require('wptools');26wptools('Barack Obama').rotr().get(function(err, data){27 console.log(data);28});29var wptools = require('wptools');30wptools('Barack Obama').rotr().get(function(err, data){31 console.log(data);32});33var wptools = require('wptools');34wptools('Barack Obama').rotr().get(function(err, data){35 console.log(data);36});37var wptools = require('wptools');38wptools('Barack Obama').rotr().get(function(err, data){39 console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpage-to-image');2var options = {3};4wpt.rotr(90, 'test.png', options, function (err, image) {5 if (err) {6 return console.log(err);7 }8 image.write('test_rotr.png', function (err) {9 if (err) {10 return console.log(err);11 }12 console.log('Image written to test_rotr.png');13 });14});15var wpt = require('webpage-to-image');16var options = {17};18wpt.crop(0, 0, 100, 100, 'test.png', options, function (err, image) {19 if (err) {20 return console.log(err);21 }22 image.write('test_crop.png', function (err) {23 if (err) {24 return console.log(err);25 }26 console.log('Image written to test_crop.png');27 });28});29var wpt = require('webpage-to-image');30var options = {31};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful