ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π±ΠΎΠ»ΡΡΠΈΡ ΡΠΈΡΠ΅Π» Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ
ΠΠΈΡΡΠΈΠ½Π³ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ: Using System.Collections.Generic; Using System.Collections.Generic; Using System.Collections.Generic; For (int i = 0; i < lenght; i++). Π Π°Π±ΠΎΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ: Int bits = thisVal. bitCount (); BigInteger a = newBigInteger (); If (lfsr.GetBits () == true). Array = newBitArray (lenght); For (int i = 0; i < k; i++). For (int i = 0; i < d; i++). ClassSelfDecimatedGenerator. Random rand… Π§ΠΈΡΠ°ΡΡ Π΅ΡΡ >
ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π±ΠΎΠ»ΡΡΠΈΡ ΡΠΈΡΠ΅Π» Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ (ΡΠ΅ΡΠ΅ΡΠ°Ρ, ΠΊΡΡΡΠΎΠ²Π°Ρ, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ)
ΠΠΈΠ½ΠΈΡΡΠ΅ΡΡΡΠ²ΠΎ ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½ΠΈΡ Π Π΅ΡΠΏΡΠ±Π»ΠΈΠΊΠΈ ΠΠ΅Π»Π°ΡΡΡΡ Π£ΡΡΠ΅ΠΆΠ΄Π΅Π½ΠΈΠ΅ ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½ΠΈΡ
«ΠΡΠ΅ΡΡΡΠΊΠΈΠΉ Π³ΠΎΡΡΠ΄Π°ΡΡΡΠ²Π΅Π½Π½ΡΠΉ ΡΠ΅Ρ Π½ΠΈΡΠ΅ΡΠΊΠΈΠΉ ΡΠ½ΠΈΠ²Π΅ΡΡΠΈΡΠ΅Ρ»
ΠΠ°ΡΠ΅Π΄ΡΠ° ΠΠΠ’
ΠΠ°Π±ΠΎΡΠ°ΡΠΎΡΠ½Π°Ρ ΡΠ°Π±ΠΎΡΠ° β4
ΠΠΎ Π΄ΠΈΡΡΠΈΠΏΠ»ΠΈΠ½Π΅ «ΠΡΠΈΠΏΡΠΎΠ³ΡΠ°ΡΠΈΡ»
ΠΠΎ ΡΠ΅ΠΌΠ΅ «ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π±ΠΎΠ»ΡΡΠΈΡ ΡΠΈΡΠ΅Π» Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ»
ΠΡΠΏΠΎΠ»Π½ΠΈΠ»Π° Π‘ΡΡΠ΄Π΅Π½ΡΠΊΠ° III ΠΊΡΡΡΠ° ΠΡΡΠΏΠΏΡ ΠΠ-5 ΠΠ»Π΅Ρ Π½ΠΈΠΊ Π.Π.
ΠΡΠΎΠ²Π΅ΡΠΈΠ» Π₯Π°ΡΠΊΠ΅Π²ΠΈΡ Π.Π.
ΠΡΠ΅ΡΡ 2010
Π’Π΅ΠΌΠ°: ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π±ΠΎΠ»ΡΡΠΈΡ ΡΠΈΡΠ΅Π» Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ. ΠΠ΅ΡΠΎΠ΄ Π€Π΅ΡΠΌΠ°.
Π¦Π΅Π»Ρ: ΠΠ·ΡΡΠΈΡΡ ΠΌΠ΅ΡΠΎΠ΄Ρ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΠΈ ΠΈ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ Π±ΠΎΠ»ΡΡΠΈΡ ΡΠΈΡΠ΅Π».
Π₯ΠΎΠ΄ ΡΠ°Π±ΠΎΡΡ:
ΠΠΈΡΡΠΈΠ½Π³ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ:
Program.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Text;
namespace Tania_KMZILab3
{
classProgram
{
staticvoid Main ()
{
BigInteger bigInteger;
do
{
SelfDecimatedGenerator generator = newSelfDecimatedGenerator (98); // Π² ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡΠ΅ Π·Π°Π΄Π°ΡΡ Π΄Π»ΠΈΠ½Ρ ΡΠΈΡΠ»Π°Π² Π±ΠΈΡΠ°Ρ
bigInteger = newBigInteger (generator.Generate (), 2); // ΡΠΎΠ·Π΄Π°ΡΠΌ Π±ΠΎΠΎΠΎΠΎΠ»ΡΡΠΎΠ΅ ΡΠΈΡΠ»ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠΌ ΠΊΠ°ΠΊ ΠΏΠ΅ΡΠ²ΡΠΉ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ ΡΡΠΎΠΊΡ Π²ΡΠΎΡΠΎΠΉ 2-ΡΡΠΎ Π·Π½Π°ΡΠΈΡ Π΄Π²ΠΎΠΈΡΠ½Π°Ρ ΡΠΈΡΡΠ΅ΠΌΠ°
}
while (!Ferma.FermatLittleTest (50, bigInteger));
Console.WriteLine (bigInteger); // Π²ΡΠ²ΠΎΠ΄ Π½Π° ΠΊΠΎΠ½ΡΠΎΠ»Ρ ΡΠΈΡΠ»Π°
Console.WriteLine (Ferma.FermatLittleTest (50, bigInteger));
Console.ReadKey (); // ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΠ΅ Π½Π°ΠΆΠ°ΡΠΈΡ ΠΊΠ»Π°Π²ΠΈΡΠΈ Ρ ΠΊΠΎΠ½ΡΠΎΠ»ΠΈ
}
}
}
Ferma.cs
using System;
namespace Tania_KMZILab3
{
staticclassFerma
{
staticpublicbool FermatLittleTest (int confidence, BigInteger thisVal)
{
if ((thisVal % 2) == 0)
returnfalse;
int bits = thisVal. bitCount ();
BigInteger a = newBigInteger ();
Random rand = newRandom ();
for (int round = 0; round < confidence; round++)
{
SelfDecimatedGenerator generator = newSelfDecimatedGenerator (40); // Π² ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡΠ΅ Π·Π°Π΄Π°ΡΡ Π΄Π»ΠΈΠ½Ρ ΡΠΈΡΠ»Π°Π² Π±ΠΈΡΠ°Ρ
a = newBigInteger (generator.Generate (), 2);
BigInteger expResult = a. modPow (thisVal — 1, thisVal);
if (expResult ≠ 1)
{
returnfalse;
}
}
returntrue;
}
}
}
SelfDecimatedGenerator.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System. Collections;
namespace Tania_KMZILab3
{
classSelfDecimatedGenerator
{
privateLFSR lfsr;
privateint k = 10;
privateint d = 23;
public SelfDecimatedGenerator (int length
{
lfsr = newLFSR (length);
lfsr.UseRegister ();
}
publicstring Generate ()
{
if (lfsr.Quantity ())
{
for (int i = 0; i < k; i++)
lfsr.UseRegister ();
}
else
{
for (int i = 0; i < d; i++)
lfsr.UseRegister ();
}
string bitString = «» ;
for (int i = 0; i < lfsr. GetBits ().Length; i++)
{
if (lfsr.GetBits ()[i] == true)
bitString += «1» ;
else
bitString += «0» ;
}
return bitString;
}
}
}
LFSR.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System. Collections;
namespace Tania_KMZILab3
{
classLFSR
{
privateBitArray Array;
privatebool outBit;
publicBitArray GetBits ()
{
return Array;
}
public LFSR (int lenght)
{
Array = newBitArray (lenght);
Random rnd = newRandom ();
for (int i = 0; i < lenght; i++)
{
if ((rnd.Next (0, 1000) % 2) == 0)
{
Array[i] = true;
}
else
{
Array[i] = false;
}
}
}
publicvoid UseRegister ()
{
bool feedBack;
feedBack = Array. Get (15) ^ Array. Get (10) ^ Array. Get (15) ^ Array. Get (12);
outBit = Array. Get (Array.Length — 1);
for (int i = 0; i < (Array.Length — 1); i++)
{
Array.Set (Array.Length — i — 1, Array. Get (Array.Length — i — 2));
}
Array.Set (0, feedBack);
}
publicbool Quantity ()
{
if (outBit == false)
{
returnfalse;
}
elsereturntrue;
}
}
}
Π Π°Π±ΠΎΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ:
True
True
True
ΠΡΠ²ΠΎΠ΄: ΠΠ·ΡΡΠΈΠ»ΠΈ ΠΌΠ΅ΡΠΎΠ΄Ρ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΠΉ Π±ΠΎΠ»ΡΡΠΈΡ ΠΏΡΠΎΡΡΡΡ ΡΠΈΡΠ΅Π», Π° ΡΠ°ΠΊ ΠΆΠ΅ ΡΠΏΠΎΡΠΎΠ±Ρ ΠΈΡ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ.