ringHoms2 := function(n) local R,e,h,f,l,j; R := Integers mod n; e := Elements(R); l := []; for j in [0..Size(e)-1] do h := x -> x^j; f := MappingByFunction(R,R,h); if IsRingHomomorphism(f) then Append(l,[j]); fi; od; return l; end;