public string RusEncrypt(string text) { text = text.ToLower(); string result_text = ""; if (text.Length % 2 != 0) { text += 'я'; } int length = text.Length / 2; int k = 0; char[,] bigram = new char[length, 2]; char[,] kripto_bigram = new char[length, 2]; for (int i = 0; i < length; i++) { for (int j = 0; j < 2; j++) { bigram[i, j] = text[k]; k++; } } print(); int step = 0; while (step < length) { Cortege cortege1 = FindIndexes(bigram[step, 0], firstMatrix); Cortege cortege2 = FindIndexes(bigram[step, 1], secondMatrix); kripto_bigram[step, 0] = secondMatrix[cortege1.I, cortege2.J]; kripto_bigram[step, 1] = firstMatrix[cortege2.I, cortege1.J]; step++; } for (int i = 0; i < length; i++) { for (int j = 0; j < 2; j++) { result_text += kripto_bigram[i, j].ToString(); } result_text += " "; } return(result_text); }
private Cortege FindIndex(char symbol, char[,] matrix) { Cortege cortege = new Cortege(); for (int firstIndex = 0; firstIndex < matrix.GetLength(0); firstIndex++) { for (int secondIndex = 0; secondIndex < matrix.GetLength(1); secondIndex++) { if (symbol == matrix[firstIndex, secondIndex]) { cortege.FIndex = firstIndex; cortege.SIndex = secondIndex; return(cortege); } } } return(null); }
private Cortege FindIndexes(char symbol, char[,] matrix) { Cortege cortege = new Cortege(); for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { if (symbol == matrix[i, j]) { cortege.I = i; cortege.J = j; return(cortege); } } } return(null); }
/// <summary> /// New position in stream. /// </summary> /// <param name="svc"></param> /// <param name="line">Received line.</param> /// <returns>true if it was processed by current handler, otherwise it means ignoring.</returns> public override bool Positioned(ISvc svc, RawText line) { if (svc.Sln.ProjectConfigList == null) { svc.Sln.ProjectConfigList = new List <IConfPlatformPrj>(); } /* * [Projects Guid] [Solution pair] [Project pair] * {A7BF1F9C-F18D-423E-9354-859DC3CFAFD4}.CI_Release|Any CPU.ActiveCfg = Release|Any CPU - configuration name * {A7BF1F9C-F18D-423E-9354-859DC3CFAFD4}.CI_Release|Any CPU.Build.0 = Release|Any CPU - flag of build (this line exists only when this flag is true) */ string _line; var cortege = new Dictionary <Cortege, ConfigPrj>(new EqCortegeComparer()); while ((_line = svc.ReadLine(this)) != null && _line.Trim() != "EndGlobalSection") { int x, y; x = _line.IndexOf('.'); var pGuid = _line.Substring(0, x).Trim(); y = _line.IndexOf('.', ++x); string csln = _line.Substring(x, y - x).Trim(); x = _line.IndexOf('=', ++y); string type = _line.Substring(y, x - y).Trim(); string cprj = _line.Substring(x + 1).Trim(); bool isActiveCfg = type.Equals("ActiveCfg", StringComparison.OrdinalIgnoreCase); bool isBuild0 = type.Equals("Build.0", StringComparison.OrdinalIgnoreCase); bool isDeploy0 = type.Equals("Deploy.0", StringComparison.OrdinalIgnoreCase); if (!isActiveCfg && !isBuild0 && !isDeploy0) { LSender.Send(this, $"Project Configuration has been ignored for line '{_line}'", Message.Level.Debug); continue; } var ident = new Cortege() { pGuid = pGuid, csln = csln, cprj = cprj, }; if (!cortege.ContainsKey(ident)) { LSender.Send(this, $"New Project Configuration `{pGuid}`, `{csln}` = `{cprj}` /{type}", Message.Level.Info); cortege[ident] = new ConfigPrj(cprj, pGuid, isBuild0, new ConfigSln(csln)); svc.Sln.ProjectConfigList.Add(cortege[ident]); continue; } if (isBuild0) { LSender.Send(this, $"Project Configuration, update Build.0 `{pGuid}`", Message.Level.Debug); cortege[ident].IncludeInBuild = true; continue; } if (isDeploy0) { LSender.Send(this, $"Project Configuration, update Deploy.0 `{pGuid}`", Message.Level.Debug); cortege[ident].IncludeInDeploy = true; continue; } } return(true); }
public string EngDecrypt(string text) { string result = ""; text = text.ToLower(); int length = text.Length / 2; int position = 0; char[,] bigram = new char[length, 2]; char[,] cryptBigram = new char[length, 2]; for (int firstIndex = 0; firstIndex < length; firstIndex++) { for (int secondIndex = 0; secondIndex < 2; secondIndex++) { bigram[firstIndex, secondIndex] = text[position]; position++; } } Console.Write("Input left key: "); string leftKey = Convert.ToString(Console.ReadLine()); Console.Write("Input right key: "); string rightKey = Convert.ToString(Console.ReadLine()); char[,] firstMatrix = new char[5, 5]; firstMatrix = FillEngMatrix(firstMatrix, leftKey); Console.WriteLine("\t__________First Matrix__________"); for (int firstIndex = 0; firstIndex < firstMatrix.GetLength(0); firstIndex++) { for (int secondIndex = 0; secondIndex < firstMatrix.GetLength(1); secondIndex++) { Console.Write("\t" + firstMatrix[firstIndex, secondIndex]); } Console.WriteLine(); } Console.WriteLine("\t_________________________________"); char[,] second_matrix = new char[5, 5]; second_matrix = FillEngMatrix(second_matrix, rightKey); Console.WriteLine("\n\t__________Second Matrix__________"); for (int firstIndex = 0; firstIndex < second_matrix.GetLength(0); firstIndex++) { for (int seconIndex = 0; seconIndex < second_matrix.GetLength(1); seconIndex++) { Console.Write("\t" + second_matrix[firstIndex, seconIndex]); } Console.WriteLine(); } Console.WriteLine("\t_________________________________"); int step = 0; while (step < length) { Cortege cortege1 = FindIndex(bigram[step, 0], second_matrix); Cortege cortege2 = FindIndex(bigram[step, 1], firstMatrix); cryptBigram[step, 0] = firstMatrix[cortege1.FIndex, cortege2.SIndex]; cryptBigram[step, 1] = second_matrix[cortege2.FIndex, cortege1.SIndex]; step++; } for (int firstIndex = 0; firstIndex < length; firstIndex++) { for (int secondIndex = 0; secondIndex < 2; secondIndex++) { result += cryptBigram[firstIndex, secondIndex].ToString(); } } return(result); }
public string RusEncrypt(string text) { text = text.ToLower(); string result = ""; if (text.Length % 2 != 0) { text += 'я'; } int size = text.Length / 2; int position = 0; char[,] bigram = new char[size, 2]; for (int firstIndex = 0; firstIndex < size; firstIndex++) { for (int secondIndex = 0; secondIndex < 2; secondIndex++) { bigram[firstIndex, secondIndex] = text[position]; position++; } } Console.Write("Введите левый ключ: "); string leftKey = Convert.ToString(Console.ReadLine()); Console.Write("Введите правый ключ: "); string rightKey = Convert.ToString(Console.ReadLine()); char[,] firstMatrix = new char[8, 4]; firstMatrix = FillRusMatrix(firstMatrix, leftKey); Console.WriteLine("\n\t_____Первая матрица_____"); for (int firstIndex = 0; firstIndex < firstMatrix.GetLength(0); firstIndex++) { for (int secondIndex = 0; secondIndex < firstMatrix.GetLength(1); secondIndex++) { Console.Write("\t" + firstMatrix[firstIndex, secondIndex]); } Console.WriteLine(); } Console.WriteLine("\t_________________________"); char[,] secondMatrix = new char[8, 4]; secondMatrix = FillRusMatrix(secondMatrix, rightKey); Console.WriteLine("\n\t_____Вторая матрица_____"); for (int firstIndex = 0; firstIndex < secondMatrix.GetLength(0); firstIndex++) { for (int secondIndex = 0; secondIndex < secondMatrix.GetLength(1); secondIndex++) { Console.Write("\t" + secondMatrix[firstIndex, secondIndex]); } Console.WriteLine(); } Console.WriteLine("\t_________________________"); char[,] cryptBigram = new char[size, 2]; int step = 0; while (step < size) { Cortege cortege1 = FindIndex(bigram[step, 0], firstMatrix); Cortege cortege2 = FindIndex(bigram[step, 1], secondMatrix); cryptBigram[step, 0] = secondMatrix[cortege1.FIndex, cortege2.SIndex]; cryptBigram[step, 1] = firstMatrix[cortege2.FIndex, cortege1.SIndex]; step++; } for (int firstIndex = 0; firstIndex < size; firstIndex++) { for (int secondIndex = 0; secondIndex < 2; secondIndex++) { result += cryptBigram[firstIndex, secondIndex].ToString(); } result += " "; } return(result); }