a securing symmetric key distribution
DESCRIPTION
A SECURING SYMMETRIC KEY DISTRIBUTION IN NETWORKTRANSCRIPT
A SECURING SYMMETRIC KEY DISTRIBUTION
IN NETWORK
DISSERTATION SUBMITTED TO
ISLAMIAH COLLEGE (AUTONOMOUS)
IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE AWARD OF THE DEGREE OF
MASTER OF SCIENCE
IN
COMPUTER SCIENCE
BY
A.VINOTH KUMAR
REGISTER NUMBER: P11CS014
UNDER THE GUIDANCE OF
XXXXXXXXXXXXX
Assistant professor
Department of computer science
DEPARTMENT OF COMPUTER SCIENCE & APPLICATION
ISLAIMAH COLLEGE (AUTONOMOUS), VANAYAMBADI
April-2013
CERTIFICATE
This is to certify that the dissertation entitled “A SECURING SYMETRIC KEY
DISTRIBUTION IN NETWORK” submitted to Islamiah College (Autonomus), affiliated
to the Thiruvalluvar university in partial fulfillment of the requirement of the award of the
degree of Master of Computer Science is a record of original project work done by
A.VINOTHKUMAR (P11CS014). During the period 2012-2013 of their study in the
Department of computer science at Islamiah College (Autonomous), Vaniyambadi under my
supervision and guidance and the dissertation has not formed the basis for the award of
Degree or other similer titles to any candidate of any university.
Signature of the HOD Signature of the Guide
Prof. H.FAHEEM AHMED Prof.
Head&Associate Professor, Assistat professor,
Department of Computer Science Department of Computer Science
Islamiah college (Autonomous), Islamiah college (Autonomous),
Vaniyambadi. Vaniyambadi.
SUBMITTED FOR THE VIVA-VOICE EXAMINATION ON
EXTERNAL EXAMINER INTERNAL EXAMINER
ACKNOWLEDGEMENTS
First I express my deep sense of gratitude to the almighty lord who showered
blessings upon me.
My profound gratitude and sincere thanks to DR.K.PREMNAZEER, M.Sc., M.Phil.,
Ph.D., principal & Head, PG & Reasearch Department of Physics. Islamiah college
(autonomous), Vaniyambadi of providing the necessary help in securing this project work.
I extend my profound gratitude to prof. H.FAHEEM AHMED
M .Sc.D.C.E.,M.I.ST.T.,M.Tech.,M.Phil. Head of the Department of Computer Science ,
Islamiah College (Autonomous), Vaniyambadi and to all faculty members for the good
encouragement extended through out my graduation studies.
I express my heartfelt thanks to my internal guide Assistant Professor of Computer
Application, for this valuable guidance and advice throughout the project.
I am deeply indebted to my respondents for their kind and willing cooperation and
responsiveness, without which it would not have been possible for me to gather the required
information.
Finally, I owe my thanks to my family members and friends for their constant help
and moral support throughout this project work
TABLE OF CONTENTS
CHA NO TITLE PAGE NO
Abstract I
List of figures and tables II
1 Introduction 1
1.1 problem statement 2
1.2 motivation 2
2 Overview of securing symmetric key distribution 3
2.2 system requirements 5
2.2.1 hardware requirements 5
2.2.2 software requirements 6
3 Design of securing symmetric key distribution 7
3.1 Detailed design 9
4 Implementation of securing symmetric key distribution
10
5 Testing of securing symmetric key distribution 13
5.1System testing 13
5.2 unit testing 14
5.3 functional testing 15
5.4 integration testing 16
5.5 test report 16
6 Conclusion and future work 18
7 References 19
8 Appendix 20
LIST OF FIGURES
FIG NO TITLE PAGE NO
2.1 Architecture for securing symmetric key distribution 4
3.1 Selecting file and using cryptography concepts 7
3.2 Key concept to use Encrypt the information 13
3.3 Decrypt the messages and view original file 14
4.5.1 Sender side module 15
4.5.2 Receiver side module 16
LIST OF TABLES
TABLE NO TITLE PAGE NO
5.1 Unit testing 14
5.2 Functional testing 15
5.3 Test report for document storing 16
5.4 Test report for key encryption 17
5.5 Test report for decryption 17
ABSTRACT
A scheme for key distribution and network access in a network that utilizes Identity-
Based Cryptography (IBC) is presented. We quantify the energy cost of authentication and
key exchange based on public-key cryptography We present a RSA and DES Algorithm,
RSA algorithm provide two keys such as private key and public key and consider mutual
authentication and key exchange between two untrusted parties such as two system in a
network. To assess the energy demands of public-key cryptography, we quantify the energy
cost1 of optimized software implementations of public-key algorithms. Since the true benefits
and accurate analysis of any particular algorithm is closely tied to how it is used within a
security protocol, we also consider protocols that provide mutual authentication. In addition,
we consider the impact of public-key cryptography on battery life and compare public-key
cryptography to other factors influencing energy consumption, such as idle listening, data
reception and transmission, symmetric cryptography, etc. Our analysis can be generalized to
estimate the cost of public- key cryptography in other security protocols and applications
with varying characteristics. Security in Networks has lately received increased attention.
However, in almost all cases, non-public-key based key distribution and authentication
schemes have been presented, with the underlying assumption that public-key cryptography
exceeds the computational capabilities of devices suitable for Networks.
INTRODUCTION:
A Symmetric key distribution and network access in a Network that utilizes Identity-
Based Cryptography (IBC) is presented. The sensitive data should be protected using some
sort of cryptography. Symmetric key scheme is more appropriate cryptography for wireless
sensor networks due to its low energy consumption and simple hardware requirements, but
most of them cannot provide sufficient security level (e.g. integrity, confidentiality, and
authentication) as public key approach does. In this work, we propose a new security scheme
that overcomes the limitations presented in both public- and symmetric-key protocols.
The scheme relies on using one-way hash function to implement the data authenticity
between nodes in the network, and a mix of symmetric and public key cryptography
functions using the pre-distributed keys to implement the data confidentiality service.
The symmetric key function is used to guarantee secure communications between in-
network nodes while the public key function is used to guarantee a secure data delivery
between the source node and the sink node. The proposed scheme is most suitable for
wireless sensor networks that incorporate data centric routing protocols.
We have calculated the computational and communication overheads in terms
of energy consumption in the new scheme. The results have shown that the proposed scheme
is scalable and an strong competitors to pure symmetric key schemes, yet, it maintains all
security levels provided by public key schemes. a symmetric key cryptosystem is appropriate
for communication between the device, though a pre-installed system wide symmetric key or
pair-wise keys stored on the devices are not suitable for reasons of security and lack of
memory, respectively. Therefore an asymmetric or public key system is required to establish
the symmetric keys between individual devices.
1
SYSTEM REQUIREMENTS
Hardware interface:
Intel pentium 4 or other above
50 MB minimum hard disk storage space
128 bit encryption and decryption
Software interface:
Development end: Netbeans IDE 7.1,java JDK.
Tolls used: ms-Visio , Netbeans IDE 7.1.
2
EXISTING SYSTEM:
It can be easy as possible in existing process and can be possible of tampering, inserting, or dropping messages in existing system have a problem on authentication, confidentiality. which can result in low cost key establishment in wireless sensor networks. But such schemes fail in handling security or efficiency problems.
communicate on short distances
perform limited data processing
PROPOSED SYSTEM:
The purpose is including security monitoring, target tracking and research activities in hazardous environments.. Since authentication and confidentiality protocols require an agreed key between the nodes and security of the communication depends on the cryptographic schemes.
A key management is a very important security issue in networks. Earlier key management protocols were based on either symmetric or asymmetric
cryptographic functions. Hence, symmetric algorithm based key using such as schemes handling security or
efficiency. Symmetric key which is used to secure communication among two or more devices. key management messages need to be transmitted frequently.
3
NETBEANS PLATFORM
The netbeans platform is a reusable framework for simplifying the development of java
swing desktop applications. The Netbeans IDE bundle for java SE contains what is needed to
start developing NetBeans plugins and NetBeans platform based applications, no additional
SDK is required, applications can install modules dynamically. Any application can include
the update center module to allow users or the application to download digitally signed
upgrade and new feautures directly into the running application. Reinstalling an upgrade or a
new realse does not force users to download the entire application again. The platform offers
reusable servives common to desktop applications, allowing developers to focus on the logic
specific to their application. Among the feautures of the platform are:
user interface management (e.g. menus and toolbars)
User settings management
Storage management (saving and loading any kind of data)
Window management
Wizard management
Wizard framework (supports step-by-step dialogs)
NetBeans visual library
Integrated development tools
NetBeans IDE is a free, open-source, cross-platform IDE eith built-in-support for java
programming language.
4
NETBEANS IDE
NetBeans IDE is an open source integrated development environment. Netbeans IDE
supports development of all java application type javaSE(including java FX)
Modularity
All the functions of the IDE are provided by modules. Each module provides a well
defined function, such as support for the java language editing, or support for the CVS
versioning system, and SVN. netBeans contains all the modules needed for java development
in a single download, allowing the user to start working immediately. Modules also allow
NetBeans to be extended. New features, such as support for other programming languages,
can be added by installing additional modules. For instancd, sun java studio enterprise, and
from sun micro systems are all based on the NetBeans IDE.
5
CHAPTERS 3
DESIGN
3.1 DERAILED DESIGN THROUGH DEPLOYMENT DIAGRAM
The project proposes the deployment diagram to easily identify the details. The following
diagrams are suitable for our project, the deployment diagram shows the information about
secured transaction.
3.1 Deployment Level 1
Yes No
Fig 3.1 selecting file and using cryptography concepts
6
Sender Browser BrowserBrowser
Select a File
Files
Generate Key
Cryptography
3.2 Deployment Level 2
Fig 3.2 Key Concept to use Encrypt the information
7
Encrypt the data using security key
Encrypted data File
Sender
Convert Cipher Text
Security key
3.3 Deployment Level 3
Yes No
Fig 3.3 Decrypt the messages and view original file
8
Receiver
Convert plain Text
Decrypt the data using security key
Decrypted data File
Select File Security key
View the Original File
Valid Key
CHAPTER 4
IMPLEMENTATION
4.1 INTRODECTION
The study and implementation of securing symmetric key distribution in network as
mentioned in chapter 3 is partitioned into four modules.
Modules
a. sender
b. Authentication Key
c. Symmetric Cryptography
d. Receiver
4.2Sender:
The sender can send the file in other server, the message will be send securely
for using cryptography algorithms. The message will be encrypted by the user and
sender can given a key to encrypted message.
4.3Authentication Key:
A key management procedure is an essential constituent of network security.
Symmetric key systems require the keys to be kept out of reach of the adversary.
Moreover, In networks have energy-wise and computational constraints; therefore it is
necessary to maintain a balanced security level with respect to those constraints. In this
section we propose a key management scheme for networks, whose objective being the
minimization of the computational, communications-wise and storage overhead due to the
key management operations.
9
4.3.1 Key Generation:
1. Choose two large random strong prime numbers.
2. Compute n = p ¢ q.
3. Pick a random number b for which 0 · b < n.
4. The public key is (n; b), the private key is (p; q)
4.4 Symmetric Cryptography:
The RSA algorithm is used in the network to encrypt the messages and public-key
cryptography has been deemed computationally expensive for networks, and
traditional public-key algorithms require extensive computation. As a result, public-
key cryptography is not considered feasible for small devices . It offers security
equivalent to that of public-key cryptography using much smaller key sizes. The key
will be used to decryption to the receiver.
4.5 Receiver:
The receiver can be give a secret key to decrypt the message and it will be
taken the information.
10
4.5.0 OUTPUT SNAPSHOTS
11
12
CHAPTER 5
TESTING
Testing is aimed at ensuring that the system works accurately and efficiently before live
Operation commences. Testing is vital to the success of the system. System testing makes a
logical assumption that if all the parts of the system are correct, the golas will be successfully
achieved.
Testing cannot show the absence of errors and defects, it can show only the software errors
And defects that are present. The various test strategies adopted in testing this system are
Outlined. The strategies are system testing, unit testing, integration testing and validation
Testing.
5.1 SYSTEM TESTING
Bottom up testing
Each modules at the lowest level of the system is tested individually. The next to be tested are
Those that had previously tested modules. This is followed repeatedly until all the modules are
Including in the testing.
Top down testing
It is the reverse of the bottom up testing. The top level one controlling module are to be
Tested. Then all the modules are to be tested individually. Modules are all combined and
Tested as a longer unit. This approach is reapplied and tested individually.
13
Regression testing
Regression testing is the most common technique in evaluating the testing results. In
Regression testing, established software tests ate run and the results compared with the
Successful results from the previous test runs. If the results do not conform previously
Verified results, the software being tested may be in error. If the errors do exits, the software
Is said to be regressed.
5.2 UNIT TESTING
Unit testing focuses verification effort on the smallest unit of the software design. This test
Occurs as a part of unit testing. The module is tested to ensure that the proper information into
And out of the program under unit test. The sample of unit testing performed for the full
Featured test search engine based on lucene.
TEST CASES DESCRIPTION TEST STATUS
Verification of selecting file
Information
The document should be
browsed and select in the file
directory
PASS. It should be properly
Select in the correct format.
Verification of key provided The key will be given to
Encrypt the messages.
PASS. If the document is
Encrypted to given a key else
The encryption will not be
Performed.
Verification of encryption The selected document
Should be encrypted by using
Cryptography algorithm.
PASS. If the document is
Encrypted properly and if it
Has a correct formats. Else
The encryption will not be
Performed.
Verification key The user has to given the key
To decryption.
PASS. If the user given the
key it will be decrypted else
it cannot decrypted.
Table 5.1 Unit testing
14
5.3 FUNCTIONAL TESTING
This type of testing ensures the full featured text search engine is as expected. This sample
Functional testing for the full featured text search engine for application software based on
Lucene is given in the following table.
TEST CASE DESCRIPTION TEST RESULTS
Document selecting Expected to select the
Documents
The expected results
Achieved successfully
Document storing Expected to storing the files The expected results
Achieved successfully
Using key Expected key has to the
given by user
The expected results
Achieved successfully
Document encryption Expected document
Encryption has to be done
The expected results
Achieved successfully
Document decryption Expected document to be
Decrypted by the correct key
The expected results
Achieved successfully
Table 5.2 Functional testing
15
5.4 INTEGRATION TESTING
Integration testing is a systematic techniques of constructing the program structure while at the
Same time conducting the tests, which uncover errors, associated within the interface. All
Modules are combined in the step. Then the entire program as a whole and chaos usually
Results. A set of errors encountered and it is solved.
5.5 TEST REPORT
5.5.1 document storing
S. no Test case
Id
Test
description
Test
Procedure
Test Input Expected
Result
Actual
result
1 T1-1 Browsing
the file
file has to
be selected
Characters
Words and
Texts
File selected Correct
Value
2 T1-2 Storing the
File
File has
Been stored
Characters,
Works and
Texts
File
uploaded
Successfully
Correct
value
Table 5.3 Test report for document storing
16
5.5.2 Key Encryption
S. no Test
Case id
Test
Description
Test
Procedure
Test input Expected
Result
Accrual
result
1 T2-1 To provide
key to the
document
Getting the
document
with proper
formats
Characters,
tests, regular
expressions
Key
provides
Correct
value
2 T2-2 Encrypt the
file using
cryptograph
y algorithms
File to be
encrypted
by properly
Characters,
texts and
regular
expressions
Document
has to be
encrypted
Incorrect
value
Table 5.4 Test report for key encryption
5.5.3 Decryption
S. no Test
Case id
Test
Description
Test
Procedure
Test input Expected
Result
Accrual
result
1 T3-1 To give
correct key
value
Select the
same file
Enter the
correct key
Documents
found
Correct
value
2 T3-2 Checking to
incorrect
key
In correct
document
Enter the
incorrect
key
No
documents
found
Incorrect
value
Table 5.5 Test report for key Decryption
17
Conclusion:
We have presented an energy conserving method to provide key
management for networks. The method uses pre-deployed symmetric keying. A
critical observation is that device one to another secure channel establishment is not
necessary for many monitoring applications. Therefore, pre-deployed keying has
become sufficient, cost-effective approach to provide a keying infrastructure for
security protocols that use those keys. Moreover, our approach supports key
revocation and renewal mechanisms, as well. Our work is an improvement in the
energy-aware design of the key management functionality for limited environments
like networks.
6.2 FUTURE WORK
The messages will be encrypted and providing key concept used to secured
Transaction. No other can access the messages without knowing key and can’t decrypt
the message. We have presented an energy conserving method to provide key
management for Networks. The method uses pre-deployed symmetric keying. A
critical observation is that device one to another secure channel establishment is not
necessary for many monitoring application. Therefore, pre-deployed keying has
become sufficient, cost-effective approach to provide a keying infrastructure for
security protocols that use those keys. Moreover, our approach supports key
revocation and renewal mechanisms, as well. Our work is an improvement in the
energy-aware design of the key management functionality for limited environments
like networks.
18
.CHAPTER 7
REFERENCES
[1] J. Rabaey, et al., “Pico Radios for Wireless Sensor Networks: The Next Challenge in Ultra-Low-Power Design,” in Proceedings of the International Solid-State Circuits Conference, (San Francisco, CA), February 2002.
[2] W. Fumy and P. Landrock, “Principles of key management,” IEEE Journal of Selected Areas in Communications, vol. 11, pp. 785-793, June 1993.
[3] D. Carman, P. Kruus, and B. Matt, “Constraints and approaches for distributed sensor network security,” Tech. Rep. 00-010, NAI Labs, September 2000.http://download.nai.com/products/media/nai/zip/nailabsreport-00-010-final.zip.
[4] A. Perrig, et al.,, “SPINS: Security Protocols for Sensor Networks,” in Seventh Annual International Conference on Mobile Computing and Networks (MobiCOM 2001), (Rome,Italy), 2001.
19
APPENDIXES A
SAMPLE CODING
//package encryption;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.*;
import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.border.LineBorder;
public class SDES1 extends JFrame
{
public SDES1()
{
buf1 = new byte[1024];
sb1 = new StringBuffer();
bin = new int[11];
lsb = new int[5];
msb = new int[5];
p8 = new int[9];
ip = new int[9];
p10 = new int[11];
20
k1 = new int[9];
k2 = new int[9];
exp = new int[9];
xr = new int[9];
MS = 0;
LS = 0;
ss = new int[5];
xr1 = new int[5];
p4 = new int[5];
mer = new int[9];
swp = new int[9];
ipi = new int[9];
dec = new int[9];
ky1 = new int[256];
ky2 = new int[256];
plain = '\0';
cipher = '\0';
kk = 0;
kk1 = 0;
c = 0;
i = 0;
sm = 0;
initComponents();
updt();
t = new Thread();
try
{
ds = new DatagramSocket(777);
}
catch(Exception ee) { }
}
public void updt()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
cntbt.updateUI();
// ctextl.updateUI();
// ctextt.updateUI();
encb.updateUI();
fopenl.updateUI();
fopent.updateUI();
fsavel.updateUI();
fsavet.updateUI();
mmarea.updateUI();
iplabel1.updateUI();
iptext1.updateUI();
jLabel1.updateUI();
jPanel1.updateUI();
jPanel2.updateUI();
jPanel3.updateUI();
jPanel4.updateUI();
jScrollPane1.updateUI();
jScrollPane2.updateUI();
keyl.updateUI();
keyt.updateUI();
meet.updateUI();
fview.updateUI();
openb.updateUI();
prtlabel1.updateUI();
prttext1.updateUI();
// ptextl.updateUI();
// ptextt.updateUI();
saveb.updateUI();
okbt.updateUI();
jLabel2.updateUI();
jPanel5.updateUI();
}
catch(Exception e1) { }
}
public void p8(int p10[])
{
p8[1] = p10[6];
p8[2] = p10[3];
p8[3] = p10[7];
p8[4] = p10[4];
p8[5] = p10[8];
p8[6] = p10[5];
p8[7] = p10[10];
p8[8] = p10[9];
}
public void leftshift(int p10[])
{
int c = p10[1];
p10[1] = p10[2];
p10[2] = p10[3];
p10[3] = p10[4];
p10[4] = p10[5];
p10[5] = c;
int d = p10[6];
p10[6] = p10[7];
p10[7] = p10[8];
p10[8] = p10[9];
p10[9] = p10[10];
p10[10] = d;
}
public void ip1(int bin[])
{
ip[1] = bin[4];
ip[2] = bin[8];
ip[3] = bin[5];
ip[4] = bin[3];
ip[5] = bin[6];
ip[6] = bin[10];
ip[7] = bin[7];
ip[8] = bin[9];
}
public void p10(int bin[])
{
p10[1] = bin[3];
p10[2] = bin[5];
p10[3] = bin[2];
p10[4] = bin[7];
p10[5] = bin[4];
p10[6] = bin[10];
p10[7] = bin[1];
p10[8] = bin[9];
p10[9] = bin[8];
p10[10] = bin[6];
}
public void convertToBin(int b)
{
for(i = 10; i >= 1; i--)
{
bin[i] = b % 2;
b /= 2;
}
}
public void key1(char a)
{
int b = a;
convertToBin(b);
p10(bin);
leftshift(p10);
p8(p10);
for(i = 1; i <= 8; i++)
k1[i] = p8[i];
}
public void four(int ip[])
{
for(i = 1; i <= 4; i++)
msb[i] = ip[i];
int k = 5;
for(i = 1; i <= 4; i++)
{
lsb[i] = ip[k];
k++;
}
}
public void expansion()
{
exp[1] = lsb[4];
exp[2] = lsb[1];
exp[3] = lsb[2];
exp[4] = lsb[3];
exp[5] = lsb[2];
exp[6] = lsb[3];
exp[7] = lsb[4];
exp[8] = lsb[1];
}
public void xor(int k[])
{
for(i = 1; i <= 8; i++)
xr[i] = exp[i] ^ k[i];
}
public void s0s1()
{
int r1 = 0;
int c1 = 0;
int r2 = 0;
int c2 = 0;
if(xr[1] == 0 && xr[4] == 0)
r1 = 0;
else
if(xr[1] == 0 && xr[4] == 1)
r1 = 1;
else
if(xr[1] == 1 && xr[4] == 0)
r1 = 2;
else
if(xr[1] == 1 && xr[4] == 1)
r1 = 3;
if(xr[2] == 0 && xr[3] == 0)
c1 = 0;
else
if(xr[2] == 0 && xr[3] == 1)
c1 = 1;
else
if(xr[2] == 1 && xr[3] == 0)
c1 = 2;
else
if(xr[2] == 1 && xr[3] == 1)
c1 = 3;
MS = s0[r1][c1];
ss[1] = MS / 10;
ss[2] = MS % 10;
if(xr[5] == 0 && xr[8] == 0)
r2 = 0;
else
if(xr[5] == 0 && xr[8] == 1)
r2 = 1;
else
if(xr[5] == 1 && xr[8] == 0)
r2 = 2;
else
if(xr[5] == 1 && xr[8] == 1)
r2 = 3;
if(xr[6] == 0 && xr[7] == 0)
c2 = 0;
else
if(xr[6] == 0 && xr[7] == 1)
c2 = 1;
else
if(xr[6] == 1 && xr[7] == 0)
c2 = 2;
else
if(xr[6] == 1 && xr[7] == 1)
c2 = 3;
LS = s1[r2][c2];
ss[3] = LS / 10;
ss[4] = LS % 10;
}
public void pp4()
{
p4[1] = ss[2];
p4[2] = ss[4];
p4[3] = ss[3];
p4[4] = ss[1];
}
public void xor1()
{
for(i = 1; i <= 4; i++)
xr1[i] = p4[i] ^ msb[i];
}
public void merge()
{
for(i = 1; i <= 4; i++)
mer[i] = xr1[i];
int j = 1;
for(i = 5; i <= 8; i++)
{
mer[i] = lsb[j];
j++;
}
}
public void swap()
{
for(i = 1; i <= 4; i++)
swp[i] = lsb[i];
int j = 1;
for(i = 5; i <= 8; i++)
{
swp[i] = xr1[j];
j++;
}
}
public void func1()
{
expansion();
xor(k1);
s0s1();
pp4();
xor1();
merge();
}
public void func2()
{
expansion();
xor(k2);
s0s1();
pp4();
xor1();
merge();
}
private void initComponents()
{
stsdg = new JDialog();
jPanel5 = new JPanel();
jLabel2 = new JLabel();
okbt = new JButton();
jPanel1 = new JPanel();
jLabel1 = new JLabel();
jPanel2 = new JPanel();
fopenl = new JLabel();
fopent = new JTextField();
openb = new JButton();
fsavel = new JLabel();
fsavet = new JTextField();
saveb = new JButton();
jPanel3 = new JPanel();
iplabel1 = new JLabel();
iptext1 = new JTextField();
prtlabel1 = new JLabel();
prttext1 = new JTextField();
cntbt = new JButton();
jPanel4 = new JPanel();
keyl = new JLabel();
keyt = new JTextField();
encb = new JButton();
jScrollPane1 = new JScrollPane();
mmarea = new JTextArea();
jScrollPane2 = new JScrollPane();
fview = new JTextArea();
// ptextl = new JLabel();
//ctextl = new JLabel();
// ptextt = new JTextField();
// ctextt = new JTextField();
meet = new JButton();
stsdg.setTitle("Status");
stsdg.setLocationByPlatform(true);
jPanel5.setBackground(new Color(222, 221, 214));
jLabel2.setFont(new Font("Californian FB", 1, 18));
jLabel2.setText("File Encryption is done");
okbt.setText("OK");
okbt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
okbtActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
GroupLayout jPanel5Layout = new GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
stsdg.getAccessibleContext().setAccessibleParent(this);
setDefaultCloseOperation(3);
setTitle("Server");
jPanel1.setBackground(new Color(219, 215, 211));
jPanel1.setMinimumSize(new Dimension(85, 100));
jLabel1.setFont(new Font("Arial", 0, 24));
jLabel1.setText("Server");
jPanel2.setBackground(new Color(219, 215, 211));
fopenl.setText("File Open");
openb.setText("Open");
openb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
openbActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
fsavel.setText("File Save");
saveb.setText("Save");
saveb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
savebActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
iplabel1.setText("IP Address");
prtlabel1.setText("Port No");
cntbt.setText("Send");
cntbt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
cntbtActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
GroupLayout jPanel3Layout = new GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel4.setBackground(new Color(219, 215, 211));
jPanel4.setBorder(BorderFactory.createTitledBorder(new LineBorder(new Color(94, 82, 82), 1, true), "Encryption"));
keyl.setText("Key");
encb.setText("Encrypt");
encb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
encbActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
GroupLayout jPanel4Layout = new GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
mmarea.setColumns(20);
mmarea.setRows(5);
jScrollPane1.setViewportView(mmarea);
fview.setColumns(20);
fview.setRows(5);
jScrollPane2.setViewportView(fview);
//ptextl.setText("Key Text");
//ctextl.setText("Plain Text");
meet.setText("Meet in the Middle");
meet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
meetActionPerformed(evt);
}
final SDES1 this$0;
{
this$0 = SDES1.this;
// super();
}
});
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
pack();
}
public void ipi1(int mer[])
{
ipi[1] = mer[4];
ipi[2] = mer[1];
ipi[3] = mer[3];
ipi[4] = mer[5];
ipi[5] = mer[7];
ipi[6] = mer[2];
ipi[7] = mer[8];
ipi[8] = mer[6];
}
public int convertToDec(int ipi[])
{
int j = 7;
int c = 0;
for(i = 1; i <= 8; i++)
{
dec[i] = ipi[i] * (int)Math.pow(2D, j);
c += dec[i];
j--;
}
return c;
}
public void Encryption(char str[], int l)
throws IOException
{
int enc = 0;
int h = 0;
char encry[] = new char[l];
sm = 0;
for(; h < l; h++)
{
int m = str[h];
convertToBin(m);
ip1(bin);
four(ip);
func1();
swap();
four(swp);
func2();
ipi1(mer);
enc = convertToDec(ipi);
encry[h] = (char)enc;
}
String stt = fsavet.getText();
outputfile(encry, l, stt);
}
public void outputfile(char encry[], int sz, String dir1)
throws IOException
{
File f = new File(dir1);
if(!f.exists())
{
FileOutputStream fos = new FileOutputStream(f);
for(i = 0; i < sz; i++)
fos.write(encry[i]);
fos.flush();
fos.close();
} else
{
FileOutputStream fos = new FileOutputStream(dir1);
for(i = 0; i < sz; i++)
fos.write(encry[i]);
fos.flush();
fos.close();
}
}
private void openbActionPerformed(ActionEvent evt)//========================================>open
{
FileDialog fd = new FileDialog(this, "File Retriver", 0);
fd.setVisible(true);
fopn = (new StringBuilder()).append(fd.getDirectory()).append(fd.getFile()).toString();
fopent.setText(fopn);
try
{
fview.setText("");
InputStreamReader inr = new InputStreamReader(new FileInputStream(fopn));
for(BufferedReader br = new BufferedReader(inr); br.ready(); fview.append("\n"))
{
String app = br.readLine().toString();
fview.append(app);
}
}
catch(Exception fe)
{
System.out.println((new StringBuilder()).append("Exception Here : ").append(fe.toString()).toString());
}
}
private void savebActionPerformed(ActionEvent evt)
{
FileDialog fd2 = new FileDialog(this, "File Updating", 1);
fd2.setVisible(true);
fsv = (new StringBuilder()).append(fd2.getDirectory()).append(fd2.getFile()).toString();
fsavet.setText(fsv);
}
public void keyschedular(char a)
{
key1(a);
}
private void encbActionPerformed(ActionEvent evt)
{
try
{
FileInputStream fis = new FileInputStream(fopn);
int size = fis.available();
byte bb[] = new byte[size];
char arr[] = new char[size];
fis.read(bb);
for(int j = 0; j < size; j++)
arr[j] = (char)bb[j];
String ks = keyt.getText();
char kss[] = ks.toCharArray();
keyschedular(kss[0]);
Encryption(arr, size);
stsdg.setSize(300, 150);
stsdg.setLocationRelativeTo(this);
stsdg.setVisible(true);
}
catch(Exception e2) { }
}
public void convertToBin(int b)
{
for(i = 10; i >= 1; i--)
{
bin[i] = b % 2;
b /= 2;
}
}
public void p10(int bin[])
{
p10[1] = bin[3];
p10[2] = bin[5];
p10[3] = bin[2];
p10[4] = bin[7];
p10[5] = bin[4];
p10[6] = bin[10];
p10[7] = bin[1];
p10[8] = bin[9];
p10[9] = bin[8];
p10[10] = bin[6];
}
public void p8(int p10[])
{
p8[1] = p10[6];
p8[2] = p10[3];
p8[3] = p10[7];
p8[4] = p10[4];
p8[5] = p10[8];
p8[6] = p10[5];
p8[7] = p10[10];
p8[8] = p10[9];
}
public void leftshift(int p10[])
{
int c = p10[1];
p10[1] = p10[2];
p10[2] = p10[3];
p10[3] = p10[4];
p10[4] = p10[5];
p10[5] = c;
int d = p10[6];
p10[6] = p10[7];
p10[7] = p10[8];
p10[8] = p10[9];
p10[9] = p10[10];
p10[10] = d;
}
public void key1(char a)
{
int b = a;
convertToBin(b);
p10(bin);
leftshift(p10);
p8(p10);
for(i = 1; i <= 8; i++)
k1[i] = p8[i];
}
public void keyschedular(char a)
{
key1(a);
}
public void ip1(int bin[])
{
ip[1] = bin[4];
ip[2] = bin[8];
ip[3] = bin[5];
ip[4] = bin[3];
ip[5] = bin[6];
ip[6] = bin[10];
ip[7] = bin[7];
ip[8] = bin[9];
}
public void four(int ip[])
{
for(i = 1; i <= 4; i++)
msb[i] = ip[i];
int k = 5;
for(i = 1; i <= 4; i++)
{
lsb[i] = ip[k];
k++;
}
}
public void expansion()
{
exp[1] = lsb[4];
exp[2] = lsb[1];
exp[3] = lsb[2];
exp[4] = lsb[3];
exp[5] = lsb[2];
exp[6] = lsb[3];
exp[7] = lsb[4];
exp[8] = lsb[1];
}
public void xor(int k[])
{
for(i = 1; i <= 8; i++)
xr[i] = exp[i] ^ k[i];
}
public void s0s1()
{
int r1 = 0;
int c1 = 0;
int r2 = 0;
int c2 = 0;
if(xr[1] == 0 && xr[4] == 0)
r1 = 0;
else
if(xr[1] == 0 && xr[4] == 1)
r1 = 1;
else
if(xr[1] == 1 && xr[4] == 0)
r1 = 2;
else
if(xr[1] == 1 && xr[4] == 1)
r1 = 3;
if(xr[2] == 0 && xr[3] == 0)
c1 = 0;
else
if(xr[2] == 0 && xr[3] == 1)
c1 = 1;
else
if(xr[2] == 1 && xr[3] == 0)
c1 = 2;
else
if(xr[2] == 1 && xr[3] == 1)
c1 = 3;
MS = s0[r1][c1];
ss[1] = MS / 10;
ss[2] = MS % 10;
if(xr[5] == 0 && xr[8] == 0)
r2 = 0;
else
if(xr[5] == 0 && xr[8] == 1)
r2 = 1;
else
if(xr[5] == 1 && xr[8] == 0)
r2 = 2;
else
if(xr[5] == 1 && xr[8] == 1)
r2 = 3;
if(xr[6] == 0 && xr[7] == 0)
c2 = 0;
else
if(xr[6] == 0 && xr[7] == 1)
c2 = 1;
else
if(xr[6] == 1 && xr[7] == 0)
c2 = 2;
else
if(xr[6] == 1 && xr[7] == 1)
c2 = 3;
LS = s1[r2][c2];
ss[3] = LS / 10;
ss[4] = LS % 10;
}
public void pp4()
{
p4[1] = ss[2];
p4[2] = ss[4];
p4[3] = ss[3];
p4[4] = ss[1];
}
public void xor1()
{
for(i = 1; i <= 4; i++)
xr1[i] = p4[i] ^ msb[i];
}
public void merge()
{
for(i = 1; i <= 4; i++)
mer[i] = xr1[i];
int j = 1;
for(i = 5; i <= 8; i++)
{
mer[i] = lsb[j];
j++;
}
}
public void swap()
{
for(i = 1; i <= 4; i++)
swp[i] = lsb[i];
int j = 1;
for(i = 5; i <= 8; i++)
{
swp[i] = xr1[j];
j++;
}
}
public void func1()
{
expansion();
xor(k1);
s0s1();
pp4();
xor1();
merge();
}
public void func2()
{
expansion();
xor(k2);
s0s1();
pp4();
xor1();
merge();
}
public void ipi1(int mer[])
{
ipi[1] = mer[4];
ipi[2] = mer[1];
ipi[3] = mer[3];
ipi[4] = mer[5];
ipi[5] = mer[7];
ipi[6] = mer[2];
ipi[7] = mer[8];
ipi[8] = mer[6];
}
public int convertToDec(int ipi[])
{
int j = 7;
int c = 0;
for(i = 1; i <= 8; i++)
{
dec[i] = ipi[i] * (int)Math.pow(2D, j);
c += dec[i];
j--;
}
return c;
}
public void Decryption(char str1[], int l)
throws IOException
{
int dc = 0;
int h = 0;
char decry[] = new char[l];
for(; h < l; h++)
{
int m = str1[h];
convertToBin(m);
ip1(bin);
four(ip);
func2();
swap();
four(swp);
func1();
ipi1(mer);
dc = convertToDec(ipi);
decry[h] = (char)dc;
}
String stt = dtext.getText();
outputfile(decry, l, path3);
dview.setText("");
try
{
for(BufferedReader brr1 = new BufferedReader(new FileReader(path3)); brr1.ready(); dview.append("\n"))
dview.append(brr1.readLine().toString());
}
catch(Exception ec1) { }
}
public void outputfile(char encry[], int sz, String dir1)
throws IOException
{
File f = new File(dir1);
if(!f.exists())
{
FileOutputStream fos = new FileOutputStream(f);
for(i = 0; i < sz; i++)
fos.write(encry[i]);
fos.flush();
fos.close();
} else
{
FileOutputStream fos = new FileOutputStream(dir1);
for(i = 0; i < sz; i++)
fos.write(encry[i]);
fos.flush();
fos.close();
}
}
APPENDIX B