Дешифрование данных - C#
Формулировка задачи:
Нужно реализовать дешифрирование данных к этой программе. У меня почему то не получается...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShifruVan
{
class Program
{
static void Main(string[] args)
{
int n = 1, key = 759;
Console.WriteLine("Введiть слово яке потрбiно зашифрувати:");
string s = Console.ReadLine();
Console.WriteLine("Величина зсуву:");
key = Convert.ToInt32(Console.ReadLine());
string s1 = "";
string alfphabet = "абвгдгдеєжзиiїйклмнопрстуфхцчшщьюя1234567890";
string alfphabet2 = alfphabet.ToUpper();
int m = alfphabet.Length;
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < alfphabet.Length; j++)
{
if (s[i] == alfphabet[j])
{
int temp = j * n + key;
while (temp >= m)
temp -= m;
s1 = s1 + alfphabet[temp];
}
}
}
Console.WriteLine("Зашифроване слово:" + s1);
Console.ReadLine();
}
}
}Решение задачи: «Дешифрование данных»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShifruVan
{
class Program
{
static void Main(string[] args)
{
int n = 1, key = 759;
Console.WriteLine("Введiть слово яке потрбiно зашифрувати:");
string s = Console.ReadLine();
string ss = s;
Console.WriteLine("Величина зсуву:");
key = Convert.ToInt32(Console.ReadLine());
string s1 = "";
string alfphabet = "абвгдгдеєжзиiїйклмнопрстуфхцчшщьюя1234567890";
string alfphabet2 = alfphabet.ToUpper();
int m = alfphabet.Length;
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < alfphabet.Length; j++)
{
if (s[i] == alfphabet[j])
{
int temp = j * n + key;
while (temp >= m)
temp -= m;
s1 = s1 + alfphabet[temp];
}
}
}
Console.WriteLine("Зашифроване слово:" + s1);
Console.WriteLine("Введите слово 'cyberforum' чтобы расшифровать зашифрованное слово: ");
while(Console.ReadLine() != "cyberforum")
{
Console.WriteLine("Неверная комманда");
}
Console.WriteLine("Расшифрованное слово:" + deshifr(s1, key));
Console.ReadLine();
}
//Функция дешифрование
static string deshifr(string s, int key)
{
int n = 1;
string s1 = "";
string alfphabet = "абвгдгдеєжзиiїйклмнопрстуфхцчшщьюя1234567890";
string alfphabet2 = alfphabet.ToUpper();
int m = alfphabet.Length;
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < alfphabet.Length; j++)
{
if (s[i] == alfphabet[j])
{
int temp = j * n - key;
while (temp >= m)
temp -= m;
if (temp <= -1)
{
temp = (alfphabet.Length + temp);
}
s1 = s1 + alfphabet[temp];
}
}
}
return s1;
}
}
}