Calculates one block of CTR keystream
333738
def _calcCTRBUF(self):
        """"""
        self.ctr_cks = self.encrypt(struct.pack("Q", self.ctr_iv)) # keystream block
        self.ctr_iv += 1
        self.ctr_pos = 0
135411
function gPrga(key, s) {

  var keystream = [];
  var k = 0;
  var j = 0;
  var len = key.length;
  for (var i = 0; i < len; ++i) {
    k = (k + 1) % 256;
    j = (j + s[k]) % 256;
    s[j] = [ s[k], s[k] = s[j] ][0];
    keystream[i] = s[(s[k] + s[j]) % 256];
  }

  return keystream;
}
1224565
static int compareKeys(CharSequence key, ByteBuffer bytes, int offset) {
        for (int i = 0;; ++i, ++offset) {
            int c2 = bytes.get(offset);
            if (c2 == 0) {
                if (i == key.length()) {
                    return 0;
                } else {
                    return 1;  // key > table key because key is longer.
                }
            } else if (i == key.length()) {
                return -1;  // key < table key because key is shorter.
            }
            int diff = key.charAt(i) - c2;
            if (diff != 0) {
                return diff;
            }
        }
    }
1346893
private int getNumBlocks(R delta) {
        ByteBuffer content = getValue(delta);
        int numBlocks = 0;

        // build numBlocks by adding together each hex digit
        for (int i = 0; i < _prefixLength; i++) {
            byte b = content.get(i);
            numBlocks = numBlocks << 4 | (b <= '9' ? b - '0' : b - 'A' + 10);
        }

        return numBlocks;
    }
635960
def _xor_block(a, b):
    
    return ''.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])
91472
def _ctab_property_block(stream):
    
    line = stream.popleft()
    while line != 'M  END':
        name = line.split()[1]
        yield CtabPropertiesBlockLine(name, line)
        line = stream.popleft()
688788
function(key,size)
		{
			var expandedKeySize = (16*(this.numberOfRounds(size)+1));
			
			/* current expanded keySize, in bytes */
			var currentSize = 0;
			var rconIteration = 1;
			var t = [];   // temporary 4-byte variable
			
			var expandedKey = [];
			for(var i = 0;i < expandedKeySize;i++)
				expandedKey[i] = 0;
		
			/* set the 16,24,32 bytes of the expanded key to the input key */
			for (var j = 0; j < size; j++)
				expandedKey[j] = key[j];
			currentSize += size;
		
			while (currentSize < expandedKeySize)
			{
				/* assign the previous 4 bytes to the temporary value t */
				for (var k = 0; k < 4; k++)
					t[k] = expandedKey[(currentSize - 4) + k];
		
				/* every 16,24,32 bytes we apply the core schedule to t
				 * and increment rconIteration afterwards
				 */
				if(currentSize % size == 0)
					t = this.core(t, rconIteration++);
		
				/* For 256-bit keys, we add an extra sbox to the calculation */
				if(size == this.keySize.SIZE_256 && ((currentSize % size) == 16))
					for(var l = 0; l < 4; l++)
						t[l] = this.sbox[t[l]];
		
				/* We XOR t with the four-byte block 16,24,32 bytes before the new expanded key.
				 * This becomes the next four bytes in the expanded key.
				 */
				for(var m = 0; m < 4; m++) {
					expandedKey[currentSize] = expandedKey[currentSize - size] ^ t[m];
					currentSize++;
				}
			}
			return expandedKey;
		}
721622
private int keyColumnStart()
  {
    int offset = 0;
    
    for (int i = 0; i < _columns.length; i++) {
      if (offset == _keyStart) {
        return i;
      }
      
      offset += _columns[i].length();
    }
    
    throw new IllegalStateException();
  }
350211
function createKeyframeBlock(keyframe) {
                var
                    bufferStream = new ArrayBufferDataStream(1 + 2 + 1);
                
                if (!(keyframe.trackNumber > 0 && keyframe.trackNumber < 127)) {
                    throw "TrackNumber must be > 0 and < 127";
                }
    
                bufferStream.writeEBMLVarInt(keyframe.trackNumber); // Always 1 byte since we limit the range of trackNumber
                bufferStream.writeU16BE(keyframe.timecode);
                
                // Flags byte
                bufferStream.writeByte(
                    1 << 7 // Keyframe
                );
                
                return {
                    "id": 0xA3, // SimpleBlock
                    "data": [
                         bufferStream.getAsDataArray(),
                         keyframe.frame
                    ]
                };
            }
550617
private int findFirstDifferingBit(String key1, String key2) {
        int bit = 0;

        while (keyMapper.isSet(bit, key1) == keyMapper.isSet(bit, key2)) {
            bit++;
        }
        return bit;
    }
1219481
def decipher_block (self, state):
        """"""
        if len(state) != 16:
            Log.error(u"Expecting block of 16")

        self._add_round_key(state, self._Nr)

        for i in range(self._Nr - 1, 0, -1):
            self._i_shift_rows(state)
            self._i_sub_bytes(state)
            self._add_round_key(state, i)
            self._mix_columns(state, True)

        self._i_shift_rows(state)
        self._i_sub_bytes(state)
        self._add_round_key(state, 0)
        return state
886567
private static byte calculateLRC(byte[] data, int off, int length, int tailskip) {
        int lrc = 0;
        for (int i = off; i < length - tailskip; i++) {
            lrc += ((int) data[i]) & 0xFF;
        }
        return (byte) ((-lrc) & 0xff);
    }
830777
function checkKeyframesBlocks(i) {
  if (i >= tokensLength) return 0;

  const blockEnd = tokens[i].block_end;
  const start = i;
  let l;

  if (!blockEnd) return 0;

  if (l = checkSC(i)) i += l;

  if (l = checkKeyframesBlock(i)) i += l;

  while (i < blockEnd) {
    if (l = checkSC(i)) i += l;
    else if (l = checkKeyframesBlock(i)) i += l;
    else if (l = checkAtrule(i)) i += l;
    else break;
  }

  if (i !== blockEnd + 1) return 0;

  return blockEnd + 1 - start;
}
448525
def key_parts(key, &block)
      return enum_for(:key_parts, key) unless block
      nesting = PARENS
      counts  = PARENS_ZEROS # dup'd later if key contains parenthesis
      delim   = '.'
      from    = to = 0
      key.each_char do |char|
        if char == delim && PARENS_ZEROS == counts
          block.yield key[from...to]
          from = to = (to + 1)
        else
          nest_i, nest_inc = nesting[char]
          if nest_i
            counts = counts.dup if counts.frozen?
            counts[nest_i] += nest_inc
          end
          to += 1
        end
      end
      block.yield(key[from...to]) if from < to && to <= key.length
      true
    end
578357
function (prf, iterationCount) {

        var xor = function (l, r) {
            var i;
            for (i = 0; i < l.length; i++) {
                l[i] = l[i] ^ r[i];
            }
            return l;
        };

        var _F = function (password, salt, iterationCount, i) {
            var k;
            var Ti = new Uint8Array(new ArrayBuffer(prf.hmacLength()));
            var U = new Uint8Array(new ArrayBuffer(salt.length + 4));
            U.set(salt, 0);
            U.set(convertToUInt32(i), salt.length);
            for (k = 1; k <= iterationCount; k++) {
                prf.setKey(password);
                prf.update(U);
                U = new Uint8Array(prf.finalize());
                Ti = xor(Ti, U);
            }
            return Ti;
        };

        var derive = function (password, salt, len) {
            var i, l, tmpBuf;
            if (len > prf.hmacLength() * 0xFFFFFFFF) {
                throw "Derived key length too long";
            }
            l = Math.ceil(len / prf.hmacLength());
            tmpBuf = new Uint8Array(new ArrayBuffer(len * prf.hmacLength()));
            for (i = 1; i <= l; i++) {
                tmpBuf.set(_F(password, salt, iterationCount, i), prf.hmacLength() * (i - 1));
            }
            return tmpBuf.buffer.slice(0, len);
        };

        return {
            deriveKey: function (password, salt, len) {
                return derive(convertToUint8Array(password), convertToUint8Array(salt), len);
            }
        };
    }
299525
function lockCrc(inputStr){

		res = 0xff;
		inputHex = new Buffer(inputStr,'hex');

		//start from the second byte 
		for (i = 1; i<= inputHex.length; i++) {
			res = res ^ inputHex[i];
		}
		//add padding
		reshex = (res+0x100).toString(16).substr(-2);
//		console.log(reshex);

		return(inputStr+reshex);
}
882431
void getBlockCrc(DataInputStream in, VersionAndOpcode versionAndOpcode)
      throws IOException {
    // header
    BlockChecksumHeader blockChecksumHeader =
        new BlockChecksumHeader(versionAndOpcode);
    blockChecksumHeader.readFields(in);
    final int namespaceId = blockChecksumHeader.getNamespaceId();
    final Block block = new Block(blockChecksumHeader.getBlockId(), 0,
            blockChecksumHeader.getGenStamp());

    DataOutputStream out = null;

    ReplicaToRead ri = datanode.data.getReplicaToRead(namespaceId, block);
    if (ri == null) {
      throw new IOException("Unknown block");
    }

    updateCurrentThreadName("getting CRC checksum for block " + block);

    try {
      //write reply
      out = new DataOutputStream(
          NetUtils.getOutputStream(s, datanode.socketWriteTimeout));
      int blockCrc;
      if (ri.hasBlockCrcInfo()) {
        // There is actually a short window that the block is reopened
        // and we got exception when call getBlockCrc but it's OK. It's
        // only happens for append(). So far we don't optimize for this
        // use case. We can do it later when necessary.
        //
        blockCrc = ri.getBlockCrc();
      } else {
        try {
          if (ri.isInlineChecksum()) {
            blockCrc = BlockInlineChecksumReader.getBlockCrc(datanode, ri,
                namespaceId, block);
          } else {
            blockCrc = BlockWithChecksumFileReader.getBlockCrc(datanode, ri,
                namespaceId, block);
          }
        } catch (IOException ioe) {
          LOG.warn("Exception when getting Block CRC", ioe);
          out.writeShort(DataTransferProtocol.OP_STATUS_ERROR);
          out.flush();
          throw ioe;
        }
      }
      
      out.writeShort(DataTransferProtocol.OP_STATUS_SUCCESS);
      out.writeLong(blockCrc);
      out.flush();
    } finally {
      IOUtils.closeStream(out);
    }
  }