encryption validity hackerrank solution in python