def test_string_to_bitlist(self): bitlist = [ 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0 ] string = 'bar' self.assertEqual(utils_misc.bitlist_to_string(bitlist), string)
def crypt(self, data, crypt_type=0): """ Crypt the data in blocks, running it through des_crypt() @param data: Data to be encrypted/decrypted. @param crypt_type: crypt type. 0 means encrypt, and 1 means decrypt. """ # Split the data into list, crypting each one seperately i = 0 result = [] while i < len(data): # Test code for caching encryption results block = utils_misc.string_to_bitlist(data[i : i + 8]) pro_block = self.des_crypt(block, crypt_type) # Add the resulting block to our list result.append(utils_misc.bitlist_to_string(pro_block)) i += 8 # Return the full encrypted/decrypted string return "".join(result)
def crypt(self, data, crypt_type=0): """ Crypt the data in blocks, running it through des_crypt() :param data: Data to be encrypted/decrypted. :param crypt_type: crypt type. 0 means encrypt, and 1 means decrypt. """ # Split the data into list, crypting each one separately i = 0 result = [] while i < len(data): # Test code for caching encryption results block = utils_misc.string_to_bitlist(data[i:i + 8]) pro_block = self.des_crypt(block, crypt_type) # Add the resulting block to our list result.append(utils_misc.bitlist_to_string(pro_block)) i += 8 # Return the full encrypted/decrypted string return ''.join(result)
def test_string_to_bitlist(self): bitlist = [0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0] string = 'bar' self.assertEqual(utils_misc.bitlist_to_string(bitlist), string)