Example #1
0
    def _get_location_after_key(key: Key, cube: Cube) -> int:
        """Perform a move on the cube and find the tracked bit.

        :param key: Indicate the movement on the cube.
        :param cube: The cube object.
        :return: The new location of the tracked bit.
        """
        cube.shift(key=key)
        cube.shift_cubie_content()
        return cube.get_tracked_location()
Example #2
0
    def _get_location(self, key: Key) -> int:
        """Get location of the tracked item after performing a effective key.

        :param key: One known effective effective key.
        :return: New location of the tracked item.
        """
        # Make a new copy of the cube.
        temp_cube = Cube(cube_input="_" * self._cube_size,
                         cube_side_length=self._side_length,
                         track_location=self._track_item_location)
        # Perform the desired shift and shift the content.
        temp_cube.shift(key=key)
        temp_cube.shift_cubie_content()

        # Return the new location of the tracked item.
        return temp_cube.get_tracked_location()
Example #3
0
def analyze_bit(key: List[Key], side_length: int, random_bits: str,
                message_bits: str):
    """Given input and key, count how the number of bits changes afterward.

    :param message_bits: Bits for the actual message.
    :param random_bits: Bits for the randomness.
    :param key: The desired key to use.
    :param side_length: Desired length of the Rubik's Cube.
    :return: Number of zeros and number of ones in the encrypted result.
    """
    # Concatenate the input to get cube input.
    cube_input = message_bits + random_bits
    # Initialize the cube.
    cube = Cube(cube_input=cube_input, cube_side_length=side_length)

    # Xor, Shift, and apply move onto the cube.
    for each_key in key:
        cube.xor()
        cube.shift_cubie_content()
        cube.shift(key=each_key)

    # Count number of zeros and number of ones.
    return {"0": cube.content.count("0"), "1": cube.content.count("1")}