Begin key algorithm