An alternating current (ac) generator works on the principle of electromagnetic induction. It converts mechanical energy into electrical energy. The mechanical energy comes from a rotating coil in the generator that moves within a magnetic field, and as the coil rotates, it induces an electromotive force (emf), thereby generating electrical energy.
Thus, the correct answer is \( \boxed{\text{mechanical energy into electrical energy}} \).