Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Globalization;
- using System.Numerics;
- using System.Collections;
- using System.IO;
- namespace Generator
- {
- class Program
- {
- static void Main(string[] args)
- {
- BigInteger p = new BigInteger(5000903);
- BigInteger q = new BigInteger(4900789);
- BigInteger n = p * q;
- BigInteger m = (p - 1) * (q - 1); // nazywane rowniez d
- BigInteger e; // powinna byc wzglednie pierwsza do d=(p-1)(q-1) - ale pomijamy
- // losowanie e
- do
- {
- e = RandomIntegerBelow(m);
- }
- while (e < 1);
- // ziarno, x0
- BigInteger x0 = RandomIntegerBelow(n); // ziarno
- String generated = "";
- BigInteger x = x0;
- const int range = 20000;
- for (int i = 0; i < range; ++i)
- {
- BigInteger xi = x;
- xi = BigInteger.ModPow(xi, e, n);
- generated += xi & 1;
- x = xi;
- }
- using (StreamWriter outputFile = new StreamWriter("generated.txt"))
- {
- outputFile.Write(generated);
- }
- // Testy
- testPojedynczychBitow(generated);
- testDlugiejSerii(generated);
- testPokerowy(generated);
- testSerii(generated);
- }
- public static BigInteger RandomIntegerBelow(BigInteger N)
- {
- byte[] bytes = N.ToByteArray();
- BigInteger R;
- do
- {
- (new Random()).NextBytes(bytes);
- bytes[bytes.Length - 1] &= (byte)0x7F; //force sign bit to positive
- R = new BigInteger(bytes);
- } while (R >= N);
- return R;
- }
- //
- public static void testPojedynczychBitow(String klucz)
- {
- int wystapienia = 0;
- foreach(char znak in klucz)
- {
- if (znak == '0')
- wystapienia++;
- }
- if (wystapienia > 9725 && wystapienia < 10275)
- Console.WriteLine("[Test pojedynczych bitow] Pozytywny");
- else
- Console.WriteLine("[Test pojedynczych bitow] Negatywny");
- }
- public static void testDlugiejSerii(String klucz)
- {
- int zera = 0;
- int jedynki = 0;
- foreach (char znak in klucz)
- {
- if (znak == '0')
- {
- zera++;
- jedynki = 0;
- }
- else
- {
- zera = 0;
- jedynki++;
- }
- }
- if (zera < 26 && jedynki < 26)
- Console.WriteLine("[Test dlugiej serii] Pozytywny");
- else
- Console.WriteLine("[Test dlugiej serii] Negatywny");
- }
- public static void testPokerowy(String klucz)
- {
- int blok = 4;
- var ciagi = new Dictionary<String, int>();
- for (int i = 0; i < klucz.Length; i += blok)
- {
- String ciag = "";
- for(int j = 0; j < blok; ++j)
- {
- ciag += klucz[i + j];
- }
- try
- {
- ciagi[ciag]++;
- }
- catch (KeyNotFoundException)
- {
- ciagi[ciag] = 1;
- }
- }
- Console.WriteLine("[Test Pokerowy " + blok + " segmentowy] Wyniki:");
- /*
- foreach (var ciag in ciagi)
- {
- Console.WriteLine(ciag.Key + ": " + ciag.Value);
- }
- */
- double suma = 0;
- foreach (var ciag in ciagi)
- {
- suma += Math.Pow(ciag.Value, 2);
- }
- double x = 16.0 / 5000.0 * suma - 5000.0;
- Console.WriteLine("Wynik testu pokerowego: " + x);
- if (x > 2.16 && x < 46.17)
- {
- Console.WriteLine("Test pozytywny");
- }
- else
- {
- Console.WriteLine("Test negatywny");
- }
- }
- public static void testSerii(String klucz)
- {
- var serie = new Dictionary<int, int>();
- int zera = 0;
- foreach (char znak in klucz)
- {
- if (znak == '0')
- {
- zera++;
- }
- else if(zera > 0)
- {
- try
- {
- serie[zera]++;
- }
- catch (KeyNotFoundException)
- {
- serie[zera] = 1;
- }
- zera = 0;
- }
- }
- Console.WriteLine("[Test Serii] Wyniki:");
- foreach (var seria in serie)
- {
- Console.Write(seria.Key + ": " + seria.Value + " ");
- if (seriaPrzedzialy(seria.Key, seria.Value))
- Console.Write("Pozytywny");
- else
- Console.Write("Negatywny");
- Console.WriteLine();
- }
- }
- public static bool seriaPrzedzialy(int i, int j)
- {
- switch (i)
- {
- case 1:
- return j > 2315 && j < 2685;
- case 2:
- return j > 1114 && j < 1386;
- case 3:
- return j > 527 && j < 723;
- case 4:
- return j > 240 && j < 384;
- case 5:
- return j > 103 && j < 209;
- default:
- return j > 103 && j < 209;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement