def encrypt_block(self, plaintext, key): ciphertext = aes_encrypt(bytes(plaintext), bytes(key), bytes(key), mode="ECB", return_mode="values")[1] replacement_subroutine(plaintext, bytearray(ciphertext))
def ctr_mode(block, iv, key, cipher, tag=None, tweak=None): cipher(iv, key, tag, tweak) xor_subroutine(block, iv) replacement_subroutine( iv, bytearray(cast( cast(cast(bytes(iv), "binary"), "integer") + 1, "bytes")))
def decrypt(data, key, conversion_key, conversion_key2): xor_subroutine(data, key) converted = convert(bytes(data), bytes(conversion_key2), bytes(conversion_key)) replacement_subroutine(data, converted) invert_diffusion_transformation(data) xor_subroutine(data, key) return bytes(data)
def encrypt_block(self, data, key): left, right, leftkey, rightkey, modulus, round_info = self._crypt_block(data, key) speck_round(left, right, leftkey, modulus) print left, right for round in range(1, 4):#NUMBER_OF_ROUNDS[round_info]): leftkey, rightkey = speck_round(rightkey, leftkey, round, modulus) left, right = speck_round(left, right, leftkey, modulus) print left, right replacement_subroutine(data, cast(left, "bytes") + cast(right, "bytes")) print left, right print data print word_to_integer(data[:len(data) / 2]), word_to_integer(data[len(data) / 2:])
def decrypt_block(self, data, key): print "Decrypting\n", data left, right, leftkey, rightkey, modulus, round_info = self._crypt_block(data, key) print left, right for round_number in range(1, 4):#NUMBER_OF_ROUNDS[round_info]): leftkey, rightkey = speck_round(rightkey, leftkey, round_number, modulus) print left, right for round in reversed(range(1, 4)):#NUMBER_OF_ROUNDS[round_info])): left, right = invert_speck_round(left, right, leftkey, modulus) print left, right leftkey, rightkey = invert_speck_round(rightkey, leftkey, round, modulus) left, right = invert_speck_round(left, right, leftkey, modulus) replacement_subroutine(data, cast(left, "bytes") + cast(right, "bytes"))
def encrypt_block(self, data, key): left, right, leftkey, rightkey, modulus, round_info = self._crypt_block( data, key) speck_round(left, right, leftkey, modulus) print left, right for round in range(1, 4): #NUMBER_OF_ROUNDS[round_info]): leftkey, rightkey = speck_round(rightkey, leftkey, round, modulus) left, right = speck_round(left, right, leftkey, modulus) print left, right replacement_subroutine(data, cast(left, "bytes") + cast(right, "bytes")) print left, right print data print word_to_integer(data[:len(data) / 2]), word_to_integer( data[len(data) / 2:])
def decrypt_block(self, data, key): print "Decrypting\n", data left, right, leftkey, rightkey, modulus, round_info = self._crypt_block( data, key) print left, right for round_number in range(1, 4): #NUMBER_OF_ROUNDS[round_info]): leftkey, rightkey = speck_round(rightkey, leftkey, round_number, modulus) print left, right for round in reversed(range(1, 4)): #NUMBER_OF_ROUNDS[round_info])): left, right = invert_speck_round(left, right, leftkey, modulus) print left, right leftkey, rightkey = invert_speck_round(rightkey, leftkey, round, modulus) left, right = invert_speck_round(left, right, leftkey, modulus) replacement_subroutine(data, cast(left, "bytes") + cast(right, "bytes"))
def shuffle(_state): temp = bytearray(16) temp[7] = _state[0] temp[12] = _state[1] temp[14] = _state[2] temp[9] = _state[3] temp[2] = _state[4] temp[1] = _state[5] temp[5] = _state[6] temp[15] = _state[7] temp[11] = _state[8] temp[6] = _state[9] temp[13] = _state[10] temp[0] = _state[11] temp[4] = _state[12] temp[8] = _state[13] temp[10] = _state[14] temp[3] = _state[15] replacement_subroutine(_state, temp)
def decrypt_block(self, data, key, tag=None, tweak=None): plaintext = decrypt(data, self.key, self.size_constants, self.rounds) replacement_subroutine(data, plaintext)
def encrypt_block(self, data, key, tag=None, tweak=None): ciphertext = encrypt(data, self.key, self.rounds, self.size_constants) replacement_subroutine(data, ciphertext)
def decrypt_block(self, data, key, tag=None, tweak=None): plaintext = decrypt(data, self.key) replacement_subroutine(data, plaintext)
def decrypt_block(self, data, key, tag): _data = list(data) decrypt_bytes(_data, key[:], tag, self.rounds) replacement_subroutine(data, _data)
def encrypt_block(self, data, key, tag=None, tweak=None): ciphertext = encrypt(data, self.key) replacement_subroutine(data, ciphertext)
def decrypt_block(self, data, key, tweak=None, tag=None): _data = encrypt(data, key, _start=5 - 1, _direction=-1) replacement_subroutine(data, _data[:len(data)])
def cbc_decrypt(block, iv, key, cipher, tag=None, tweak=None): next_iv = block[:] cipher(block, key, tag, tweak) xor_subroutine(block, iv) replacement_subroutine(iv, next_iv)
def cbc_encrypt(block, iv, key, cipher, tag=None, tweak=None): xor_subroutine(block, iv) cipher(block, key, tag, tweak) replacement_subroutine(iv, block)
def shuffle(data, key, indices): output = data[:] for index, place in indices: output = rotate(output[:index + 1], key[index]) + output[index + 1:] replacement_subroutine(data, output)
def ella_mode(block, iv, key, cipher, tag, tweak=None): datablock = tag + block cipher(datablock, key) replacement_subroutine(block, datablock[8:]) replacement_subroutine(tag, datablock[:8]) #tag[:8] = datablock[:8]
def absorb(data, state, rate, mixing_subroutine, replacement_subroutine): for block in slide(bytearray(data), rate.stop - rate.start): replacement_subroutine(state, block) mixing_subroutine(state)
def encrypt_block(self, data, key, tweak=None, tag=None): _data = encrypt(data, key) replacement_subroutine(data, _data[:len(data)])
def crypt(data, key, iv, cipher, mode_of_operation, blocksize, tag, tweak): output = bytearray() for block in slide(data, blocksize): mode_of_operation(block, iv, key, cipher, tag, tweak) output.extend(block) replacement_subroutine(data, output)