Algaritim: Savol-javoblar C# dasturlash tilida oqim nima? Javob


Ma'lumotlar oqimi yordamida shifrlangan fayldan ma'lumotlarni parolini


Download 66.18 Kb.
bet14/18
Sana05.05.2023
Hajmi66.18 Kb.
#1429940
1   ...   10   11   12   13   14   15   16   17   18
Bog'liq
Algaritim amaliy-2

52. Ma'lumotlar oqimi yordamida shifrlangan fayldan ma'lumotlarni parolini
ochadigan va o'qiydigan C# dasturini amalga oshiring.
Javob:
using System;
using System.IO;
using System.Security.Cryptography;
class Program
{
static void Main()
{
string filePath = @"C:\secret.txt";
byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };

using (Aes aesAlg = Aes.Create())


{
aesAlg.Key = key;
aesAlg.IV = iv;

ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

using (FileStream fsDecrypt = new FileStream(filePath,
FileMode.Open))
{
53. Ma'lumotlar oqimi yordamida XML faylidan ma'lumotlarni o'qiydigan va uni formatlangan ko'rinishda ko'rsatadigan C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.Xml;

namespace XMLReader


{
class Program
{
static void Main(string[] args)
{
string xmlFilePath = @"YourFilePath.xml";

XmlReader reader = XmlReader.Create(new FileStream(xmlFilePath, FileMode.Open));

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
Console.Write("<" + reader.Name + ">");
}

if (reader.NodeType == XmlNodeType.Text)


{
Console.Write(reader.Value);
}

if (reader.NodeType == XmlNodeType.EndElement)


{
Console.Write("");
}

Console.WriteLine("");


}

Console.ReadLine();


}
}
}
Eslatma: Bu kod belgilangan fayl yoʻlidagi XML faylni oʻqiydi va konsoldagi maʼlumotlarning formatlangan koʻrinishini chiqaradi.
54. Tarmoq ulanishi orqali ma'lumotlarni yuborish va qabul qilish uchun
ma'lumotlar oqimidan foydalanadigan C# dasturini yarating.
Javob:
using System;
using System.Threading.Tasks.Dataflow;

namespace DataFlowExample


{
class Program
{
static void Main(string[] args)
{
var server = new ActionBlock(message =>
{
Console.WriteLine("Server: " + message);
// Do some processing with the message
// Send back a reply message to the client
client.Post("Hello from the server!");
});

var client = new ActionBlock(message =>


{
Console.WriteLine("Client: " + message);
// Do some processing with the message
// Send back a reply message to the server
server.Post("Hello from the client!");
});

// Start the data flow by sending the first message from the client to the server


client.Post("Hello from the client!");

// Wait for the data flow to finish processing


server.Completion.Wait();
client.Completion.Wait();
}
}
}
Eslatma: Ushbu kod ActionBlock sinfidan foydalangan holda mijoz va server o'rtasida oddiy ma'lumotlar oqimini yaratadi. mijoz va server bloklari xabarlarni Post usuli yordamida oldinga va orqaga uzatadi. Completion.Wait ma'lumotlar oqimini qayta ishlash tugashini kutish uchun ishlatiladi.

Download 66.18 Kb.

Do'stlaringiz bilan baham:
1   ...   10   11   12   13   14   15   16   17   18




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling