def _pad(key, value, seeds, amplify_factor): has_key = int(hashlib.md5(f"{key}".encode("ascii")).hexdigest(), 16) # LOGGER.debug(f"hash_key: {has_key}") cur_seeds = {uid: has_key + seed for uid, seed in seeds.items()} # LOGGER.debug(f"cur_seeds: {cur_seeds}") rands = {uid: RandomPads(v & 0xFFFFFFFF) for uid, v in cur_seeds.items()} if isinstance(value, np.ndarray): ret = value for uid, rand in rands.items(): if uid > self._uuid: ret = rand.add_rand_pads(ret, 1.0 * amplify_factor) else: ret = rand.add_rand_pads(ret, -1.0 * amplify_factor) return key, ret elif isinstance(value, Instance): ret = value.features for uid, rand in rands.items(): if uid > self._uuid: ret = rand.add_rand_pads(ret, 1.0 * amplify_factor) else: ret = rand.add_rand_pads(ret, -1.0 * amplify_factor) value.features = ret return key, value else: ret = value for uid, rand in rands.items(): if uid > self._uuid: ret += rand.rand(1)[0] * self._amplify_factor else: ret -= rand.rand(1)[0] * self._amplify_factor return key, ret
def set_exchanged_keys(self, keys): self._seeds = { uid: v & 0xffffffff for uid, v in keys.items() if uid != self._uuid } self._rands = { uid: RandomPads(v & 0xffffffff) for uid, v in keys.items() if uid != self._uuid }