private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length > 0) { string s = ""; string key = textBox1.Text; StreamReader sr = new StreamReader("in.txt"); while (!sr.EndOfStream) { s += sr.ReadLine(); } sr.Close(); s = StringToRightLength(s); CutStringIntoBlocks(s); key = CorrectKeyWord(key, s.Length / (2 * Blocks.Length)); textBox1.Text = key; key = StringToBinaryFormat(key); for (int j = 0; j < quantityOfRounds; j++) { for (int i = 0; i < Blocks.Length; i++) { Blocks[i] = EncodeDES_One_Round(Blocks[i], key); } key = KeyToNextRound(key); } key = KeyToPrevRound(key); textBox2.Text = StringFromBinaryToNormalFormat(key); string result = ""; for (int i = 0; i < Blocks.Length; i++) { result += Blocks[i]; } StreamWriter sw = new StreamWriter("out1.txt"); sw.WriteLine(Utf8Encoder.GetString(Utf8Encoder.GetBytes(StringFromBinaryToNormalFormat(result)))); //переводим строку с двоичными данными в символьный формат sw.Close(); Process.Start("out1.txt"); } else { MessageBox.Show("Введите ключевое слово!"); } }
/// <summary> /// Convert JSON string to class object. USAGE: TestClass test = Output.DeserializeJSON<TestClass>(xml); /// </summary> /// <typeparam name="T">The type of the class</typeparam> /// <param name="json">The JSON string</param> /// <returns>Object</returns> public static T DeserializeJSON <T>(string json) { // First, convert to base64 //string encoded = Statics.Base64Encode(json); //string decoded = Statics.Base64Decode(encoded); string decoded = Utf8Encoder.GetString(Utf8Encoder.GetBytes(json)); T obj = Activator.CreateInstance <T>(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(decoded))) { obj = (T)serializer.ReadObject(ms); } return(obj); }