
/*
  Vipul Mathur
  Roll Number 03405001

  IT 653: Network Security
  Assignment 2
  Problem 1

    Suppose A's Diffie-Hellmann parameters (P, g) are (24691, 106) respectively and his
    public key is 12375, write a program to compute A's private key.
*/

int main()
{
  int P     = 24691;  int g    = 106;  int pubA = 12375;
  int privA = 1;      int temp = 1;

  // pubA = g^privA (mod p)         (find privA)
  while( ((temp=(temp*g) % P) != pubA) ) {
    printf("[%5d->%5d]  ", privA, temp);
    privA++;
  }

  printf("[%5d->%5d]  ", privA, temp);
  if (temp == pubA) printf("\nFound privA = %d!!\n", privA);
  return(0);
}
