DevioLab CRYPTO TRADING AUTOMATION
LIVE
AUTOMATED CRYPTO TRADING • BINANCE
Автоматизуйте свій криптопортфель
Торгові боти DevioLab аналізують крипторинок, автоматично відкривають і закривають позиції та керують вашим портфелем на Binance 24/7.
CRYPTO 80 Bots
BINANCE Spot Trading
TRADING 24 / 7
Спробувати DevioLab
deviolab.com

Практична робота № 5

Інформація про навчальний заклад

ВУЗ:
Національний університет Львівська політехніка
Інститут:
Не вказано
Факультет:
Не вказано
Кафедра:
Не вказано

Інформація про роботу

Рік:
2013
Тип роботи:
Практична робота
Предмет:
Криптологія

Частина тексту файла (без зображень, графіків і формул):

МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ «ЛЬВІВСЬКА ПОЛІТЕХНІКА» Кафедра БІТ  Практична робота № 5 з навчальної дисципліни: “Прикладна криптологія” Львів – 2011 Завдання Написати програму мовою Сі, яка моделює роботу псевдовипадкових генераторів Фібоначчі на основі примітивних многочленів, заданих в таблиці. Провести дослідження величини періоду псевдовипадкової послідовності від типу примітивного многочлена. Написати програму мовою Сі, яка зашифровує-розшифровує текстовий файл (2 сторінки word- документу) за допомогою псевдовипадкової послідовності, сформованої генератором із найбільшим періодом. Таблиця № з/п F,(x) F2(x) F3(x) F4(x) F5(x) F6(x) F7(x) Fs(x)  2 (19,5,2,1,0) (151,9, 0) (31, 13,0) (49, 6, 5, 4, 0) (65, 18, 0) (157, 6,5,2, 0) (225,109, 0) (34, 7, 6, 5, 2, 1,0)   Блок-схема програми 1 Блок-схема програми 2 Текст програми 1 using System; using System.Collections; using System.IO; using System.Text; namespace lab5 { class Program { static void Main() { System.Text.Encoding a = Encoding.GetEncoding(1251); FileStream input = new FileStream("1.txt", FileMode.Open); StreamReader sr = new StreamReader(input); string s = ""; string vt = ""; while ((s = sr.ReadLine()) != null) { s += sr.ReadLine(); if (s != null) vt += s; } bool[] arre = new bool[vt.Length * 8]; byte[] encodedBytes = a.GetBytes(vt); int p = 0; for (int m = 0; m < encodedBytes.Length; m++) { BitArray ba = new BitArray(new byte[] { encodedBytes[m] }); ba.CopyTo(arre, p); p += 8; } int[] LFSR = new int[] { 19, 5, 2, 1, 0 }; bool[] poslid = new bool[1000000]; poslid = great(LFSR); //шифрування bool[] shufrtext = new bool[arre.Length]; int c = 0; for (int b = 0; b < shufrtext.Length; b++) { shufrtext[b] = XOR(arre[b], poslid[c]); c++; if (c == poslid.Length) c = 0; } //переведення в букви і вивід на екран int lich = 0, inten, lin = 0; bool[] vShufr = new bool[8]; byte[] Shufr = new byte[shufrtext.Length / 8]; for (int zx = 0; zx < shufrtext.Length; zx++) { vShufr[lich] = shufrtext[zx]; lich++; if (lich == 8) { Array.Reverse(vShufr); inten = To10(vShufr); Shufr[lin] = Convert.ToByte(inten); lich = 0; lin++; } } string shufrotext = a.GetString(Shufr); Console.WriteLine("Зашифроване повiдомлення: {0}", shufrotext); // РОЗШИФРОВУВАННЯ bool[] rozshufr = new bool[shufrtext.Length]; c = 0; for (int h = 0; h < shufrtext.Length; h++) { rozshufr[h] = XOR(shufrtext[h], poslid[c]); c++; if (c == poslid.Length) c = 0; } //переведення в букви і вивід на екран int lich1 = 0, inten1, lin1 = 0; bool[] vRozhufr = new bool[8]; byte[] Rozshufr = new byte[shufrtext.Length / 8]; for (int zx = 0; zx < shufrtext.Length; zx++) { vRozhufr[lich1] = rozshufr[zx]; lich1++; if (lich1 == 8) { Array.Reverse(vRozhufr); inten1 = To10(vRozhufr); Rozshufr[lin1] = Convert.ToByte(inten1); lich1 = 0; lin1++; } } string rozhufrovText = a.GetString(Rozshufr); Console.WriteLine("Розшифроване повiдомлення: {0}", rozhufrovText); FileStream output = new FileStream("2.txt", FileMode.Open); StreamWriter sw = new StreamWriter(output); sw.Write(rozhufrovText); Console.ReadKey(); } public static bool[] great(int[] registr) { bool[] LFSR = new bool[registr[0] + 1]; //початковий стан LFSR[1] = true; double rozm = Math.Pow(2, registr[0] + 1); bool[] rez = new bool[1000000]; for (int i = 0; i < rez.Length; i++) { LFSR = slide_for_LSFR_5(LFSR, registr); rez[i] = LFSR[0]; } return LFSR; } public static bool[] slide_for_LSFR_5(bool[] LSFR, int[] register) { bool temp; temp = XOR(LSFR[register.Length - 1], LSFR[register[register.Length - 2]]); temp = XOR(temp, LSFR[register[register.Length - 3]]); temp = XOR(temp, LSFR[register[register.Length - 4]]); temp = XOR(temp, LSFR[register[0]]); for (int u = 0; u < LSFR.Length - 1; u++) { LSFR[u] = LSFR[u + 1]; } LSFR[LSFR.Length - 1] = temp; return LSFR; } public static bool XOR(bool x, bool y) { if (x == y) return false; else return true; } public static int To10(bool[] bin) { int stepin = 1; int sum = 0; int hint = 0; for (int v = bin.Length - 1; v >= 0; v--) { if (bin[v]) { hint = 1; sum += hint * stepin; } stepin *= 2; } return sum; } } } Текст програми 2 using System; using System.Collections; using System.Linq; using System.Text; using System.IO; namespace LFSR_5 { class Program { static void Main() { int[] LFSR1 = new int[] { 19, 5, 2, 1, 0 }; int[] LFSR2 = new int[] { 34, 7, 6, 5, 2, 1, 0 }; int[] LFSR3 = new int[] { 31, 13, 0 }; int[] LFSR4 = new int[] { 49, 6, 5, 4, 0 }; int[] LFSR5 = new int[] { 65, 18, 0 }; int[] LFSR6 = new int[] { 157, 6, 5, 2, 0 }; int[] LFSR7 = new int[] { 225, 109, 0 }; int[] LFSR8 = new int[] { 151, 9, 0 }; double one = great(LFSR1); Console.WriteLine(one); FileStream output1 = new FileStream("1.txt", FileMode.OpenOrCreate); FileStream output2 = new FileStream("2.txt", FileMode.OpenOrCreate); FileStream output3 = new FileStream("3.txt", FileMode.OpenOrCreate); FileStream output4 = new FileStream("4.txt", FileMode.OpenOrCreate); FileStream output5 = new FileStream("5.txt", FileMode.OpenOrCreate); FileStream output6 = new FileStream("6.txt", FileMode.OpenOrCreate); FileStream output7 = new FileStream("7.txt", FileMode.OpenOrCreate); FileStream output8 = new FileStream("8.txt", FileMode.OpenOrCreate); StreamWriter sw1 = new StreamWriter(output1); sw1.WriteLine(one); sw1.Close(); double two = great(LFSR2); Console.WriteLine(two); StreamWriter sw2 = new StreamWriter(output2); sw2.WriteLine(two); sw2.Close(); double three = great(LFSR3); Console.WriteLine(three); StreamWriter sw3 = new StreamWriter(output3); sw3.WriteLine(three); sw3.Close(); double four = great(LFSR4); Console.WriteLine(four); StreamWriter sw4 = new StreamWriter(output4); sw4.WriteLine(four); sw4.Close(); double five = great(LFSR5); Console.WriteLine(five); StreamWriter sw5 = new StreamWriter(output5); sw5.WriteLine(five); sw5.Close(); double six = great(LFSR6); Console.WriteLine(six); StreamWriter sw6 = new StreamWriter(output6); sw6.WriteLine(six); sw6.Close(); double seven = great(LFSR7); Console.WriteLine(seven); StreamWriter sw7 = new StreamWriter(output7); sw7.WriteLine(seven); sw7.Close(); double eight = great(LFSR8); Console.WriteLine(eight); StreamWriter sw8 = new StreamWriter(output8); sw8.WriteLine(eight); sw8.Close(); Console.Read(); } public static double great(int[] registr) { bool[] LFSR = new bool[registr[0] + 1]; //початковий стан LFSR[1] = true; bool[] test = new bool[registr[0] + 1]; Array.Copy(LFSR, test, registr[0] + 1); double rozm = Math.Pow(2, registr[0] + 1); //bool[] rez = new bool[2147483648]; for (double i = 0; i < rozm + 1; i++) { if (registr.Length == 3) LFSR = slide_for_LSFR_3(LFSR, registr); if (registr.Length == 5) LFSR = slide_for_LSFR_5(LFSR, registr); if (registr.Length == 7) LFSR = slide_for_LSFR_7(LFSR, registr); //rez[i] = LFSR[0]; if (perev(test, LFSR)) { return i + 1; } } return 0; } public static bool[] slide_for_LSFR_5(bool[] LSFR, int[] register) { bool temp; temp = XOR(LSFR[register.Length - 1], LSFR[register[register.Length - 2]]); temp = XOR(temp, LSFR[register[register.Length - 3]]); temp = XOR(temp, LSFR[register[register.Length - 4]]); temp = XOR(temp, LSFR[register[0]]); for (int u = 0; u < LSFR.Length - 1; u++) { LSFR[u] = LSFR[u + 1]; } LSFR[LSFR.Length - 1] = temp; return LSFR; } public static bool[] slide_for_LSFR_3(bool[] LSFR, int[] register) { bool temp; temp = XOR(LSFR[register.Length - 1], LSFR[register[register.Length - 2]]); temp = XOR(temp, LSFR[register[0]]); for (int u = 0; u < LSFR.Length - 1; u++) { LSFR[u] = LSFR[u + 1]; } LSFR[LSFR.Length - 1] = temp; return LSFR; } public static bool[] slide_for_LSFR_7(bool[] LSFR, int[] register) { bool temp; temp = XOR(LSFR[register.Length - 1], LSFR[register[register.Length - 2]]); temp = XOR(temp, LSFR[register[register.Length - 3]]); temp = XOR(temp, LSFR[register[register.Length - 4]]); temp = XOR(temp, LSFR[register[register.Length - 5]]); temp = XOR(temp, LSFR[register[register.Length - 6]]); temp = XOR(temp, LSFR[register[0]]); for (int u = 0; u < LSFR.Length - 1; u++) { LSFR[u] = LSFR[u + 1]; } LSFR[LSFR.Length - 1] = temp; return LSFR; } public static bool perev(bool[] a, bool[] b) { for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) return false; } return true; } public static bool XOR(bool x, bool y) { if (x == y) return false; else return true; } } } Результат виконання програми 1  Результат виконання програми 2  Висновок В даній лабораторній роботі я написав програму, яка зашифровує - розшифровує текстовий файл за допомогою псевдовипадкової послідовності, сформованої генератором із найбільшим періодом.
Антиботан аватар за замовчуванням

22.05.2013 20:58

Коментарі

Ви не можете залишити коментар. Для цього, будь ласка, увійдіть або зареєструйтесь.

Ділись своїми роботами та отримуй миттєві бонуси!

Нічого не вибрано
0%

Оголошення від адміністратора

Антиботан аватар за замовчуванням

Подякувати Студентському архіву довільною сумою

Admin

26.02.2023 12:38

Дякуємо, що користуєтесь нашим архівом!