Friday, 17 November 2017

Java Program to Implement Naor Reingold Pseudo Random Function


Code:

import java.util.Random;

public class Naor_Reingold 
{
    public static void main(String args[])
    {
        int p=7, l=3, g=2, n=4, x;
        int []a = {1,2,2,1};
        int []bin = new int[4];
        Random random = new Random();
        System.out.println("The Random numbers are: ");
        for(int i=0; i<10 font="" i="">
        {
            x = random.nextInt(17);
            for(int j=3; j>=0; j--)
            {
                bin[j] = x%2;
                x/=2;
            }
            int mul = 1;
            for(int k=0; k<4 font="" k="">
                mul *= Math.pow(a[k], bin[k]);
            System.out.println(Math.pow(g, mul));
        }
    }
}


Output:

The Random numbers are: 
2.0
4.0
2.0
2.0
2.0
16.0
4.0
16.0
16.0
4.0


More Java 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...