Beispiel #1
0
        private void rc4CryptFileBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (((this.rc4CtrCbx.Checked != true) && (this.rc4KeyTxtBox.Text != "")) ||
                    ((this.rc4CtrCbx.Checked == true) && (this.rc4KeyTxtBox.Text != "") && (this.rc4IVTxtBox.Text != "")))
                {
                    AlgorithmProperties metaData = new AlgorithmProperties()
                    {
                        Key      = Encoding.ASCII.GetBytes(rc4KeyTxtBox.Text),
                        FileName = System.IO.Path.GetFileName(ofd.FileName)
                    };
                    if (rc4CtrCbx.Checked == true)
                    {
                        metaData.AlgorithmType = AlgorithmType.RC4CTR;
                        metaData.IV            = Encoding.ASCII.GetBytes(rc4IVTxtBox.Text);
                    }
                    else
                    {
                        metaData.AlgorithmType = AlgorithmType.RC4;
                    }
                    Crypto.EncryptFile(ofd.FileName, metaData);
                }
                else
                {
                    MessageBox.Show("Polja nisu popunjena.");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dekriptovanje fajla A52
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void A52FileDecryptBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (((this.A52CtrModeCbox.Checked != true) && (this.A52KeyTxtBox.Text != "") && (this.f22TxtBox.Text != "")) ||
                    ((this.A52CtrModeCbox.Checked == true) && (this.A52KeyTxtBox.Text != "") && (this.A52IVtxtBox.Text != "") && (this.f22TxtBox.Text != "")))
                {
                    AlgorithmProperties metaData = new AlgorithmProperties()
                    {
                        Key      = Encoding.ASCII.GetBytes(A52KeyTxtBox.Text),
                        FileName = System.IO.Path.GetFileName(ofd.FileName),
                        FKeyA52  = f22TxtBox.Text
                    };
                    if (A52CtrModeCbox.Checked == true)
                    {
                        metaData.AlgorithmType = AlgorithmType.A52CTR;
                        metaData.IV            = Encoding.ASCII.GetBytes(A52IVtxtBox.Text);
                    }
                    else
                    {
                        metaData.AlgorithmType = AlgorithmType.A52;
                    }
                    Crypto.DecryptFile(ofd.FileName, metaData);
                }
                else
                {
                    MessageBox.Show("Polja nisu popunjena.");
                }
            }
        }
        private Container3D Create3DGuillotineCutContainer(AlgorithmProperties properties, int width, int height, int depth)
        {
            switch (properties.SplittingStrategy)
            {
            case (ContainerSplittingStrategy.MaxVolumeSplitRule):
                return(new GuillotineCutMaxVolumeContainer3D(width, height, depth));

            case (ContainerSplittingStrategy.MinVolumeSplitRule):
                return(new GuillotineCutMinVolumeContainer3D(width, height, depth));

            case (ContainerSplittingStrategy.LongerAxisSplitRule):
                return(new GuillotineCutLongerAxisContainer3D(width, height, depth));

            case (ContainerSplittingStrategy.LongerLeftoverAxisSplitRule):
                return(new GuillotineCutLongerLeftoverAxisContainer3D(width, height, depth));

            case (ContainerSplittingStrategy.ShorterAxisSplitRule):
                return(new GuillotineCutShorterAxisContainer3D(width, height, depth));

            case (ContainerSplittingStrategy.ShorterLeftoverAxisSplitRule):
                return(new GuillotineCutShorterLeftoverAxisContainer3D(width, height, depth));

            default:
                throw new NotSuchAlgorithmException();
            }
        }
Beispiel #4
0
 public void SetObjects(Algorithm algorithm)
 {
     AlgorithmProperties.Clear();
     foreach (var algorithmProperty in algorithm.AlgorithmProperties)
     {
         AlgorithmProperties.Add(algorithmProperty);
     }
 }
Beispiel #5
0
        private void Init()
        {
            generator           = new ObjectGenerator();
            containerFactory    = new ContainerFactory();
            factory             = new AlgorithmFactory();
            algorithmProperties = new AlgorithmProperties();
            results             = new AlgorithmExecutionResults();
            stopwatch           = new Stopwatch();

            HandleDimensionalityChange();
        }
Beispiel #6
0
        private IAlgorithm Create3DAlgorithm(AlgorithmProperties properties, Container3D initialContainer)
        {
            switch (properties.Family)
            {
            case (AlgorithmFamily.Shelf):
                return(Create3DShelfAlgorithm(properties.AlgorithmType, initialContainer));

            case (AlgorithmFamily.GuillotineCut):
                return(Create3DGuillotineAlgorithm(properties.AlgorithmType, properties.SplittingStrategy, initialContainer));

            default:
                throw new NotSuchAlgorithmException();
            }
        }
Beispiel #7
0
        public IAlgorithm Create(AlgorithmProperties properties, IFigure size)
        {
            switch (properties.Dimensionality)
            {
            case (AlgorithmDimensionality.TwoDimensional):
                return(Create2DAlgorithm(properties, size as Container2D));

            case (AlgorithmDimensionality.ThreeDimensional):
                return(Create3DAlgorithm(properties, size as Container3D));

            default:
                throw new NotSuchAlgorithmException();
            }
        }
Beispiel #8
0
        public static void Write(AlgorithmExecutionResults endResults, AlgorithmProperties properties, ObjectOrdering ordering, IFigure initialContainer, string filePath, string inputSetName)
        {
            if (!CheckDestinationCSV(filePath))
            {
                FileHelper.CreateNewFile(filePath);
            }
            //throw new InvalidArgumentException($"Cannot access target file at given path {filePath}");

            WriteHeaders(filePath);

            string containerSize = properties.Dimensionality.Equals(AlgorithmDimensionality.TwoDimensional) ? $"{(initialContainer as Container2D).Width}x{(initialContainer as Container2D).Height}" :
                                   $"{(initialContainer as Container3D).Width}x{(initialContainer as Container3D).Height}x{(initialContainer as Container3D).Depth}";

            File.AppendAllText(filePath,
                               $"{inputSetName};{properties.Dimensionality};{properties.Family};{properties.AlgorithmType};{properties.SplittingStrategy};{ordering};{containerSize};{endResults.AverageFulfillmentRatio};{endResults.Quality};{endResults.ExecutionTime};{endResults.ContainersUsed};{endResults.ObjectCount}" + Environment.NewLine);
        }
Beispiel #9
0
        public static async void DecryptFile(string fileName, AlgorithmProperties props)
        {
            await Task.Run(() =>
            {
                try
                {
                    using (var stream = File.OpenRead(fileName))
                    {
                        if (stream.Length > Crypto.MaxMessageSize)
                        {
                            throw new MaxSizeException("Velicina fajla prelazi maksimalnu dozvoljednu velicinu.");
                        }
                        props.FileName = Path.GetFileName(fileName);
                        // Pozove se funkcija za kriptovanje
                        MessageBox.Show(String.Format("Fajl {0} se kriptuje od strane FSW-a.", fileName));
                        bool finished = ServiceDriver.Instance.Decrypt(props, stream);

                        if (finished)
                        {
                            // Ukoliko su ulazni i izlazni folderi isti proveri se da li postoji fajl sa tim imenom
                            string path          = Crypto.GenerateFileName(Crypto.DstDir, props.FileName);
                            Stream encryptedData = ServiceDriver.Instance.DownloadFile(props.FileName);
                            using (var fileStream = File.Create(path))
                            {
                                encryptedData.CopyTo(fileStream);
                                MessageBox.Show(String.Format("Fajl {0} je uspesno kriptovan.", props.FileName), "File System Watcher");
                            }
                        }
                        else
                        {
                            MessageBox.Show(String.Format("Fajl {0} nije uspesno kriptovan.", props.FileName), "File System Watcher");
                        }
                    }
                }
                catch (MaxSizeException me)
                {
                    MessageBox.Show(me.Message);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Doslo je do greske pri radu buffering queue-a FSW-a.");
                }
            });
        }
        public Container3D Create(AlgorithmProperties properties, int Width, int Height, int Depth)
        {
            if (properties.Dimensionality != AlgorithmDimensionality.ThreeDimensional)
            {
                throw new NotSuchAlgorithmException();
            }

            switch (properties.Family)
            {
            case (AlgorithmFamily.Shelf):
                return(new ShelfContainer3D(Width, Height, Depth));

            case (AlgorithmFamily.Skyline):
                throw new NotSuchAlgorithmException();

            case (AlgorithmFamily.GuillotineCut):
                return(Create3DGuillotineCutContainer(properties, Width, Height, Depth));

            default:
                throw new NotSuchAlgorithmException();
            }
        }
Beispiel #11
0
        private static void ProcessArguments(string[] args)
        {
            InputFilePath = args[0];

            string pathWithoutFile = Path.GetDirectoryName(InputFilePath);
            string fileWithoutPath = Path.GetFileName(InputFilePath);

            bool hasThreeSizes = false;

            if (string.IsNullOrEmpty(pathWithoutFile))
            {
                pathWithoutFile = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            }
            else if (!Directory.Exists(pathWithoutFile))
            {
                Directory.CreateDirectory(pathWithoutFile);
            }

            InputFilePath = pathWithoutFile + "//" + fileWithoutPath;

            OutputFilePath = args.Last();

            if (!Directory.Exists(OutputFilePath) && !File.Exists(OutputFilePath))
            {
                OutputFilePath = pathWithoutFile + "\\" + OutputFilePath;
                if (!File.Exists(OutputFilePath))
                {
                    File.Create(OutputFilePath);
                }
            }

            if (!OutputFilePath.EndsWith(".csv"))
            {
                OutputFilePath += ".csv";
            }

            ContainerWidth  = Int32.Parse(args[1]);
            ContainerHeight = Int32.Parse(args[2]);

            int tmpDepth;

            if (Int32.TryParse(args[3], out tmpDepth))
            {
                ContainerDepth = tmpDepth;
                hasThreeSizes  = true;
            }

            Properties = new AlgorithmProperties();

            if (hasThreeSizes)
            {
                if (args.Count() > 5 && arguments.Contains(args[4]))
                {
                    RecognizePair(args[4], args[5]);
                }
                if (args.Count() > 7 && arguments.Contains(args[6]))
                {
                    RecognizePair(args[6], args[7]);
                }
                if (args.Count() > 9 && arguments.Contains(args[8]))
                {
                    RecognizePair(args[8], args[9]);
                }
                if (args.Count() > 11 && arguments.Contains(args[10]))
                {
                    RecognizePair(args[10], args[11]);
                }
            }
            else
            {
                if (args.Count() > 4 && arguments.Contains(args[3]))
                {
                    RecognizePair(args[3], args[4]);
                }
                if (args.Count() > 6 && arguments.Contains(args[5]))
                {
                    RecognizePair(args[5], args[6]);
                }
                if (args.Count() > 8 && arguments.Contains(args[7]))
                {
                    RecognizePair(args[7], args[8]);
                }
                if (args.Count() > 10 && arguments.Contains(args[9]))
                {
                    RecognizePair(args[9], args[10]);
                }
            }
        }
Beispiel #12
0
 public void AddProperty(AlgorithmProperty additionParams)
 {
     AlgorithmProperties.Add(additionParams);
 }
Beispiel #13
0
        // Procesira queue
        public async void ProcessQueue()
        {
            string fullName = this.Peek().ToString();
            Task   t        = Task.Run(() =>
            {
                try
                {
                    using (var stream = File.OpenRead(fullName))
                    {
                        if (stream.Length > Crypto.MaxMessageSize)
                        {
                            throw new MaxSizeException("Enqueued file is too large.");
                        }
                        AlgorithmProperties metaData = new AlgorithmProperties()
                        {
                            FileName      = Path.GetFileName(fullName),
                            AlgorithmType = AlgorithmType.RC4,
                            Key           = Crypto.KeyRC4
                        };
                        // Pozove se funkcija za kriptovanje
                        MessageBox.Show(String.Format("File {0} is being crypted by FSW.", fullName));
                        bool finished = ServiceDriver.Instance.Encrypt(metaData, stream);

                        if (finished)
                        {
                            // Ukoliko su ulazni i izlazni folderi isti proveri se da li postoji fajl sa tim imenom
                            string path          = Crypto.GenerateFileName(Crypto.DstDir, metaData.FileName);
                            Stream encryptedData = ServiceDriver.Instance.DownloadFile(metaData.FileName);

                            if (Crypto.SrcDir == Crypto.DstDir)
                            {
                                AlreadyEncrypted.Add(path);
                            }

                            using (var fileStream = File.Create(path))
                            {
                                encryptedData.CopyTo(fileStream);
                                MessageBox.Show(String.Format("File {0} has been successfully crypted.", metaData.FileName), "File System Watcher");
                            }
                        }
                        else
                        {
                            MessageBox.Show(String.Format("Error while crypting {0} ", metaData.FileName), "File System Watcher");
                        }
                    }
                }
                catch (MaxSizeException me)
                {
                    MessageBox.Show(me.Message);
                }
                catch (Exception e)
                {
                    MessageBox.Show("There has been an error while processing queue.");
                }
            });
            await t;

            AlreadyEncrypted.Add(fullName);
            this.Dequeue();
            if (this.Count != 0)
            {
                ProcessQueue();
            }
        }