wrote algorithm for ksum