Exemple #1
0
        public static void EncryptTextMenu()
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Zakoduj:");
                Console.WriteLine("1. Z wlasnym kluczem");
                Console.WriteLine("2. Z losowym kluczem");
                Console.WriteLine("3. Powrót");
                String c = Console.ReadLine();

                switch (c)
                {
                case "1":
                    Console.Clear();
                    Console.WriteLine("Podaj 64-bitowy klucz (ciąg 0/1):");
                    string textKey = Console.ReadLine();

                    if (textKey.Length != 64)
                    {
                        Console.WriteLine("Twoj klucz nie ma 64 bitów! ");
                        Console.ReadKey();
                        break;
                    }

                    int[] key = new int[64];
                    for (int i = 0; i < 64; i++)
                    {
                        key[i] = (int)(textKey[i] - '0');
                    }

                    Console.WriteLine("Podaj tekst do zakodowania (wejściowego):");
                    string input = Console.ReadLine();

                    string output = EncodeString(input, key);
                    Console.WriteLine("Twoj zakodowany tekst to: \"" + output + "\"");
                    Console.WriteLine("Twoj rozkodowany tekst to: \"" + DecodeString(output, key) + "\"");
                    //EncryptFromBinFileToBinFile(input, output, key);

                    Console.WriteLine("Naciśnij klawisz aby kontynuować...");
                    Console.ReadKey();
                    break;

                case "2":
                    Console.Clear();
                    Console.WriteLine("Twój klucz to:");
                    string textKey2 = "";
                    int[]  key2;
                    DES2   algorytm = new DES2();
                    algorytm.generateAndAssignRandomKey();
                    key2 = algorytm.getKey();
                    for (int i = 0; i < 64; i++)
                    {
                        textKey2 = textKey2 + key2[i];
                    }
                    Console.WriteLine(textKey2);

                    Console.WriteLine("Podaj tekst do zakodowania (wejściowego):");
                    string input2 = Console.ReadLine();

                    string output2 = EncodeString(input2, key2);
                    Console.WriteLine("Twoj zakodowany tekst to: \"" + output2 + "\"");
                    Console.WriteLine("Twoj rozkodowany tekst to: \"" + DecodeString(output2, key2) + "\"");
                    //EncryptFromBinFileToBinFile(input, output, key);

                    Console.WriteLine("Naciśnij klawisz aby kontynuować...");
                    Console.ReadKey();
                    break;

                case "3":
                    return;
                }
            }
        }
Exemple #2
0
        public static void DecryptMenu()
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Rozkoduj:");
                Console.WriteLine("1. Z wlasnym kluczem");
                Console.WriteLine("2. Z losowym kluczem");
                Console.WriteLine("3. Powrót");
                String c = Console.ReadLine();

                switch (c)
                {
                case "1":
                    Console.Clear();
                    Console.WriteLine("Podaj 64-bitowy klucz (ciąg 0/1):");
                    string textKey = Console.ReadLine();

                    if (textKey.Length != 64)
                    {
                        Console.WriteLine("Twoj klucz nie ma 64 bitów! ");
                        Console.ReadKey();
                        break;
                    }

                    int[] key = new int[64];
                    for (int i = 0; i < 64; i++)
                    {
                        key[i] = (int)(textKey[i] - '0');
                    }

                    Console.WriteLine("Podaj nazwę pliku do rozkodowania (wejściowego):");
                    string input = Console.ReadLine();

                    Console.WriteLine("Podaj nazwę pliku - wyjściowego:");
                    string output = Console.ReadLine();

                    Console.WriteLine("Podaj o iles bajtow skrocic plik (<=0 anuluja skracanie):");
                    int numOfBytes = Int32.Parse(Console.ReadLine());

                    DecryptFromBinFileToBinFile(input, output, key, numOfBytes);

                    Console.WriteLine("Naciśnij klawisz aby kontynuować...");
                    Console.ReadKey();
                    break;

                case "2":
                    Console.Clear();
                    Console.WriteLine("Twój klucz to:");
                    string textKey2 = "";
                    int[]  key2;
                    DES2   algorytm = new DES2();
                    algorytm.generateAndAssignRandomKey();
                    key2 = algorytm.getKey();
                    for (int i = 0; i < 64; i++)
                    {
                        textKey2 = textKey2 + key2[i];
                    }
                    Console.WriteLine(textKey2);

                    Console.WriteLine("Podaj nazwę pliku do rozkodowania (wejściowego):");
                    string input2 = Console.ReadLine();

                    Console.WriteLine("Podaj nazwę pliku - wyjściowego:");
                    string output2 = Console.ReadLine();

                    Console.WriteLine("Podaj o iles bajtow skrocic plik (<=0 anuluja skracanie):");
                    int numOfBytes2 = Int32.Parse(Console.ReadLine());

                    DecryptFromBinFileToBinFile(input2, output2, key2, numOfBytes2);

                    Console.WriteLine("Naciśnij klawisz aby kontynuować...");
                    Console.ReadKey();
                    break;

                case "3":
                    return;
                }
            }
        }