Mam zrobić program szyfrujący GADERYPOLUKI(prosty szyfr podstawieniowy). Poniżej kod, który napisałem ale coś nie działa - funkcja zwraca to samo co przyjmuje.
- Poradzi ktoś co jest źle ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static class Gaderypoluki
{
public static string Encode(string key, string decodedText)
{
string encoded = decodedText;
StringBuilder en = new StringBuilder(encoded);
for (int i = 0; i < decodedText.Length; i++)
{
for (int j = 0; j < key.Length; j++)
{
if (decodedText[i] == key[j])
{
if (j % 2 == 0)
en[i] = key[j + 1];
else
en[i] = key[j - 1];
}
}
}
string encoded2 = en.ToString();
return encoded2;
}
}
static void Main(string[] args)
{
var key = "GADERYPOLUKI";
var decodedText = "xyz abcd";
var gadery = Gaderypoluki.Encode(key, decodedText);
Console.WriteLine(gadery);
Console.ReadKey();
}
}
}
- Chciałbym też móc w taki sposób wywołać tą klasę:
Tuple<string, int[]> actual = Gaderypoluki.Encode(key, encodedText);
Rozumiem że muszę w metodzie zwracać obiekt klasy Tuple? (teraz dostaję error że nie można skonwertować stringa na tuple)