Implementation of richard agraval algorith