Hello friends,

I am struggling trying to implement Diffie-Hellman's protocol in a network application I am working on. As far as I know, it's recommended to use large prime values for the "p" variable of the algorithm. I've read in some articles p must be over 600 digits to ensure it remains unbreakable.

https://en.wikipedia.org/wiki/Diffie–Hellman_key_exchangeI would like to hear your experience with the protocol itself and if you know any good implementation of it.

The question: how do you generate random prime numbers with at least 600 digits?

With the following code I can generate a list of prime numbers up to n. But I believe it to be not a good solution for what I ask, having to generate a list each time and picking up the numbers with the size desired, I am confused. Please, let me see what you think.

{**********************************

Criba de Eratóstenes

***********************************

Debo usar un vector dinámico que crezca en función de la cantidad de números

primos que la criba haya podido generar. Cada vez que se genere un primo,

mediante setLength(array, i = i + 1) incrementamos en 1 la longitud del array.

Al redimensionar un array se mantiene lo anterior si se incrementa o encoje,

pero siempre se pierde lo posterior.

}

function GeneratePrimeNumberList( topNumber : integer ):array of integer;

var

i,j,lengthArray:integer;

primeFlag:boolean;

primeNumbers: array of integer;

begin

lengthArray := 0;

for j := 2 to topNumber do

begin

i := 2; primeFlag := true;

while i <= (j div 2) do

begin

if (j mod i) = 0 then

primeFlag := false;

i := i + 1;

end;

if primeFlag = true then

begin

lengthArray := lengthArray + 1;

SetLength(primeNumbers,lengthArray);

primeNumbers[lengthArray-1] := j;

end;

end;

Result := primeNumbers;

end;

Do you know any other better way?

regards