#ifndef PASSWORDVERIFIER001_H
#define PASSWORDVERIFIER001_H

#include <NTL/ZZ.h>
using namespace NTL;

#include <typedefs.h>

/*!
\brief Password verification without passing the passoword, 
       instead evaluating a public one way function. 

The client and server are both represented by this class.
*/
class passwordverifier001
{
public:

  /** The password is a nbit-1 or less bit number. */
  ZZ password;
  /** A variable in the one way function. */
  ZZ j1;
  /** A variable in the one way function. */
  ZZ j2;
  /** A variable in the one way function. */
  ZZ n1;
  /** A variable in the one way function. */
  ZZ n2;
  /** A variable in the one way function. */
  ZZ k1;

  /** The strength is O(2^(nbits-1)). */
  uintc nbits;

  /** The number of bits is a measure of the solution space. */
  passwordverifier001(uintc nbits_)
    : nbits(nbits_) {}

  /** Randomly generate a nbits-1 password. */
  void generatePassword();

  /** j1 j2 n1 n2 k1 values are randomly generated. */
  void generateRandomFunction();

  /** Set this classes parameters j1 j2 n1 n2 k1 as a string. */
  void parameters_set(stringc & parameters );
  /** Get/read the parameters j1 j2 n1 n2 k1. */
  void parameters_get(string & parameters );

  /** Apply the one way function to the password. */
  void eval( ZZ & val ) const;

  /** Apply the one way function to the password. */
  void eval( string & val ) const;

  /** The current one way function is evaluated and if
      its result is equal to the attemp true is returned. */
  boolc verify( stringc & attempt ) const;

private:

  static void random(ZZ & num, uintc nb);

  static void convInverse(string & wstr, ZZ const w );
};



    


#endif



