Crypt the block of data through DES bit-manipulation
195787
def __des_crypt(self, block, crypt_type):
        """"""
        block = self.__permutate(des.__ip, block)
        self.L = block[:32]
        self.R = block[32:]

        # Encryption starts from Kn[1] through to Kn[16]
        if crypt_type == des.ENCRYPT:
            iteration = 0
            iteration_adjustment = 1
        # Decryption starts from Kn[16] down to Kn[1]
        else:
            iteration = 15
            iteration_adjustment = -1

        i = 0
        while i < 16:
            # Make a copy of R[i-1], this will later become L[i]
            tempR = self.R[:]

            # Permutate R[i - 1] to start creating R[i]
            self.R = self.__permutate(des.__expansion_table, self.R)

            # Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
            self.R = list(map(lambda x, y: x ^ y, self.R, self.Kn[iteration]))
            B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
            # Optimization: Replaced below commented code with above
            #j = 0
            #B = []
            #while j < len(self.R):
            #    self.R[j] = self.R[j] ^ self.Kn[iteration][j]
            #    j += 1
            #    if j % 6 == 0:
            #        B.append(self.R[j-6:j])

            # Permutate B[1] to B[8] using the S-Boxes
            j = 0
            Bn = [0] * 32
            pos = 0
            while j < 8:
                # Work out the offsets
                m = (B[j][0] << 1) + B[j][5]
                n = (B[j][1] << 3) + (B[j][2] << 2) + (B[j][3] << 1) + B[j][4]

                # Find the permutation value
                v = des.__sbox[j][(m << 4) + n]

                # Turn value into bits, add it to result: Bn
                Bn[pos] = (v & 8) >> 3
                Bn[pos + 1] = (v & 4) >> 2
                Bn[pos + 2] = (v & 2) >> 1
                Bn[pos + 3] = v & 1

                pos += 4
                j += 1

            # Permutate the concatination of B[1] to B[8] (Bn)
            self.R = self.__permutate(des.__p, Bn)

            # Xor with L[i - 1]
            self.R = list(map(lambda x, y: x ^ y, self.R, self.L))
            # Optimization: This now replaces the below commented code
            #j = 0
            #while j < len(self.R):
            #    self.R[j] = self.R[j] ^ self.L[j]
            #    j += 1

            # L[i] becomes R[i - 1]
            self.L = tempR

            i += 1
            iteration += iteration_adjustment
        
        # Final permutation of R[16]L[16]
        self.final = self.__permutate(des.__fp, self.R + self.L)
        return self.final
311854
def Decrypt(self, encrypted_data):
    
    index_split = -(len(encrypted_data) % AES.block_size)
    if index_split:
      remaining_encrypted_data = encrypted_data[index_split:]
      encrypted_data = encrypted_data[:index_split]
    else:
      remaining_encrypted_data = b''

    decrypted_data = self._aes_cipher.decrypt(encrypted_data)

    return decrypted_data, remaining_encrypted_data
689853
def crypt(self, data, crypt_type):
        """"""

        # Error check the data
        if not data:
            return ''
        if len(data) % self.block_size != 0:
            if crypt_type == des.DECRYPT: # Decryption must work on 8 byte blocks
                raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n" + data + ".")
            if not self.getPadding():
                raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n. Try setting the optional padding character")
            else:
                data += (self.block_size - (len(data) % self.block_size)) * self.getPadding()
            # print "Len of data: %f" % (len(data) / self.block_size)

        if self.getMode() == CBC:
            if self.getIV():
                iv = self.__String_to_BitList(self.getIV())
            else:
                raise ValueError("For CBC mode, you must supply the Initial Value (IV) for ciphering")

        # Split the data into blocks, crypting each one seperately
        i = 0
        result = []
        while i < len(data):
            block = self.__String_to_BitList(data[i:i+8])

            # Xor with IV if using CBC mode
            if self.getMode() == CBC:
                if crypt_type == des.ENCRYPT:
                    block = list(map(lambda x, y: x ^ y, block, iv))

                processed_block = self.__des_crypt(block, crypt_type)

                if crypt_type == des.DECRYPT:
                    processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
                    iv = block
                else:
                    iv = processed_block
            else:
                processed_block = self.__des_crypt(block, crypt_type)


            # Add the resulting crypted block to our list
            result.append(self.__BitList_to_String(processed_block))
            i += 8

        # Return the full crypted string
        if _pythonMajorVersion < 3:
            return ''.join(result)
        else:
            return bytes.fromhex('').join(result)
946180
private void ekskey(final byte data[], final byte key[]) {
        int i;
        final int koffp[] = {0}, doffp[] = {0};
        final int lr[] = {0, 0};
        final int plen = P.length, slen = S.length;

        for (i = 0; i < plen; i++) {
            P[i] = P[i] ^ streamtoword(key, koffp);
        }

        for (i = 0; i < plen; i += 2) {
            lr[0] ^= streamtoword(data, doffp);
            lr[1] ^= streamtoword(data, doffp);
            encipher(lr, 0);
            P[i] = lr[0];
            P[i + 1] = lr[1];
        }

        for (i = 0; i < slen; i += 2) {
            lr[0] ^= streamtoword(data, doffp);
            lr[1] ^= streamtoword(data, doffp);
            encipher(lr, 0);
            S[i] = lr[0];
            S[i + 1] = lr[1];
        }
    }
252781
function AES_Decrypt(block, key) {
	var l = key.length;
	AES_AddRoundKey(block, key.slice(l - 16, l));
	AES_ShiftRows(block, AES_ShiftRowTab_Inv);
	AES_SubBytes(block, AES_Sbox_Inv);
	for(var i = l - 32; i >= 16; i -= 16) {
		AES_AddRoundKey(block, key.slice(i, i + 16));
		AES_MixColumns_Inv(block);
		AES_ShiftRows(block, AES_ShiftRowTab_Inv);
		AES_SubBytes(block, AES_Sbox_Inv);
	}
	AES_AddRoundKey(block, key.slice(0, 16));
	return block;
}
328834
function decrypt(key, iv, data) {
    if(!Buffer.isBuffer(key)) {
        assert(typeof key === 'string');
        key = Buffer.from(key, 'binary')
    }

    if(!Buffer.isBuffer(iv)) {
        assert(typeof iv === 'string');
        iv = Buffer.from(iv, 'binary')
    }

    if(!Buffer.isBuffer(data)) {
        assert(typeof data === 'string');
        data = Buffer.from(data, 'binary')
    }

    let ret = Buffer.alloc(data.length/2);
    for(let i = 0; i < ret.length; i++){
        ret[i] = ((data[i*2]-97)<<4) | (data[i*2+1]-97);
    }

    var decoded = aes.decipher(ret, key, iv);
    return decoded.toString('binary');
}
28826
function getBlockHmac(key, blockIndex, blockLength, blockData) {
    return getHmacKey(key, new Int64(blockIndex)).then(function(blockKey) {
        var blockDataForHash = new Uint8Array(blockData.byteLength + 4 + 8);
        var blockDataForHashView = new DataView(blockDataForHash.buffer);
        blockDataForHash.set(new Uint8Array(blockData), 4 + 8);
        blockDataForHashView.setInt32(0, blockIndex, true);
        blockDataForHashView.setInt32(8, blockLength, true);
        return CryptoEngine.hmacSha256(blockKey, blockDataForHash.buffer);
    });
}
504222
def block_verify( cls, verified_block_header, block_txids ):
        

        block_data = {
            'merkleroot': verified_block_header['merkleroot'],
            'tx': block_txids
        }

        return bits.block_verify( block_data )
47314
function blockEncrypt(input, inOffset, sessionKey) {

        if (input &&
          sessionKey &&
          utils.isAnArray(sessionKey) &&
          utils.isAnArray(input)) {

          input = new Uint8Array(input);
          var sBox = sessionKey[0]
            , sKey = sessionKey[1]

            /*eslint-disable no-plusplus*/
            , x0 = input[inOffset++] & 0xFF |
                   (input[inOffset++] & 0xFF) << 8 |
                   (input[inOffset++] & 0xFF) << 16 |
                   (input[inOffset++] & 0xFF) << 24

            , x1 = input[inOffset++] & 0xFF |
                   (input[inOffset++] & 0xFF) << 8 |
                   (input[inOffset++] & 0xFF) << 16 |
                   (input[inOffset++] & 0xFF) << 24

            , x2 = input[inOffset++] & 0xFF |
                   (input[inOffset++] & 0xFF) << 8 |
                   (input[inOffset++] & 0xFF) << 16 |
                   (input[inOffset++] & 0xFF) << 24

            , x3 = input[inOffset++] & 0xFF |
                   (input[inOffset++] & 0xFF) << 8 |
                   (input[inOffset++] & 0xFF) << 16 |
                   (input[inOffset++] & 0xFF) << 24
            /*eslint-enable no-plusplus*/

            , t0
            , t1
            , k = ROUND_SUBKEYS
            , R = 0;

          x0 ^= sKey[INPUT_WHITEN];
          x1 ^= sKey[INPUT_WHITEN + 1];
          x2 ^= sKey[INPUT_WHITEN + 2];
          x3 ^= sKey[INPUT_WHITEN + 3];
          for (R = 0; R < ROUNDS; R += 2) {

            t0 = fe32(sBox, x0, 0);
            t1 = fe32(sBox, x1, 3);
            /*eslint-disable no-plusplus*/
            x2 ^= t0 + t1 + sKey[k++];
            /*eslint-enable no-plusplus*/
            x2 = x2 >>> 1 | x2 << 31;
            x3 = x3 << 1 | x3 >>> 31;
            /*eslint-disable no-plusplus*/
            x3 ^= t0 + 2 * t1 + sKey[k++];
            /*eslint-enable no-plusplus*/

            t0 = fe32(sBox, x2, 0);
            t1 = fe32(sBox, x3, 3);
            /*eslint-disable no-plusplus*/
            x0 ^= t0 + t1 + sKey[k++];
            /*eslint-enable no-plusplus*/
            x0 = x0 >>> 1 | x0 << 31;
            x1 = x1 << 1 | x1 >>> 31;
            /*eslint-disable no-plusplus*/
            x1 ^= t0 + 2 * t1 + sKey[k++];
            /*eslint-enable no-plusplus*/
          }

          x2 ^= sKey[OUTPUT_WHITEN];
          x3 ^= sKey[OUTPUT_WHITEN + 1];
          x0 ^= sKey[OUTPUT_WHITEN + 2];
          x1 ^= sKey[OUTPUT_WHITEN + 3];

          return new Uint8Array([x2, x2 >>> 8, x2 >>> 16, x2 >>> 24,
             x3, x3 >>> 8, x3 >>> 16, x3 >>> 24,
             x0, x0 >>> 8, x0 >>> 16, x0 >>> 24,
             x1, x1 >>> 8, x1 >>> 16, x1 >>> 24]);
        }

        throw 'input block is not an array or sessionKey is incorrect';
      }
939483
def xor(block1, block2):
    
    xored = ''.join(['{0:#0{1}x}'.format((i ^ j), 4)[2:] for i, j in zip(B2raw(block1), B2raw(block2))])
    return bytes(xored.upper(), 'utf-8')
1185580
def encrypt(data, digest=True):
    """"""
    alg = get_best_algorithm()
    enc = implementations["encryption"][alg](
        data, implementations["get_key"]()
    )
    return "%s$%s" % (alg, (_to_hex_digest(enc) if digest else enc))
609900
def encrypt(message, modN, e, blockSize):
    """"""
    numList = string2numList(message)
    numBlocks = numList2blocks(numList, blockSize)  # only one block
    message = numBlocks[0]
    # return [modExp(blocks, e, modN) for blocks in numBlocks]
    return modExp(message, e, modN)
1103921
function(input,key,size)
		{
			var output = [];
			var block = []; /* the 128 bit block to encode */
			var nbrRounds = this.numberOfRounds(size);
			/* Set the block values, for the block:
			 * a0,0 a0,1 a0,2 a0,3
			 * a1,0 a1,1 a1,2 a1,3
			 * a2,0 a2,1 a2,2 a2,3
			 * a3,0 a3,1 a3,2 a3,3
			 * the mapping order is a0,0 a1,0 a2,0 a3,0 a0,1 a1,1 ... a2,3 a3,3
			 */
			for (var i = 0; i < 4; i++) /* iterate over the columns */
				for (var j = 0; j < 4; j++) /* iterate over the rows */
					block[(i+(j*4))] = input[(i*4)+j];
		
			/* expand the key into an 176, 208, 240 bytes key */
			var expandedKey = this.expandKey(key, size); /* the expanded key */
			/* encrypt the block using the expandedKey */
			block = this.main(block, expandedKey, nbrRounds);
			for (var k = 0; k < 4; k++) /* unmap the block again into the output */
				for (var l = 0; l < 4; l++) /* iterate over the rows */
					output[(k*4)+l] = block[(k+(l*4))];
			return output;
		}
839485
function encrypt(key, iv, data) {
    if(!Buffer.isBuffer(key)) {
        assert(typeof key === 'string');
        key = Buffer.from(key, 'binary')
    }

    if(!Buffer.isBuffer(iv)) {
        assert(typeof iv === 'string');
        iv = Buffer.from(iv, 'binary')
    }

    if(!Buffer.isBuffer(data)) {
        assert(typeof data === 'string');
        data = Buffer.from(data, 'binary')
    }

    var crypted = aes.encipher(data, key, iv);

    crypted = Buffer.from(crypted, 'binary');
    
    let ret = Buffer.alloc(crypted.length*2);
    for(let i = 0; i < crypted.length; i++){
        ret[2*i] = (crypted[i] >> 4) + 97;
        ret[2*i+1] = (crypted[i] & 0x0F) + 97;
    }
    return ret.toString('binary');
}
793252
def cipher_block (self, state):
        """"""
        # PKCS7 Padding
        state=state+[16-len(state)]*(16-len(state))# Fails test if it changes the input with +=

        self._add_round_key(state, 0)

        for i in range(1, self._Nr):
            self._sub_bytes(state)
            self._shift_rows(state)
            self._mix_columns(state, False)
            self._add_round_key(state, i)

        self._sub_bytes(state)
        self._shift_rows(state)
        self._add_round_key(state, self._Nr)
        return state
1140231
function encrypt(userKey, plainText) {
        var i
          , offset
          , ct = []
          , tmpBlockEncrypt;

        if (utils.isAnArray(userKey) &&
          utils.isAnArray(plainText)) {

          userKey = new Uint8Array(userKey);
          plainText = new Uint8Array(plainText);
        } else {

          throw 'Inputs must be an array';
        }

        userKey = makeKey(userKey);

        for (offset = 0; offset < plainText.length; offset += 16) {

          tmpBlockEncrypt = blockEncrypt(plainText, offset, userKey);
          for (i = 0; i < tmpBlockEncrypt.length; i += 1) {

            ct.push(tmpBlockEncrypt[i]);
          }
        }

        return ct;
      }
600597
function contentEncryptCbc(aad, cek, cekEnc, plain, bits) {
  let iv = crypto.randomBytes(16);
  let bytes = bits >> 3;
  let cipher = crypto.createCipheriv(`AES-${bits}-CBC`, cek.slice(bytes), iv);
  let enc = Buffer.concat([cipher.update(plain), cipher.final()]);
  let len = aad.length << 3;
  let al = Buffer.from(`000000000000000${len.toString(16)}`.slice(-16), 'hex');
  let hmac = crypto.createHmac(`SHA${bits << 1}`, cek.slice(0, bytes));
  hmac.update(Buffer.from(aad)).update(iv).update(enc).update(al);
  let tag = buf2b64url(hmac.digest().slice(0, bytes));
  return `${aad}.${cekEnc}.${buf2b64url(iv)}.${buf2b64url(enc)}.${tag}`;
}