Improved logic for deciding which encryption algorithm to use