Saturday 18 November 2017

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


Code:

#include   iostream
#include   math.h
#include   stdlib.h

using namespace std;

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


Output:

The Random numbers are: 
2 4 16 4 2 4 16 16 4 2



More C++ Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...