Energy of van der Waals and dipole-dipole interactions between atoms in Rydberg states