Example #1
0
 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))
Example #2
0
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")))
Example #3
0
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)
Example #4
0
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)
Example #5
0
 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:])
Example #6
0
 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"))
Example #7
0
 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:])
Example #8
0
    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"))
Example #9
0
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)    
Example #10
0
 def decrypt_block(self, data, key, tag=None, tweak=None):
     plaintext = decrypt(data, self.key, self.size_constants, self.rounds)
     replacement_subroutine(data, plaintext)
Example #11
0
 def encrypt_block(self, data, key, tag=None, tweak=None):            
     ciphertext = encrypt(data, self.key, self.rounds, self.size_constants)        
     replacement_subroutine(data, ciphertext)        
Example #12
0
 def decrypt_block(self, data, key, tag=None, tweak=None):
     plaintext = decrypt(data, self.key)
     replacement_subroutine(data, plaintext)
Example #13
0
 def decrypt_block(self, data, key, tag):        
     _data = list(data)
     decrypt_bytes(_data, key[:], tag, self.rounds)        
     replacement_subroutine(data, _data)        
Example #14
0
 def encrypt_block(self, data, key, tag=None, tweak=None):
     ciphertext = encrypt(data, self.key)
     replacement_subroutine(data, ciphertext)
Example #15
0
 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)])
Example #16
0
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)
Example #17
0
def cbc_encrypt(block, iv, key, cipher, tag=None, tweak=None):
    xor_subroutine(block, iv)
    cipher(block, key, tag, tweak)
    replacement_subroutine(iv, block)
Example #18
0
 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))
Example #19
0
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)
Example #20
0
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)            
Example #21
0
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]
Example #22
0
 def decrypt_block(self, data, key, tag=None, tweak=None):
     plaintext = decrypt(data, self.key)
     replacement_subroutine(data, plaintext)
Example #23
0
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)
Example #24
0
 def encrypt_block(self, data, key, tag=None, tweak=None):            
     ciphertext = encrypt(data, self.key)        
     replacement_subroutine(data, ciphertext)                
Example #25
0
 def encrypt_block(self, data, key, tweak=None, tag=None):
     _data = encrypt(data, key)
     replacement_subroutine(data, _data[:len(data)])
Example #26
0
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)
Example #27
0
 def encrypt_block(self, data, key, tag=None, tweak=None):
     ciphertext = encrypt(data, self.key, self.rounds, self.size_constants)
     replacement_subroutine(data, ciphertext)
Example #28
0
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)
Example #29
0
 def decrypt_block(self, data, key, tag=None, tweak=None):
     plaintext = decrypt(data, self.key, self.size_constants, self.rounds)
     replacement_subroutine(data, plaintext)