We describe an adaptation of the billiard algorithm for finding dense packings of equal spheres inside a domain of the euclidean space. In order to improve the convergence of this stochastic algorithm, we introduce systematic perturbations in it. We apply this perturbed billiard algorithm in the case of n spheres in a cube and display all the optimal and best known packings up to n = 32. We improve the previous record packings for all 11 n 26 except n = 13, 14, 18. We prove the existence of the displayed packings for n = 11, 12, 15, 17, 20, 21, 22, 26, 32, by constructing them explicitly. For example, the graph of the conjectured optimal packing of twenty-two spheres is composed of five octahedrons and four isolated points. We also conjecture that the minimum distance dn between spheres centers of the optimal packings is constant in the range 29 n 32.