You are on page 1of 3

Security

TextBox :‫اسم االداة‬


Lab6: Normal_txt :‫االسم البرمجي‬
Mixed Alphabet Substitution Cipher (Encryption) ReadOnly True

Button :‫اسم االداة‬


Random_btn :‫االسم البرمجي‬

TextBox :‫اسم االداة‬


Random_txt :‫االسم البرمجي‬

RichTextBox :‫اسم االداة‬


Plain1_rch :‫االسم البرمجي‬

Button :‫اسم االداة‬


Enc_btn:‫االسم البرمجي‬

RichTextBox :‫اسم االداة‬


Cipher1_rch :‫االسم البرمجي‬

Mixed Alphabet Substitution Cipher (Decryption)

RichTextBox :‫اسم االداة‬


Cipher2_rch :‫االسم البرمجي‬

Button:‫اسم االداة‬
Dec_btn:‫االسم البرمجي‬

RichTextBox :‫اسم االداة‬


Plain2_rch :‫االسم البرمجي‬

1
Asst. Prof. Melad Jader Asst. Lect. Manar Talaat
Security

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mixed_Aphabet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Random_btn_Click(object sender, EventArgs e)


{
// Random ‫تكٌٌن كائن من انكالس‬
Random rn = new Random();
// ‫جدٌد‬string ً‫ًضع انيجائٍة غٍز انعشٌائٍة ف‬
string st = Normal_txt.Text;

// ً‫انحصٌل عهى ىجائٍة مزتبة تزتٍب عشٌائ‬


while (st != "")
{
//‫انحصٌل عهى مٌقع انحزف انذي سٍتم اختٍاره بشكم عشٌائً نٌٍضع فً انيجائٍة انعشٌائٍة انمتكٌنة‬
int k = rn.Next(st.Length - 1);
//‫تكٌٌن انيجائٍة انعشٌائٍة‬
Random_txt.Text += st[k];
//‫مسح انحزف من انيجائٍة االصهٍة نتالفً تكزار اختٍاره فً انيجائٍة انعشٌائٍة انمتكٌنة‬
st = st.Remove(k, 1);
}
}

private void Enc_btn_Click(object sender, EventArgs e)


{
//‫انتشفٍز ٌتم باخذ حزف حزف من اننص انصزٌح ً انبحث عنو فً انيجائٍة االصهٍة انمزتٍة ً اخذ انحزف انذي ٌقابهو فً انيجائٍة انعشٌائٍة انمتكٌنة‬
for (int i = 0; i < Plain1_rch.Text.Length; i++)
{
int index = Normal_txt.Text.IndexOf(Plain1_rch.Text[i]);
Cipher1_rch.Text += Random_txt.Text[index];
}
}
private void Dec_btn_Click(object sender, EventArgs e)
{
// ‫فك انتشفٍز ٌتم باخذ حزف حزف من اننص انمشفز ً انبحث عنو فً انيجائٍة انعشٌائٍة ًاخذ انحزف انذي ٌقابهو فً انيجائٍة االصهٍة انمزتبة‬
for (int i = 0; i < Cipher2_rch.Text.Length; i++)
{
int index = Random_txt.Text.IndexOf(Cipher2_rch.Text[i]);
Plain2_rch.Text += Normal_txt .Text[index];
}
}
}
}

2
Asst. Prof. Melad Jader Asst. Lect. Manar Talaat
‫‪Security‬‬

‫‪Example:‬‬
‫‪PlainText: send help soon‬‬
‫فكرة ال ‪ Mixed Alphabet‬هي االتفاق عهى هجائيت تشفير و فك انشفرة ما بيه انمرسم و‬ ‫‪‬‬
‫انمستقبم و يتم انحصىل عهى هذه انهجائبت مه ترتيب انحروف االبجديت بشكم عشىائي ‪...‬‬
‫فهى وفترض ان انهجائيت انمتفك عهيها ما بيه انمرسم و انمستقبم كتاني‪...‬‬ ‫‪‬‬
‫‪h x q a w m g i r y b e o t u n d p c y l k s i f z‬‬

‫‪ ‬ستكون طريقة التشفير كالتالي‪..‬‬


‫‪a‬‬ ‫‪b‬‬ ‫‪c‬‬ ‫‪d e‬‬ ‫‪f‬‬ ‫‪g‬‬ ‫‪h‬‬ ‫‪i‬‬ ‫‪j‬‬ ‫‪k‬‬ ‫‪l m‬‬ ‫‪n‬‬ ‫‪o‬‬ ‫‪p‬‬ ‫‪q‬‬ ‫‪r‬‬ ‫‪s‬‬ ‫‪t‬‬ ‫‪u v w x y z‬‬
‫‪h‬‬ ‫‪x‬‬ ‫‪q‬‬ ‫‪a w m‬‬ ‫‪g‬‬ ‫‪j‬‬ ‫‪r‬‬ ‫‪y‬‬ ‫‪b‬‬ ‫‪e o‬‬ ‫‪t‬‬ ‫‪u‬‬ ‫‪n‬‬ ‫‪d‬‬ ‫‪p‬‬ ‫‪c‬‬ ‫‪y‬‬ ‫‪l k s i f z‬‬

‫حيث ان االحرف المظلله اعاله هي التي من خاللها سنشفر االحرف للنص المعطى‪.‬‬ ‫‪‬‬
‫‪Cipher Text: cwtajwencuut‬‬
‫‪ ‬و ستكون طريقة فك التشفير كالتالي‪..‬‬

‫‪h‬‬ ‫‪x‬‬ ‫‪q‬‬ ‫‪a w m‬‬ ‫‪g‬‬ ‫‪j‬‬ ‫‪r‬‬ ‫‪y‬‬ ‫‪b‬‬ ‫‪e o‬‬ ‫‪t‬‬ ‫‪u‬‬ ‫‪n‬‬ ‫‪d‬‬ ‫‪p‬‬ ‫‪c‬‬ ‫‪y‬‬ ‫‪l‬‬ ‫‪k s‬‬ ‫‪i‬‬ ‫‪f‬‬ ‫‪z‬‬
‫‪a‬‬ ‫‪b‬‬ ‫‪c‬‬ ‫‪d e‬‬ ‫‪f‬‬ ‫‪g‬‬ ‫‪h‬‬ ‫‪i‬‬ ‫‪j‬‬ ‫‪k‬‬ ‫‪l m‬‬ ‫‪n‬‬ ‫‪o‬‬ ‫‪p‬‬ ‫‪q‬‬ ‫‪r‬‬ ‫‪s‬‬ ‫‪t‬‬ ‫‪u‬‬ ‫‪v w‬‬ ‫‪x‬‬ ‫‪y‬‬ ‫‪z‬‬

‫حيث ان االحرف المظلله اعاله هي التي من خاللها سنفك شفرة االحرف للنص المشفر و الحصول على النص الصريح‪.‬‬ ‫‪‬‬
‫‪Plain Text: send help soon‬‬

‫‪3‬‬
‫‪Asst. Prof. Melad Jader‬‬ ‫‪Asst. Lect. Manar Talaat‬‬

You might also like