Пример #1
0
 static void IsInforequired()
 {
     if (TypesOfParameters.Contains("/?"))
     {
         InformationScreen();
     }
 }
Пример #2
0
 static bool CheckValidParameters_d_v()
 {
     if (TypesOfParameters.Contains("/d") && TypesOfParameters.Contains("/v"))
     {
         Console.WriteLine("Invalid parameter {0}", "/v");
         return(false);
     }
     return(true);
 }
Пример #3
0
        static bool CheckKey()
        {
            if (!TypesOfParameters.Contains("/k"))
            {
                Console.WriteLine("Key not specified");
                return(false);
            }

            bool isHex = Regex.IsMatch(Key, "^[0-9a-fA-F]+$");

            if (!isHex)
            {
                Console.WriteLine("Invalid key format");
                return(false);
            }
            return(true);
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (!CheckFirstInput(args))
            {
                return;
            }
            if (!FileExists(args[0]))
            {
                return;
            }

            FileInput = args[0];
            byte[] fileContent = null;

            if (!SetAndCheckParameters(args))
            {
                return;
            }
            IsInforequired();

            if (!CheckKey())
            {
                return;
            }
            if (!CheckValidParameters_d_v())
            {
                return;
            }

            try
            {
                fileContent = File.ReadAllBytes(FileInput);
            }
            catch (IOException)
            {
                Console.WriteLine("Operation failed");
                return;
            }

            long fileLength = GetLength(fileContent);

            fileContent = Normalize(fileContent);

            byte[] finalValue = null;
            bool   encrypted  = false;

            if (!TypesOfParameters.Contains("/d"))
            {
                if (TypesOfParameters.Contains("/v"))
                {
                    finalValue = EncryptWithCRC(fileContent, fileLength);
                    encrypted  = true;
                }
                else
                {
                    finalValue = EncryptWithoutCRC(fileContent);
                    encrypted  = true;
                }

                if (TypesOfParameters.Contains("/o") && encrypted)
                {
                    if (!FileFill(FileOutput, finalValue))
                    {
                        return;
                    }
                    else if (!FileExists(FileOutput))
                    {
                        return;
                    }
                }
                else if (encrypted)
                {
                    if (!FileCreateAndFillEncryption(finalValue))
                    {
                        return;
                    }
                }
            }
            else
            {
                finalValue = Decryption(fileContent);

                if (BytesArrayIsZero(finalValue))
                {
                    return;
                }
                else
                {
                    if (TypesOfParameters.Contains("/o"))
                    {
                        if (!FileFill(FileOutput, finalValue))
                        {
                            return;
                        }
                        else if (!FileExists(FileOutput))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (!FileCreateAndFillDecryption(finalValue))
                        {
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("Operation successful! ");
            Console.ReadKey();
        }