for i in range(num_blocks): block = ciphertext[i*54:(i+1)*54] dec_block = permute_inverse(block) pt = xor(IV, dec_block) plaintext.extend(pt) IV = block[:] with open("dec_", "wb") as f: f.write(plaintext) solve() ''' cube.F() r = cube.raw() print(r) print("OOOOOOYYYYYRWWWOGGBBBYYRWWWOGGBBBYYRWWWOGGBBBGGGRRRRRR") ''' ''' Cube("OOOOOOOOOYYYWWWGGGBBBYYYWWWGGGBBBYYYWWWGGGBBBRRRRRRRRR") Cube("OOOOOOYYYYYRWWWOGGBBBYYRWWWOGGBBBYYRWWWOGGBBBGGGRRRRRR") OOO OOO OOO YYY WWW GGG BBB YYY WWW GGG BBB YYY WWW GGG BBB RRR RRR RRR OOO OOO YYY YYR WWW OGG BBB YYR WWW OGG BBB YYR WWW OGG BBB GGG RRR RRR '''
elif c == 'U2': A.U() A.U() A.print_cube() elif c == 'D': A.D() A.print_cube() elif c in ['D\'', 'D`']: A.D(clockwise=False) A.print_cube() elif c == 'D2': A.D() A.D() A.print_cube() elif c == 'F': A.F() A.print_cube() elif c in ['F\'', 'F`']: A.F(clockwise=False) A.print_cube() elif c == 'F2': A.F() A.F() A.print_cube() elif c.lower() == 'print': A.print_cube() elif c.lower() == 'init': A.cube = [[[i, i, i] for j in range(3)] for i in range(6)] A.print_cube() elif c.lower() in ['quit', 'exit']: break
def _solveCross(self): ''' Step 1: Get the cross on the down face. ''' down_color = self.cube.getCubeFaceColor(DOWN) side_colors = [ self.cube.getCubeFaceColor(FRONT), self.cube.getCubeFaceColor(RIGHT), self.cube.getCubeFaceColor(BACK), self.cube.getCubeFaceColor(LEFT), ] best_cube = None best_moves = None best_clean_moves = [0] * 100 # Test all orders to find the least moves for perm in permutations(side_colors): current_cube = Cube(self.cube) current_moves = self.moves[:] for color in perm: # Spin whole cube until color is on front face while current_cube.getCubeFaceColor(FRONT) != color: current_cube.Y() current_moves.append('Y') piece = current_cube.getCubieByColors((down_color, color)) # Get the face of the down color down_color_face = piece.getCubieFaceFromColor(down_color) # Continue if piece is solved if all(piece.pos == DOWN + FRONT) and down_color_face == 'D': # Piece is already solved pass else: # Move to up layer, if not already if not piece.onFace(UP): # Get color of cubie that isn't the down color other_color = (piece.getCubieColors() - set( (down_color, ))).pop() # Get the face of the other color other_color_face = piece.getCubieFaceFromColor( other_color) # In E layer if (other_color_face + down_color_face) in ('FL', 'RF', 'BR', 'LB'): # Need to rotate face, UP, inverse face current_moves.append(other_color_face) current_moves.append('U') current_moves.append(other_color_face + 'i') current_cube.moveSequence( f'{other_color_face} U {other_color_face}i') # Also in E layer elif (other_color_face + down_color_face) in ('LF', 'FR', 'RB', 'BL'): # Need to rotate inverse face, UP, face current_moves.append(other_color_face + 'i') current_moves.append('U') current_moves.append(other_color_face) current_cube.moveSequence( f'{other_color_face}i U {other_color_face}') # In D layer elif (other_color_face + down_color_face) in ('DF', 'DR', 'DB', 'DL'): # Need to rotate face, face, Up, face, face current_moves.append(down_color_face) current_moves.append(down_color_face) current_moves.append('U') current_moves.append(down_color_face) current_moves.append(down_color_face) current_cube.moveSequence( f'{down_color_face} {down_color_face} U {down_color_face} {down_color_face}' ) elif (other_color_face + down_color_face) in ('FD', 'RD', 'BD', 'LD'): # OPTIMIZE: if down_color on down face, don't need to move to U layer first # Need to rotate face, face, Up, face, face current_moves.append(other_color_face) current_moves.append(other_color_face) current_moves.append('U') current_moves.append(other_color_face) current_moves.append(other_color_face) current_cube.moveSequence( f'{other_color_face} {other_color_face} U {other_color_face} {other_color_face}' ) else: assert False, "Piece wasn't in a spot to move to U layer" # If Down color is on Up face, rotate Up until on correct face and spin # face twice if piece.getCubieFaceColor(UP) == cube.getCubeFaceColor( DOWN): # In up layer, to Up+Front count = 0 while not all(piece.pos == UP + FRONT): count += 1 current_moves.append('U') current_cube.U() assert count < 4, "Piece can't get to UP+FRONT" # Piece is above, two front turns current_moves.append('F') current_moves.append('F') current_cube.F() current_cube.F() # Down color is not on Up face, move to either Left or Right face else: # Need to put it to the right or left side if not already if piece.onFace(FRONT) or piece.onFace(BACK): current_moves.append('U') current_cube.U() # On either Left or Right assert piece.onFace(LEFT) or piece.onFace(RIGHT) current_moves.append('Ri') current_moves.append('L') current_moves.append('X') current_cube.Ri() current_cube.L() current_cube.X() if piece.onFace(LEFT): current_moves.append('Ui') current_cube.Ui() elif piece.onFace(RIGHT): current_moves.append('U') current_cube.U() current_moves.append('R') current_moves.append('Li') current_moves.append('Xi') current_cube.R() current_cube.Li() current_cube.Xi() # Clean Up the current moves current_clean_moves = self.cleanUpMoves(current_moves) # Check if current clean moves beat the best clean moves if len(current_clean_moves) < len(best_clean_moves): best_clean_moves = current_clean_moves best_moves = current_moves best_cube = current_cube # Use the best moves self.moves = best_moves[:] self.cube = best_cube