# C++ Program to Implement Naor-Reingold Pseudo Random Function

C++Server Side ProgrammingProgramming

Naor-Reingold Pseudo Random Function is another method of generating random numbers.

Moni Naor and Omer Reingold described efficient constructions for various cryptographic primitives in private key as well as public-key cryptography, in 1997. Let p and l be prime numbers with l |p−1. Select an element g ε Fp* of multiplicative order l. Then for each n-dimensional vector a = (a0,a1, ..., an).

They define the function

fa(x)=ga0.a1x1a2x2…..anxn ε Fp

where x = x1 … xn is the bit representation of integer x, 0 ≤ x ≤ 2 n−1

This function can be used as the basis of many cryptographic schemes including symmetric encryption, authentication, and digital signatures.

## Algorithm

Begin
Declare the variables p, l, g, n, x
Read the variables p, l, g, n
Declare array a[], b[]
For i=0 to 10, do
x = rand() mod 16;
For j=g to 0, do
b[j] = x mod 2;
x =x divided by2;
Done
Assign mult = 1
For k = 0 to n do
mult = mult *(pow(a[k], b[k]))
Done
Print the random numbers
Done
End

## Example Code

#include <iostream>
using namespace std;
int main(int argc, char **argv) {
int p = 7, l = 2, g = 3, n = 6, x;
int a[] = { 1, 2, 2, 1 };
int b[4];
cout << "The Random numbers are: ";
for (int i = 0; i < 10; i++) {
x = rand() % 16;
for (int j = 3; j >= 0; j--) {
b[j] = x % 2;
x /= 2;
}
int mult = 1;
for (int k = 0; k < 6; k++)
mult *= pow(a[k], b[k]);
cout << pow(g, mult)<<" ";
}
}

## Output

The Random numbers are: 81 81 3 9 3 81 9 9 3 9
Published on 15-Mar-2019 06:24:47