أخر الاخبار

Subject Information security homework solutions

 




شكر خاص(حل هذه الاسئلة) : محمد فؤاد عبداللة 
Q-

sol//

using System;
 using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
namespace information_security_1
 {
 public partial class Form1 : Form 
 {
 public Form1() 
 {
 InitializeComponent(); 
 button2.Enabled = false; 
 }
 //enemyattackstonightz 
 int[] key = new int[5] { 2, 0, 3, 4, 1 };
 int z = 0;
 public string Encryt(string plaintext) 
 {
 char[,] temp1= new char[4, 5];
 char[,] temp2 = new char[4, 5]; 
 char[] output = new char[20]; 
 for (int i = 0; i < 4; i++) 
 { 
 for (int j = 0; j < 5; j++) 
 { 
 temp1[i, j] = plaintext[z++]; 
 } 
 }
 for (int i = 0; i < 4; i++) 
 {
 for (int j = 0; j < 5; j++) 
 { 
 temp2[i, j] = temp1[i, key[j]]; 
 } 
 }
 z = 0;
 for (int j = 0; j < 5; j++) 
 {
 for (int i = 0; i < 4; i++)
 { output[z++] = temp2[i, j]; 
 }
 }
 return new string(output).ToUpper();
 }
 public string decryption(string ciphertext) 
 { 
 char[,] temp1 = new char[4, 5];
 char[,] temp2 = new char[4, 5];
 char[] output = new char[20]; 
 z = 0; 
 for (int j = 0; j < 5; j++) 
 { for (int i = 0; i < 4; i++) 
 { 
 temp1[i, j] = ciphertext[z++];
 } 
 } 
 for (int i = 0; i < 4; i++)
 { 
 for (int j = 0; j < 5; j++)
 { 
 temp2[i, key[j]] = temp1[i, j]; 
 }
 }
 z = 0;
 for (int i = 0; i < 4; i++) 
 { 
 for (int j = 0; j < 5; j++)
 {
 output[z++] = temp2[i, j]; 
 }
 } 
 return new string(output).ToLower(); 
 }
 private void button1_Click(object sender, EventArgs e) 
 { 
 if (textBox1.Text.Length == 20) 
 {
 label1.Text = Encryt(textBox1.Text); 
 button2.Enabled = true; button1.Enabled = false;
 }
 else
 {
  MessageBox.Show("Enter a string length 20 characters = " + textBox1.Text.Length, "error input !"); textBox1.Clear();
 } 
 }
 private void button2_Click(object sender, EventArgs e) 
 {
 label2.Text = decryption(label1.Text);
 button1.Enabled = true; button2.Enabled = false;
 }
 private void button3_Click(object sender, EventArgs e)
 {
 textBox1.Clear(); label1.Text = "";
 label2.Text = ""; 
 }
 } 
}

Output










Q-



sol//




using System;
 using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 namespace information_security_h.k2 
 public partial class Form1 : Form
 {
 public Form1() 
 { 
 InitializeComponent(); 
 }
 int key,num; 
 public string Cryptography (string input, int key) 
 { 
 string output = string.Empty; 
 for (int i = 0; i < input.Length; i++) 
 { 
 if (char.IsLetter(input[i])) output += (char)((((input[i] - 97) + key) % 26) + 97); 
 else 
 output += input[i]; 
 }
 return output; 
 }
 private void button1_Click(object sender, EventArgs e)
 {
 if (textBox3.Text != string.Empty && textBox2.Text != string.Empty && textBox1.Text != string.Empty) 
 { 
 string cipher;
 key = int.Parse(textBox1.Text); 
 num = int.Parse(textBox3.Text);
 if (key > 26 || key < 1) 
 { 
 MessageBox.Show("pleaes enter the key between 1 to 26 ", "input erorr key");
 textBox1.Clear(); 
 }
 else 
 {
 cipher = Cryptography(textBox2.Text.ToLower(), key);
 for (int i = 1; i < num; i++) cipher = Cryptography(cipher, key);
 label4.Text = cipher; 
 }
 }
 else 
 MessageBox.Show("check you input value", "erorr");
  }
 private void button2_Click(object sender, EventArgs e) 
 { 
 textBox1.Clear();
 textBox2.Clear();
 textBox3.Clear(); 
 label4.Text = ""; 
 } 
 } 
}

Output



Q-











sol//

using System;
 using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
namespace WindowsFormsApplication1
 {
 public partial class Form1 : Form
 {
 public Form1() 
 { 
 InitializeComponent();
 } 
 string keyword;
 int key;
 public string Cryptography(string input, string key) 
 { 
 string output = ""; 
 for (int i = 0; i < input.Length; i++)
 {
 if (char.IsLetter(input[i])) 
 {
 int k = key[i % key.Length] - 97; output += (char)((((input[i] - 97) + k) % 26) + 97); 
 }
 else
 output += input[i]; 
 }
 return output;
 }
 public string mul(string input, int key) 
 { 
 string output = "";
 for (int i = 0; i < input.Length; i++)
 { 
 if (char.IsLetter(input[i])) output += (char)((((input[i] - 97) * key) % 26) + 97); else output += input[i]; }
 return output;
 } 
 public static int MultiplicativeInverse(int key)
 { 
 int x = 1;
 while (((key * x) % 26 != 1)) 
 {
 x++; 
 } 
 return x;
 }
 private void button1_Click(object sender, EventArgs e)
 { 
 if (textBox1.Text != "" && textBox2.Text != "" && textBox4.Text != "")
 {
 keyword = textBox4.Text;
 key = int.Parse(textBox2.Text);
 int invkey = MultiplicativeInverse(key);
 string Deckey = string.Empty; 
 for (int i = 0; i < keyword.Length; i++) 
 {
 Deckey += (char)((26 - (keyword[i] - 97)) + 97);
 }
 textBox3.Text = mul(Cryptography(textBox1.Text, Deckey), invkey);
 }
 else 
 MessageBox.Show("Enter text");
 }
 }
 }


Output






Q-




sol//

using System;
 using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
namespace informatin.S_h.w4
 {
 public partial class Form1 : Form 
 {
 public Form1() 
 {
 InitializeComponent();
 }
 int[] Skey;
 int[] PKey = new int[6] { 5,0,2,4,1,3 };
 public void KeyGenerator(int len) 
 {
 Skey = new int[len];
 // Key Generator = last 6 number 010101
 int[] Lfsr = new int[10] { 1, 0, 1, 0, 1, 0, 1, 0, 1 , 0 };
 int tap1, tap2, Newbit;
 for (int a = 0; a < len; a++) 
 {
 tap1 = Lfsr[1];
 tap2 = Lfsr[2];
 Newbit = tap1 ^ tap2; Skey[a] = Lfsr[Lfsr.Length - 1];
 for (int i = Lfsr.Length - 1; i > 0; i--)
 {
 Lfsr[i] = Lfsr[i - 1];
 }
 Lfsr[0] = Newbit;
 }
 }
 public string Encryption(string plain)
 {
 int len = plain.Length; 
 char[] temp = new char[len];
 for (int i = 0; i < len; i++)
 {
  temp[PKey[i]] = plain[i];
 }
 return new string(temp) ; 
 }
 private void button1_Click(object sender, EventArgs e)
 {
 int len = int.Parse(textBox1.Text);
 if (PKey.Length != len)
 {
 MessageBox.Show("length is not equal "+len, "erorr length"); textBox1.Clear();
 }
 else
 { 
 KeyGenerator(len);
 string input = string.Empty;
 for (int i = 0; i < len; i++) 
 {
 input += Skey[i]; 
 }
 textBox2.Text = Encryption(input); 
 textBox3.Text = input;
 } 
 } 
 } 
}

Output




شكر خاص(حل هذه الاسئلة) : محمد فؤاد عبداللة 
تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-