Ejemplo n.º 1
0
		public MainWindow()
		{
			InitializeComponent();
			_incrementProgress = delegate
			{
				Progress.Value++;
				Title = Convert.ToString(Progress.Value) + " from " + Convert.ToString(Progress.Maximum);
			};
			_setMaximum = delegate { Progress.Maximum = _max; };
			_closeApp = Close;
		}
Ejemplo n.º 2
0
 public MainWindow()
 {
     InitializeComponent();
     _incrementProgress = delegate
     {
         Progress.Value++;
         Title = Convert.ToString(Progress.Value) + " from " + Convert.ToString(Progress.Maximum);
     };
     _setMaximum = delegate { Progress.Maximum = _max; };
     _closeApp   = Close;
 }
Ejemplo n.º 3
0
        public static void StartEncryptDecrypt(string iFileName, string oFileName, UInt64 key, CouplingMode couplingMode, bool isEncrypt = true)
        {
            codingValue   = 0;
            _key          = key;
            _wasEncrypted = 0;

            FileStream iFStream = new FileStream(iFileName, FileMode.Open);

            using (BinaryReader iFileStream = new BinaryReader(iFStream))
            {
                var lenght = iFStream.Length;                    //количество байт
                SetMaximum.Invoke(lenght * 3 / 8);
                ulong  blocks        = (ulong)lenght / (ulong)8; //количество unsigned long int (UInt64)
                ulong  cryptedBlocks = 0;
                UInt64 block         = 0;
                _blocks.Clear();
                using (BinaryWriter oFileStream = new BinaryWriter(new FileStream(oFileName, FileMode.Create)))
                {
                    while (blocks > cryptedBlocks)
                    {
                        block = iFileStream.ReadUInt64();
                        _blocks.Add(block);
                        //Write(block.ToString());
                        block = 0;

                        cryptedBlocks++;

                        codingValue++;
                        SetValue.Invoke(codingValue);
                    }

                    if (isEncrypt)
                    {
                        if (lenght % 8 != 0)
                        {
                            for (int i = 0; i < lenght % 8; i++)
                            {
                                var bt = (byte)iFileStream.ReadByte();
                                block  = block << 8;
                                block |= bt;
                            }
                            block = MakeFullBlock(block, (int)(lenght % 8));
                        }
                        else
                        {
                            block = 8;
                        }
                        _blocks.Add(block);
                        //Write(block.ToString());
                        codingValue++;
                        SetValue.Invoke(codingValue);
                    }

                    List <UInt64> newBlocks = new List <ulong>();

                    switch (SetCouplingMode)
                    {
                    case CouplingMode.ECB:
                        newBlocks = ECB(isEncrypt);
                        break;

                    case CouplingMode.CBC:
                        newBlocks = CBC(isEncrypt);
                        break;

                    case CouplingMode.CFB:
                        newBlocks = CFB(isEncrypt);
                        break;

                    case CouplingMode.OFB:
                        newBlocks = OFB(isEncrypt);
                        break;
                    }

                    for (int i = 0; i < newBlocks.Count; i++)
                    {
                        var tmpBlock = newBlocks[i];
                        if (!isEncrypt && i == newBlocks.Count - 1)
                        {
                            var tmp = MakeCuttedBlock(tmpBlock);
                            if (tmp.Length != 10)
                            {
                                foreach (var b in tmp)
                                {
                                    oFileStream.Write(b);
                                }
                            }
                        }
                        else
                        {
                            oFileStream.Write(tmpBlock);
                            //Write(tmpBlock.ToString());
                        }
                        codingValue++;
                        SetValue.Invoke(codingValue);
                    }

                    EncodeFinished($"Файл\n{iFileName}\nуспешно зашифрован\n\nСоздан файл\n{oFileName}\nс шифротекстом");
                }
            }
        }
 private void Import()
 {
     if (File.Exists(localeo_path.Text) && File.Exists(ipo_path.Text) && Directory.Exists(Path.GetDirectoryName(olocale_path.Text)))
     {
         if (import_msg.InvokeRequired)
         {
             SetTextCallback d = new SetTextCallback(SetText);
             this.Invoke(d, new object[] { "" });
         }
         using (Stream stream = new FileStream(localeo_path.Text, FileMode.Open, FileAccess.Read))
         {
             Locale m_Locale = DataSerializer.Deserialize <Locale>(stream, DataSerializer.Mode.File);
             Dictionary <Locale.Key, string> m_LocalizedStrings = Utils.GetPrivateField <Dictionary <Locale.Key, string> >(m_Locale, "m_LocalizedStrings");
             Dictionary <Locale.Key, string> l_LocalizedStrings = new Dictionary <Locale.Key, string>(m_LocalizedStrings);
             List <string> lines = new List <string>();
             using (StreamReader file = new StreamReader(ipo_path.Text))
             {
                 string line;
                 while ((line = file.ReadLine()) != null)
                 {
                     lines.Add(line);
                 }
             }
             if (progress.InvokeRequired)
             {
                 SetMaximum d = new SetMaximum(SetMaximum);
                 this.Invoke(d, new object[] { lines.Count });
             }
             if (progress.InvokeRequired)
             {
                 SetVisible d = new SetVisible(SetVisible);
                 this.Invoke(d, new object[] { true });
             }
             Regex regex        = new Regex(@"#. ""(.+)\[(.+)\]:(\d+)""|#. ""(.+):(\d+)""");
             Regex regex_msgid  = new Regex(@"msgid ""(.+)""");
             Regex regex_msgstr = new Regex(@"msgstr ""(.+)""");
             for (int i = 0; i < lines.Count; i++)
             {
                 if (progress.InvokeRequired)
                 {
                     SetValue d = new SetValue(SetValue);
                     this.Invoke(d, new object[] { i + 1 });
                 }
                 if (i + 2 < lines.Count && regex.IsMatch(lines[i]))
                 {
                     string m_Identifier = regex.Match(lines[i]).Groups[1].Value.Length != 0 ? regex.Match(lines[i]).Groups[1].Value : regex.Match(lines[i]).Groups[4].Value;
                     string m_Index      = regex.Match(lines[i]).Groups[3].Value.Length != 0 ? regex.Match(lines[i]).Groups[3].Value : regex.Match(lines[i]).Groups[5].Value;
                     string m_Key        = regex.Match(lines[i]).Groups[2].Value.Length != 0 ? regex.Match(lines[i]).Groups[2].Value : null;
                     string msgid        = regex_msgid.Match(lines[i + 1]).Groups[1].Value;
                     string msgstr       = regex_msgstr.Match(lines[i + 2]).Groups[1].Value;
                     if (msgid.Length != 0)
                     {
                         Locale.Key key = new Locale.Key();
                         key.m_Identifier = m_Identifier;
                         key.m_Index      = int.Parse(m_Index);
                         key.m_Key        = m_Key;
                         if (l_LocalizedStrings.ContainsKey(key))
                         {
                             l_LocalizedStrings.Remove(key);
                             l_LocalizedStrings.Add(key, msgid.Replace(@"\r", "\r").Replace(@"\n", "\n"));
                         }
                         else
                         {
                             l_LocalizedStrings.Add(key, msgid.Replace(@"\r", "\r").Replace(@"\n", "\n"));
                         }
                     }
                 }
             }
             string m_EnglishName = language_e.Text;
             string m_NativeName  = language.Text;
             if (m_EnglishName.Length != 0)
             {
                 Utils.SetPrivateField <string>(m_Locale, "m_EnglishName", m_EnglishName);
             }
             if (m_NativeName.Length != 0)
             {
                 Utils.SetPrivateField <string>(m_Locale, "m_NativeName", m_NativeName);
             }
             Utils.SetPrivateField <Dictionary <Locale.Key, string> >(m_Locale, "m_LocalizedStrings", l_LocalizedStrings);
             Utils.ExportFile(olocale_path.Text, m_Locale);
             if (import_msg.InvokeRequired)
             {
                 SetTextCallback d = new SetTextCallback(SetText);
                 this.Invoke(d, new object[] { "import success !" });
             }
             if (progress.InvokeRequired)
             {
                 SetVisible d = new SetVisible(SetVisible);
                 this.Invoke(d, new object[] { false });
             }
         }
     }
     else
     {
         if (import_msg.InvokeRequired)
         {
             SetTextCallback d = new SetTextCallback(SetText);
             this.Invoke(d, new object[] { "file or directory not exist !" });
         }
     }
 }