Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
enigma 2
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static String mMessage = "Esperar algo mejor para el futuro me parece una fantasia. La naturaleza humana no cambia."; public class Rotor { static int mPrime = 122949823; int[] mEncode, mDecode; int mMax, mPosition; public Rotor(int pMax) { mPosition = 0; mMax = pMax; mEncode = new int[mMax]; mDecode = new int[mMax]; InitRotor(); } void InitRotor() { List<int> oIndexes = new List<int>(); for (int i=0; i<mMax; i++) oIndexes.Add(i); for (int i=0; i<mMax; i++) { int iIndex = (mPrime % (mMax+1-i)) - 1; mEncode[i] = oIndexes[iIndex] - i; mDecode[oIndexes[iIndex]] = i - oIndexes[iIndex]; oIndexes.RemoveAt(iIndex); } } public int GetEncodedInt(int iVal) { int iIndex = (mPosition + iVal) % mMax; Rotate(); int iResult = (iIndex + mEncode[iIndex] + mMax) % mMax; return iResult; } public int GetDecodedInt(int iVal) { int iIndex = (mPosition + iVal) % mMax; Rotate(); int iResult = (iIndex + mDecode[iIndex] + mMax) % mMax; return iResult; } void Rotate() { mPosition = (mPosition + 1) % mMax; } public void SetPosition(int pPos) { mPosition = pPos; } } public static void Main(string[] args) { Rotor oRotor = new Rotor(5); int n = 5; int[] iCoded = new int[n]; for (int i=0; i<n; i++) { iCoded[i] = oRotor.GetEncodedInt(i); // iCoded[i] = oRotor.GetEncodedInt(7); Console.WriteLine(iCoded[i]); } Console.WriteLine("----------"); oRotor.SetPosition(0); for (int i=0; i<n; i++) { int iVal = oRotor.GetDecodedInt(iCoded[i]); Console.WriteLine(iVal); } } } }
run
|
edit
|
history
|
help
0
Classes
CodeAdvent
Cenforce 100 mg
30272 Ex if...
FindSmallest
Метод catch b try в словарях
T
csharp enum
30272 Example1
asfdfsafasfsa