Ejemplo n.º 1
0
 def test_back_90(self):
     # Create the cube.
     cube = Cube(cube_input=self.cube_input, cube_side_length=2)
     cube.shift(Key(move=CubeMove.back.value, angle=90, index=1))
     assert cube.content == \
         "890767859012345678901234567890123456456312340129" \
         "123456784563234185670789290141236785789023415678"
Ejemplo n.º 2
0
 def test_down_90(self):
     # Create the cube.
     cube = Cube(cube_input=self.cube_input, cube_side_length=2)
     cube.shift(Key(move=CubeMove.down.value, angle=90, index=1))
     assert cube.content == \
         "123456789012345678901234123456783456789056789012" \
         "290141236345856778901234123456783456789056789012"
Ejemplo n.º 3
0
 def test_front_90(self):
     # Create the cube.
     cube = Cube(cube_input=self.cube_input, cube_side_length=2)
     cube.shift(Key(move=CubeMove.front.value, angle=90, index=1))
     assert cube.content == \
         "123456788567078985670789290141232901789063455678" \
         "412363459012345678901234567890123456412312348567"
Ejemplo n.º 4
0
 def test_left_90(self):
     # Create the cube.
     cube = Cube(cube_input=self.cube_input, cube_side_length=2)
     cube.shift(Key(move=CubeMove.left.value, angle=90, index=1))
     assert cube.content == \
         "129056783412345612341234901290123456789012345678" \
         "789056785678345678901290567834124123634585670789"
Ejemplo n.º 5
0
 def test_special(self):
     # Create the cube.
     cube = Cube(cube_input=self.cube_input, cube_side_length=2)
     try:
         cube.shift(Key(move="abracadabra", angle=90, index=0))
         raise AssertionError("Error message did not raise.")
     except ValueError as error:
         assert str(error) == WRONG_CUBE_MOVE
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
    def _check_effective_key(self, key: Key) -> bool:
        """Check if the given key moves the tracked item.

        :param key: The possible key that moves the location.
        :return: If the key actually moves the item. (Not Equal = True)
        """
        # 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.
        temp_cube.shift(key=key)
        # Return True if the location is changed.
        return temp_cube.get_tracked_location() != self._track_item_location
Ejemplo n.º 8
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()
Ejemplo n.º 9
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")}