Total members 11778 |It is currently Wed Jun 19, 2019 5:15 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This is a polyalphabetic Security Algorithm(polyalphabetic cipher decryption and encryption) i made using J# (close to C#) :gOOd: .Download the Code and enjoy .You must have the virtual machine installed on your PC to run this code.
csharp code
package ployalphapetic;

import System.Collections.Generic.*;
import System.Data.*;
import System.Drawing.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Collections.ArrayList;

/**
* Summary description for Form1.
*/
public class Form1 extends System.Windows.Forms.Form
{
private TextBox textBox1;
private TextBox textBox2;
private Label label1;
private Label label2;
private Label label3;
private TextBox textBox3;
private Button button1;
private Button button2;
// ArrayList letter = new ArrayList();
char[] letter = new char[26];
final static int addnumber = 97;
String pureplaintxt="";
String ciphertxt = "";
private Timer timer1;
/**
* Required designer variable.
*/
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

#region Windows Form Designer generated code
/**
* Clean up any resources being used.
*/
protected void Dispose(boolean disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
super.Dispose(disposing);
}

/**
* Required method for Designer support - do not modify
* the contents of this method with the code editor.
*/
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// textBox1
//
this.textBox1.set_Location(new System.Drawing.Point(73, 25));
this.textBox1.set_Name("textBox1");
this.textBox1.set_Size(new System.Drawing.Size(207, 20));
this.textBox1.set_TabIndex(0);
//
// textBox2
//
this.textBox2.set_Location(new System.Drawing.Point(73, 64));
this.textBox2.set_Multiline(true);
this.textBox2.set_Name("textBox2");
this.textBox2.set_Size(new System.Drawing.Size(207, 77));
this.textBox2.set_TabIndex(1);
//
// label1
//
this.label1.set_AutoSize(true);
this.label1.set_Location(new System.Drawing.Point(12, 28));
this.label1.set_Name("label1");
this.label1.set_Size(new System.Drawing.Size(41, 13));
this.label1.set_TabIndex(2);
this.label1.set_Text("Key : ");
//
// label2
//
this.label2.set_AutoSize(true);
this.label2.set_Location(new System.Drawing.Point(12, 68));
this.label2.set_Name("label2");
this.label2.set_Size(new System.Drawing.Size(59, 13));
this.label2.set_TabIndex(3);
this.label2.set_Text("Plain text :");
//
// label3
//
this.label3.set_AutoSize(true);
this.label3.set_Location(new System.Drawing.Point(12, 158));
this.label3.set_Name("label3");
this.label3.set_Size(new System.Drawing.Size(108, 13));
this.label3.set_TabIndex(4);
this.label3.set_Text("Encrypted message :");
//
// textBox3
//
this.textBox3.set_Location(new System.Drawing.Point(73, 182));
this.textBox3.set_Multiline(true);
this.textBox3.set_Name("textBox3");
this.textBox3.set_Size(new System.Drawing.Size(207, 112));
this.textBox3.set_TabIndex(5);
//
// button1
//
this.button1.set_Location(new System.Drawing.Point(205, 312));
this.button1.set_Name("button1");
this.button1.set_Size(new System.Drawing.Size(75, 23));
this.button1.set_TabIndex(6);
this.button1.set_Text("Encrypte");
this.button1.set_UseVisualStyleBackColor(true);
this.button1.add_Click(new System.EventHandler(this.button1_Click));
//
// button2
//
this.button2.set_Location(new System.Drawing.Point(91, 312));
this.button2.set_Name("button2");
this.button2.set_Size(new System.Drawing.Size(75, 23));
this.button2.set_TabIndex(7);
this.button2.set_Text("Decrypte");
this.button2.set_UseVisualStyleBackColor(true);
this.button2.add_Click(new System.EventHandler(this.button2_Click));
//
// timer1
//
this.timer1.set_Enabled(true);
this.timer1.add_Tick(new System.EventHandler(this.timer1_Tick));
//
// Form1
//
this.set_AutoScaleDimensions(new System.Drawing.SizeF(6F, 13F));
this.set_AutoScaleMode(System.Windows.Forms.AutoScaleMode.Font);
this.set_ClientSize(new System.Drawing.Size(292, 383));
this.get_Controls().Add(this.button2);
this.get_Controls().Add(this.button1);
this.get_Controls().Add(this.textBox3);
this.get_Controls().Add(this.label3);
this.get_Controls().Add(this.label2);
this.get_Controls().Add(this.label1);
this.get_Controls().Add(this.textBox2);
this.get_Controls().Add(this.textBox1);
this.set_ForeColor(System.Drawing.Color.get_Blue());
this.set_FormBorderStyle(System.Windows.Forms.FormBorderStyle.FixedSingle);
this.set_MaximizeBox(false);
this.set_Name("Form1");
this.set_StartPosition(System.Windows.Forms.FormStartPosition.CenterScreen);
this.set_Text("Polyalphabetic");
this.add_FormClosing(new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing));
this.add_Load(new System.EventHandler(this.Form1_Load));
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

private void Form1_Load(Object sender, System.EventArgs e)
{
for (int i = 0; i < 26; i++)
{
letter[i] = (char)(i + addnumber);
}
}

private void button1_Click(Object sender, System.EventArgs e)
{
// textBox1 which have the key
// textBox2 which have plain text
// textBox3 which have encrypted message
textBox3.set_Enabled(true);
textBox2.set_Enabled(false);
textBox1.set_Enabled(false);
textBox3.set_Text("");
String key = textBox1.get_Text();
for (int i = 0; i < textBox2.get_Text().length(); i++)
{
if (!(textBox2.get_Text().substring(i,i+1).Equals(" ")))
{
pureplaintxt += textBox2.get_Text().substring(i, i+1);
}
}
while (textBox1.get_Text().length() < pureplaintxt.length())
{
textBox1.set_Text(textBox1.get_Text() + key);
}
textBox1.set_Text(textBox1.get_Text().substring(0,pureplaintxt.length()));
key = textBox1.get_Text();
encrypte();
key = "";
pureplaintxt = "";
}
public void encrypte()
{
String keyletter;
String plaintxtletter;
int keyindex = 0 ;
int plaintxtindex=0;
int cipherindex=0;

//////// To get letter by letter from key and pure plain text ///////

for (int i = 0; i < pureplaintxt.length(); i++)
{
keyletter = textBox1.get_Text().substring(i, i + 1);
plaintxtletter = pureplaintxt.substring(i, i + 1);

/// To search inside the array letter with key letter and plain text letter ///

for (int j = 0; j < letter.length; j++)
{
if (keyletter.toCharArray()[0]==letter[j])
{
keyindex = j;
}
if (plaintxtletter.toCharArray()[0] == letter[j])
{
plaintxtindex = j;
}
}
cipherindex = (keyindex + plaintxtindex) % 26;
textBox3.set_Text(textBox3.get_Text()+letter[cipherindex]);
}
}

private void button2_Click(Object sender, System.EventArgs e)
{
textBox2.set_Enabled(true);
textBox3.set_Enabled(false);
textBox1.set_Enabled(false);
textBox2.set_Text("");
String key = textBox1.get_Text();
for (int i = 0; i < textBox3.get_Text().length(); i++)
{
if (!(textBox3.get_Text().substring(i, i + 1).Equals(" ")))
{
ciphertxt += textBox3.get_Text().substring(i, i + 1);
}
}
while (textBox1.get_Text().length() < ciphertxt.length())
{
textBox1.set_Text(textBox1.get_Text() + key);
}
textBox1.set_Text(textBox1.get_Text().substring(0, ciphertxt.length()));
key = textBox1.get_Text();
decrypte();
key = "";
ciphertxt = "";
}
public void decrypte()
{
String keyletter;
String cipherletter;
int keyindex = 0;
int cipherindex = 0;
int plaintxtindex = 0;
int check = 0;
//////// To get letter by letter from key and pure plain text ///////

for (int i = 0; i < ciphertxt.length(); i++)
{
keyletter = textBox1.get_Text().substring(i, i + 1);
cipherletter = ciphertxt.substring(i, i + 1);

/// To search inside the array letter with key letter and plain text letter ///

for (int j = 0; j < letter.length; j++)
{
if (keyletter.toCharArray()[0] == letter[j])
{
keyindex = j;
}
if (cipherletter.toCharArray()[0] == letter[j])
{
cipherindex = j;
}
}
check = cipherindex - keyindex;
if (check < 0)
{
check = 26 - (keyindex - cipherindex);
plaintxtindex = check % 26;
textBox2.set_Text(textBox2.get_Text() + letter[plaintxtindex]);
}
else
{
plaintxtindex = check % 26;
textBox2.set_Text(textBox2.get_Text() + letter[plaintxtindex]);
}
}
}

private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
DialogResult exit;
exit = MessageBox.Show("Are u sure ? ", "Exit",MessageBoxButtons.YesNo);
if (exit == DialogResult.Yes)
{
MessageBox.Show("Thanks for using my program ", "Goooooooooooood bye");
Application.ExitThread();
}
else
{
e.set_Cancel(true);
}
}

private void timer1_Tick(Object sender, System.EventArgs e)
{
}
}





Attachments:
ployalphabetic J#.rar [27.97 KiB]
Downloaded 858 times

_________________
Please recommend my post if you found it helpful
Author:
Newbie
User avatar Posts: 9
Have thanks: 0 time

thx useful :)


Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time

updated.


Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 3 posts ] 

  Related Posts  to : polyalphabetic J# Code
 polyalphabetic cipher java code     -  
 Polyalphabetic cipher technique     -  
 i want code for connecting mobile and pc can u send me code     -  
 Freeman chain code algorithm code     -  
 asking for code     -  
 code     -  
 error in code     -  
 NotePad C# code     -  
 What will be validation for Zip code ?     -  
 Get IP address code     -  



Topic Tags

C# Algorithms






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com