code: def key_periods(ciphertext, max_key_period):
      if max_key_period <= 0:
          raise ValueError("max_key_period must be a positive integer")
      key_scores = []
      for period in range(1, min(max_key_period, len(ciphertext)) + 1):
          score = abs(ENGLISH_IC - index_of_coincidence(*split_columns(ciphertext, period)))
          key_scores.append((period, score))
      return [p[0] for p in sorted(key_scores, key=lambda x: x[1])]