SlideShare a Scribd company logo
1 of 51
Table of ContentsTable of Contents
1. Introduction……………………………………………………. 2
2. Purpose of Cryptography…………………………………….... 3
3. Encryption and decryption…………………………………….. 4
4. Encryption Algorithms………………………………………… 5
4.1. Symmetric Algorithm……………………………….. 5
4.2. Asymmetric Algorithm……………………………… 6
5. Encryption & Decryption Technique………………………….. 7
5.1. Caesar Cipher………………………………………. 7
5.1.1. Advantage & Disadvantage……………………. 8
5.2. Rail Fence………………………………………….... 9
5.2.1. Advantage & Disadvantage……………………. 10
5.3. Vernam Cipher……………………………………… 11
5.3.1. Advantage & Disadvantage……………………. 12
5.4. Advanced Encryption Standard……………………... 13
5.4.1. Advantage & Disadvantage……………………. 14
5.5. Data Encryption Standard………………………….... 15
5.5.1. Advantage & Disadvantage…………………….. 16
6. Modified Encryption Technique……………………………… 17
6.1. Advantage & Disadvantage……………………… 19
7. Working Code………………………………………………… 20
8. Future Scope………………………………………………….. 49
9. Conclusion……………………………………………………. 50
10. Bibliography………………………………………………… 51
1
1. INTRODUCTION
Cryptography is a method of storing and transmitting data in a form that
only those it is intended for can read and process. It is a science of
protecting information by encoding it into an unreadable format.
Cryptography is an effective way of protecting sensitive information as
it is stored on media or transmitted through network communication
paths. Although the ultimate goal of cryptography, and the mechanisms
that make it up, is to hide information from unauthorized individuals,
most algorithms can be broken and the information can be revealed if
the attacker has enough time, desire, and resources. So a more realistic
goal of cryptography is to make obtaining the information too work-
intensive to be worth it to the attacker.
The first encryption methods date back to 4,000 years ago and were
considered more of an ancient art. As encryption evolved, it was mainly
used to pass messages through hostile environments of war, crisis, and
for negotiation processes between conflicting groups of people.
Throughout history, individuals and governments have worked to protect
communication by encrypting it. As time went on, the encryption
algorithms and the devices that used them increased in complexity, new
methods and algorithms were continually introduced, and it became an
integrated part of the computing world.
2
2. PURPOSE OF CRYPTOGRAPHY
Cryptography provides a number of security goals to ensure the privacy
of data, non-alteration of data and so on. Due to the great security
advantages of cryptography it is widely used today. Following are the
various goals of cryptography.
• Confidentiality:-Information in computer is transmitted and
has to be accessed only by the authorized party and not by anyone
else.
• Authentication:-The information received by any system has to
check the identity of the sender that whether the information is
arriving from a authorized person or a false identity.
• Integrity:-Only the authorized party is allowed to modify the
transmitted information. No one in between the sender and receiver
are allowed to alter the given message.
• Non Repudiation:-Ensures that neither the sender, nor the
receiver of message should be able to deny the transmission.
• Access Control:-Only the authorized parties are able to access
the given information.
3
3. ENCRYPTION & DECRYPTION
Data that can be read and understood without any special measures is
called plaintext or cleartext. The method of disguising plaintext in such a
way as to hide its substance is called encryption. Encrypting plaintext
results in unreadable gibberish called ciphertext. We use encryption to
ensure that information is hidden from anyone for whom it is not
intended, even those who can see the encrypted data. The process of
reverting ciphertext to its original plaintext is called decryption.
4
4. ENCRYPTION ALGORITHM
4.1. SYMMETRIC ALGORITHM
Symmetric algorithms (also called private-key encryption or secret-key
encryption) involve using the same key for encryption and decryption.
The most common private-key algorithms are DES (Data Encryption
Standard), Triple-DES, Blowfish, IDEA and AES (Advanced
Encryption Standard).
Symmetric key systems have very long and strong keys but at the
contrary are based on a single key for encryption and decryption with
the risk of being intercepted during the key exchange between those
involved in the process.
5
4.2. ASYMMETRIC ALGORITHMS
The public-key algorithms use two different keys to encrypt and decrypt
the message. The keys are generated by a particular algorithm that
doesn't allow to obtain one key from another. One of the keys, called
public key, is shared and will be used for the encryption process. The
other key, called private, must be kept secret and is used to decrypt the
messages.
If person A wants to send a confidential message to the person B, for
example, A encrypts the message with B's public key, being a public key
it is of public domain.
This means that the message is decipherable only with B's private key,
being a private key, it can only be in B's possession.
The most common asymmetric key algorithms are RSA (named by their
inventors: Rivest, Shamir and Adleman), Diffie-Hellman, DSS (Digital
Signature Standard), Rabin, El Gamal, elliptic curve cryptography.
6
5. ENCRYPTION & DECRYPTION
TECHNIQUE
5.1. CAESAR CIPHER
Caesar cipher
The action of a Caesar cipher is to replace each plaintext letter with one
fixed number of places down the alphabet. This example is with a left
shift of three, so that a E in the plaintext becomes B in the ciphertext.
In cryptography, a Caesar cipher, also known as Caesar's cipher, the
shift cipher, Caesar's code or Caesar shift, is one of the simplest and
most widely known encryption techniques. It is a type of substitution
cipher in which each letter in the plaintext is replaced by a letter some
fixed number of positions down the alphabet. For example, with a left
shift of 3, D would be replaced by A, E would become B, and so on. The
method is named after Julius Caesar, who used it in his private
correspondence.
The encryption step performed by a Caesar cipher is often incorporated
as part of more complex schemes, such as the Vigenère cipher, and still
has modern application in the ROT13 system. As with all single
alphabet substitution ciphers, the Caesar cipher is easily broken and in
modern practice offers essentially no communication security.
7
5.1.1. ADVANTAGE
1. Replace each letter l with l +3 mod 26
5.1.1. DISADVANTAGES
1. Algorithm: Shift characters by a fixed amount
2. Key: the fixed amount.
3. Knowing the algorithm (but not the key) makes this cipher much
easier to crack 26 possibilities vs. 26!
4. Word structure is preserved.
5. An attacker that knows the block size can separate out characters
encoded with different keys.
6. Key length is shorter than the message.
8
5.2. RAIL FENCE TECHNIQUE
Rail Fence Cipher (also called a zigzag cipher) generally refers to a
form of transposition cipher. It derives its name from the way in which it
is encoded.
In the rail fence cipher, the plaintext is written downwards and
diagonally on successive "rails" of an imaginary fence, then moving up
when we reach the bottom rail. When we reach the top rail, the message
is written downwards again until the whole plaintext is written out. The
message is then read off in rows. For example, if we have 3 "rails" and a
message of 'WE ARE DISCOVERED. FLEE AT ONCE', the cipherer
writes out:
T . . . I . . . M . . . R . . . J . . .
. H . S . S . Y . A . O . P . O . E . T
. . I . . . M . . . J . . . R . . . C .
Then reads off to get the ciphertext:
TIMRJ HSSYA OPOET IMJRC
9
5.2.1. ADVANTAGE
1. The advantage of the Rail Fence cipher over other transposition
ciphers like the sawtooth cipher is that there is a variable
distance between consecutive letters. What we mean by variable
distance is that the letters need not be arranged in fixed vertical
columns that descends, but it can also be arranged in a zig zag
manner. Therefore, this increases the difficulty of cracking the
code.
2. As we can see, the rail fence cipher is being decrypted by
reading it in arranging it in columns or rows before reading it.
therefore, it is quite a easy and fast process, and it is less prone
to mistakes.
5.2.1. DISADVANTAGE
1. One of the problems that the rail fence cipher face is that the
security of the code is dependent on the fact that a cryptanalyst
does not know the method of encryption. Hence, once the
method of encryption is broken, the code is broken already.
2. Another problem with the rail fence cipher is that is not very
strong. This means that the number of possible solutions are so
small that a cryptanalyst can try them all by hand. Therefore, the
rail fence cipher is very easy to break as we only have to test all
the possible divisors up to half the length of the text.
10
5.3. VERNAM CIPHER
In cryptography, the one-time pad (OTP) is a type of encryption which
has been proven to be impossible to crack if used correctly. Each bit or
character from the plaintext is encrypted by a modular addition with a
bit or character from a secret random key (or pad) of the same length as
the plaintext, resulting in a ciphertext. If the key is truly random, as large
as or greater than the plaintext, never reused in whole or part, and kept
secret, the ciphertext will be impossible to decrypt or break without
knowing the key. It has also been proven that any cipher with the perfect
secrecy property must use keys with effectively the same requirements
as OTP keys. However, practical problems have prevented one-time
pads from being widely used.
Example:
SENDING
-------
message: 0 0 1 0 1 1 0 1 0 1 1 1 ...
pad: 1 0 0 1 1 1 0 0 1 0 1 1 ...
XOR ------------------------------------------
cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ...
RECEIVING
---------
cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ...
pad: 1 0 0 1 1 1 0 0 1 0 1 1 ...
XOR ----------------------------------------
message: 0 0 1 0 1 1 0 1 0 1 1 1 ...
This cipher is unbreakable in a very strong sense. The intuition is that
any message can be transformed into any cipher (of the same length) by
a pad, and all transformations are equally likely. Given a two letter
message, there is a pad which adds to the message to give OK, and
another pad which adds to the message to give NO. Since either of these
pads are equally likely, the message is equally likely to be OK or NO.
11
5.3.1. ADVANTAGE
1. Theoretically unbreakable.
2. Attacker can do no better than guessing.
3. Ciphertext gives no information about plaintext.
5.3.1. DISADVANTAGE
1. The key is as long as the message, this doubles the amount of data.
2. The key must be known by sender and receiver; the key must be
transmitted somehow to the receiver and then we have the same
problem, because it makes no difference whether to send the
message or the key (It is very difficult to produce big amounts of
truly random keys).
12
5.4. AES (ADVANCED ENCRYPTION STANDARD)
The Advanced Encryption Standard (AES) is an encryption algorithm
for securing sensitive but unclassified material by U.S. Government
agencies and, as a likely consequence, may eventually become the de
facto encryption standard for commercial transactions in the private
sector. (Encryption for the US military and other classified
communications is handled by separate, secret algorithms.)
AES is based on a design principle known as a substitution-permutation
network, and is fast in both software and hardware. Unlike its
predecessor DES, AES does not use a Feistel network. AES is a variant
of Rijndael which has a fixed block size of 128 bits, and a key size of
128, 192, or 256 bits. By contrast, the Rijndael specification per se is
specified with block and key sizes that may be any multiple of 32 bits,
both with a minimum of 128 and a maximum of 256 bits.
AES operates on a 4×4 column-major order matrix of bytes, termed the
state, although some versions of Rijndael have a larger block size and
have additional columns in the state. Most AES calculations are done in
a special finite field.
The key size used for an AES cipher specifies the number of repetitions
of transformation rounds that convert the input, called the plaintext, into
the final output, called the ciphertext. The number of cycles of repetition
are as follows:
• 10 cycles of repetition for 128-bit keys.
• 12 cycles of repetition for 192-bit keys.
• 14 cycles of repetition for 256-bit keys.
Each round consists of several processing steps, including one that
depends on the encryption key itself. A set of reverse rounds are applied
to transform ciphertext back into the original plaintext using the same
encryption key.
13
5.4.1. ADVANTAGE
1. Advanced Encryption Standard not only assures security but
also improves the performance in a variety of settings such as
smartcards, hardware implementations etc.
2. AES is federal information processing standard and there are
currently no known non-brute-force direct attacks against AES.
3. AES is strong enough to be certified for use by the US
government for top secret information
4. High efficiency ,not complex ,high secure.
5.4.1 DISADVANTAGE
1. It need more processing.
2. It require more rounds of communication as compare to DES.
14
5.5. DES (DATA ENCRYPTIONE STANDARD)
The Data Encryption Standard is a previously predominant algorithm
for the encryption of electronic data. It was highly influential in the
advancement of modern cryptography in the academic world. Developed
in the early 1970s at IBM and based on an earlier design by Horst
Feistel, the algorithm was submitted to the National Bureau of Standards
(NBS) following the agency's invitation to propose a candidate for the
protection of sensitive, unclassified electronic government data. In 1976,
after consultation with the National Security Agency (NSA), the NBS
eventually selected a slightly modified version, which was published as
an official Federal Information Processing Standard (FIPS) for the
United States in 1977. The publication of an NSA-approved encryption
standard simultaneously resulted in its quick international adoption and
widespread academic scrutiny. Controversies arose out of classified
design elements, a relatively short key length of the symmetric-key
block cipher design, and the involvement of the NSA, nourishing
suspicions about a backdoor. The intense academic scrutiny the
algorithm received over time led to the modern understanding of block
ciphers and their cryptanalysis.
Data Encryption Standard
The Feistel function (F function) of DES
15
5.5.1. ADVANTAGE
1. It is a step-by-step rep. of a solution to a given problem ,which is
very easy to understand
2. It has got a definite procedure.
3. It easy to first developed an algorithm, then convert it into a
flowchart &then into a computer program.
4. It is independent of programming language.
5. It is easy to debug as every step is got its own logical sequence.
5.5.1. DISADVANTAGE
1. The 56-bit key size is the biggest defect of DES. Chips to perform
one million of DES encrypt or decrypt operations a second are
available (in 1993). A $1 million DES cracking machine can search
the entire key space in about 7 hours.
2. Hardware implementations of DES are very fast; DES was not
designed for software and hence runs relatively slowly.
16
6.MODIFIED ENCRYPTION TECHNIQUE
After studying different techniques of encryption and decryption in
symmetric key cryptography we found some disadvantage in every
method. So, to reduce the disadvantage and make the data more secure
from unauthorized user, we developed a new technique of encryption
and decryption. In this technique we used three methods of encryption
and decryption technique viz. Ceaser cipher , Rail fence, Vernam
cipher. Sender can encrypt message by using any two mention methods
and receiver can only decrypt the message by using the same methods in
the same order. This can confuse any hacker that which two method is
used from three and which one is used first. In our technique we used
only advantage of the three technique used and tried to design a unique
method which is more secure then any of the three individual method.
Let us consider an example of encrypting a text message from our new
technique.
Plaintext: hello world
17
Encrypted File
Ciphertext: 3ifmmp olwrd1
Decrypted File
18
6.1. ADVANTAGE
1. More secure because ,more than one techniques used on a
single file.
2. Attacker must know both the techniques as well as the keys
to decrypt a file.
6.1. DISADVANTAGE
1. Very time consuming when implemented on large files.
19
7. WORKING CODE
MODIFIED ENCRYPTION TECHNIQUE
import java.awt.Dialog.ModalityType;
import javax.swing.JFileChooser;
import java.io.*;
public class EncryptorDecriptor extends javax.swing.JFrame {
/** Creates new form EncryptorDecriptor */
int flag=0;
boolean r,v,ca,co,a,d;
String indx,cip1,cip2,tech1="",tech2="",plainp1,plainp2, key1pwrd,
key2pwrd,temp,ALPHABET = "abcdefghijklmnopqrstuvwxyz";
String dkey1="",dkey2="";
public EncryptorDecriptor() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jd1 = new javax.swing.JDialog();
jLabel6 = new javax.swing.JLabel();
close_bttn1 = new javax.swing.JButton();
jd2 = new javax.swing.JDialog();
jLabel7 = new javax.swing.JLabel();
close_bttn2 = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
browse_tfield = new javax.swing.JTextField();
browse_bttn = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jSeparator2 = new javax.swing.JSeparator();
techDone_bttn = new javax.swing.JButton();
combox2 = new javax.swing.JComboBox();
combox1 = new javax.swing.JComboBox();
20
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
info_label = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
keyDone_bttn1 = new javax.swing.JButton();
keyDone_bttn2 = new javax.swing.JButton();
info_label2 = new javax.swing.JLabel();
final_bttn = new javax.swing.JButton();
encryp_radio = new javax.swing.JRadioButton();
decryp_radio = new javax.swing.JRadioButton();
key1_tfield = new javax.swing.JTextField();
key2_tfield = new javax.swing.JTextField();
decrypt_ok = new javax.swing.JButton();
jLabel8 = new javax.swing.JLabel();
jTextField1.setText("jTextField1");
jd1.setAlwaysOnTop(true);
jd1.setBounds(new java.awt.Rectangle(225, 225, 400, 145));
jd1.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_M
ODAL);
jd1.setResizable(false);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel6.setText("FILE SUCCESSSFULLY ENCRYPTED!!!");
close_bttn1.setFont(new java.awt.Font("Tahoma", 1, 11)); //
NOI18N
close_bttn1.setText("OK");
close_bttn1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt) {
close_bttn1ActionPerformed(evt);
}
});
21
javax.swing.GroupLayout jd1Layout = new
javax.swing.GroupLayout(jd1.getContentPane());
jd1.getContentPane().setLayout(jd1Layout);
jd1Layout.setHorizontalGroup( jd1Layout.createParallelGroup(java
x.swing.GroupLayout.Alignment.LEADING)
.addGroup(jd1Layout.createSequentialGroup()
.addGroup(jd1Layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(jd1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel6,
javax.swing.GroupLayout.DEFAULT_SIZE, 365,
Short.MAX_VALUE))
.addGroup(jd1Layout.createSequentialGroup()
.addGap(152, 152, 152)
.addComponent(close_bttn1,
javax.swing.GroupLayout.PREFERRED_SIZE, 76,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jd1Layout.setVerticalGroup(
jd1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jd1Layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jLabel6,
javax.swing.GroupLayout.PREFERRED_SIZE, 29,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
22
.addComponent(close_bttn1,
javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(38, Short.MAX_VALUE))
);
jd2.setBounds(new java.awt.Rectangle(225, 225, 400, 145));
jd2.setModal(true);
jd2.setResizable(false);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel7.setText("FILE SUCCESSSFULLY DECRYPTED!!!");
close_bttn2.setFont(new java.awt.Font("Tahoma", 1, 11)); //
NOI18N
close_bttn2.setText("OK");
close_bttn2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt) {
close_bttn2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jd2Layout = new
javax.swing.GroupLayout(jd2.getContentPane());
jd2.getContentPane().setLayout(jd2Layout);
jd2Layout.setHorizontalGroup(
jd2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jd2Layout.createSequentialGroup()
.addGroup(jd2Layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(jd2Layout.createSequentialGroup()
.addGap(25, 25, 25)
23
.addComponent(jLabel7,
javax.swing.GroupLayout.DEFAULT_SIZE, 370,
Short.MAX_VALUE))
.addGroup(jd2Layout.createSequentialGroup()
.addGap(155, 155, 155)
.addComponent(close_bttn2,
javax.swing.GroupLayout.PREFERRED_SIZE, 76,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jd2Layout.setVerticalGroup(
jd2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jd2Layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jLabel7,
javax.swing.GroupLayout.PREFERRED_SIZE, 29,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(close_bttn2,
javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(35, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_C
LOSE);
browse_tfield.setEditable(false);
browse_tfield.setFont(new java.awt.Font("Rod", 0, 11));
browse_tfield.setText("SELECT FILE TO BE ENCRYPTED");
browse_bttn.setFont(new java.awt.Font("Tahoma", 1, 11));
browse_bttn.setText("BROWSE");
24
browse_bttn.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browse_bttnActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Verdana", 1, 12));
jLabel1.setText("CHOOSE ANY TWO ENCRYPTION
TECHNIQUE");
techDone_bttn.setFont(new java.awt.Font("Tahoma", 1, 11));
techDone_bttn.setText("DONE");
techDone_bttn.setEnabled(false);
techDone_bttn.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
techDone_bttnActionPerformed(evt);
}
});
combox2.setModel(new javax.swing.DefaultComboBoxModel(new
String[] { "RAIL FENCE", "VERNAM", "CAESAR" }));
combox2.setEnabled(false);
combox1.setModel(new javax.swing.DefaultComboBoxModel(new
String[] { "RAIL FENCE", "VERNAM", "CAESAR" }));
combox1.setEnabled(false);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel2.setText("TECHNIQUE 1");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel3.setText("TECHNIQUE 2");
info_label.setForeground(new java.awt.Color(255, 51, 0));
25
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel4.setText("KEY 1 :");
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel5.setText("KEY 2 :");
keyDone_bttn1.setFont(new java.awt.Font("Tahoma", 1, 11)); //
NOI18N
keyDone_bttn1.setText("DONE");
keyDone_bttn1.setEnabled(false);
keyDone_bttn1.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keyDone_bttn1ActionPerformed(evt);
}
});
keyDone_bttn2.setFont(new java.awt.Font("Tahoma", 1, 11)); //
NOI18N
keyDone_bttn2.setText("DONE");
keyDone_bttn2.setEnabled(false);
keyDone_bttn2.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keyDone_bttn2ActionPerformed(evt);
}
});
info_label2.setForeground(new java.awt.Color(255, 51, 0));
final_bttn.setForeground(new java.awt.Color(255, 255, 255));
final_bttn.setBorder(null);
final_bttn.setBorderPainted(false);
final_bttn.setFocusPainted(false);
final_bttn.setFocusable(false);
final_bttn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
final_bttnActionPerformed(evt);
26
}
});
encryp_radio.setFont(new java.awt.Font("Tahoma", 1, 11));
encryp_radio.setSelected(true);
encryp_radio.setText("ENCRYPTION");
encryp_radio.setEnabled(false);
encryp_radio.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
encryp_radioActionPerformed(evt);
}
});
decryp_radio.setFont(new java.awt.Font("Tahoma", 1, 11));
decryp_radio.setText("DECRYPTION");
decryp_radio.setEnabled(false);
decryp_radio.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decryp_radioActionPerformed(evt);
}
});
key1_tfield.setEnabled(false);
key2_tfield.setEnabled(false);
decrypt_ok.setText("Decrypt");
decrypt_ok.setEnabled(false);
decrypt_ok.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt) {
decrypt_okActionPerformed(evt);
}
});
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
27
jLabel8.setText("FILE ENCRYPTER/DECRYPTER");
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(browse_tfield,
javax.swing.GroupLayout.PREFERRED_SIZE, 498,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(47, 47, 47)
.addComponent(browse_bttn)
.addGap(77, 77, 77))
.addComponent(jSeparator2,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 728,
Short.MAX_VALUE)
.addComponent(jSeparator1,
javax.swing.GroupLayout.DEFAULT_SIZE, 728,
Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(95, 95, 95)
28
.addComponent(info_label,
javax.swing.GroupLayout.DEFAULT_SIZE, 337,
Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED))
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 93,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(combox1,
javax.swing.GroupLayout.PREFERRED_SIZE, 108,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED, 80, Short.MAX_VALUE)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 93,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(22, 22, 22)))
.addComponent(combox2,
javax.swing.GroupLayout.PREFERRED_SIZE, 97,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(111, 111, 111)
.addComponent(encryp_radio)
.addGap(227, 227, 227)
.addComponent(decryp_radio)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
29
.addComponent(techDone_bttn,
javax.swing.GroupLayout.PREFERRED_SIZE, 81,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(84, 84, 84))
.addGroup(layout.createSequentialGroup()
.addGap(74, 74, 74)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING)
.addComponent(info_label2,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 394,
Short.MAX_VALUE)
.addComponent(key2_tfield,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 394,
Short.MAX_VALUE)
.addComponent(key1_tfield,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 394,
Short.MAX_VALUE))
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.TRAILING, false)
.addComponent(keyDone_bttn1,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
30
.addComponent(keyDone_bttn2,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
.addComponent(decrypt_ok,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(final_bttn,
javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(47, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(174, 174, 174)
.addComponent(jLabel1)
.addContainerGap(248, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(157, 157, 157)
.addComponent(jLabel8,
javax.swing.GroupLayout.PREFERRED_SIZE, 408,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(163, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel8,
javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
31
.addComponent(browse_tfield,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(browse_bttn))
.addGap(27, 27, 27)
.addComponent(jSeparator1,
javax.swing.GroupLayout.PREFERRED_SIZE, 2,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(decryp_radio)
.addComponent(encryp_radio))
.addGap(29, 29, 29)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(combox1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(techDone_bttn)
.addComponent(combox2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE))
32
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(info_label,
javax.swing.GroupLayout.PREFERRED_SIZE, 9,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addComponent(jSeparator2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 19,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(key1_tfield,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(keyDone_bttn1))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE)
.addComponent(jLabel5,
javax.swing.GroupLayout.PREFERRED_SIZE, 19,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(keyDone_bttn2)
.addComponent(key2_tfield,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
33
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL
ATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(decrypt_ok)
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(final_bttn,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap(40, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(info_label2,
javax.swing.GroupLayout.PREFERRED_SIZE, 9,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()))))
);
pack();
}// </editor-fold>
private void browse_bttnActionPerformed(java.awt.event.ActionEvent
evt) {
FChooser frame=new FChooser();
browse_tfield.setText(frame.FName);
combox1.setEnabled(true);
combox2.setEnabled(true);
techDone_bttn.setEnabled(true);
encryp_radio.setEnabled(true);
decryp_radio.setEnabled(true);
}
34
private void
techDone_bttnActionPerformed(java.awt.event.ActionEvent evt) {
String c1=combox1.getSelectedItem().toString();
String c2=combox2.getSelectedItem().toString();
if(c1.equals(c2)){
info_label.setText("** MUST SELECT TWO DIFFERENT
TECHNIQUES **");
}
if(c1=="VERNAM" || c1=="CAESAR")
{info_label.setText("");
key1_tfield.setEnabled(true);
keyDone_bttn1.setEnabled(true);
}
if(c2=="VERNAM" || c2=="CAESAR")
{
info_label.setText("");
key2_tfield.setEnabled(true);
keyDone_bttn2.setEnabled(true);
info_label2.setText("");
}
}
private void
keyDone_bttn1ActionPerformed(java.awt.event.ActionEvent evt) {
String c1=combox1.getSelectedItem().toString();
String c2=combox2.getSelectedItem().toString();
int key1len=key1_tfield.getText().length();
if(key1len==0){
info_label2.setText("** MUST ENTER KEY 1 **");
}
else if(key1len>0){
info_label2.setText("");
if(c2=="VERNAM" || c2=="CAESAR")
{
key2_tfield.setEnabled(true);
keyDone_bttn2.setEnabled(true);
35
}
else if(c2!="VERNAM" || c2!="CAESAR"){
final_bttn.doClick();
}
}
}
private void
keyDone_bttn2ActionPerformed(java.awt.event.ActionEvent evt) {
int key2len=key2_tfield.getText().length();
if(key2len==0){
info_label2.setText("** MUST ENTER KEY 2 **");
}
else{
info_label2.setText(" ");
final_bttn.doClick();
}
}
private void encryp_radioActionPerformed(java.awt.event.ActionEvent
evt) {
decryp_radio.setSelected(false);
encryp_radio.setSelected(true);
combox1.setEnabled(true);
combox2.setEnabled(true);
techDone_bttn.setEnabled(true);
}
private void decryp_radioActionPerformed(java.awt.event.ActionEvent
evt) {
encryp_radio.setSelected(false);
decryp_radio.setSelected(true);
combox1.setEnabled(false);
combox2.setEnabled(false);
techDone_bttn.setEnabled(false);
key1_tfield.setEnabled(true);
key2_tfield.setEnabled(true);
decrypt_ok.setEnabled(true);
36
}
private void final_bttnActionPerformed(java.awt.event.ActionEvent evt)
{
boolean sel=encryp_radio.isSelected();
if(sel==true){
encryp();
}
}
private void decrypt_okActionPerformed(java.awt.event.ActionEvent
evt) {
decryp();
}
private void close_bttn1ActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
jd1.dispose();
}
private void close_bttn2ActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
jd2.dispose();
}
void encryp() {
try{
File file=new File(browse_tfield.getText());
int len=(int)file.length();
FileReader f=new FileReader(browse_tfield.getText());
FileWriter fw=new FileWriter("EncryptedFile.txt");
char data[]=new char[len];
int charsread=f.read(data);
String txt=new String(data,0,charsread);
int p1index=txt.length()/2;
int p2index=p1index+1;
37
String p1=txt.substring(0, p1index);
String p2=txt.substring(p2index-1,txt.length());
String t1=combox1.getSelectedItem().toString();
String t2=combox2.getSelectedItem().toString();
if("RAIL FENCE".equals(t1)){
cip1=rail_encryp(p1);
indx="1";
cip1=indx.concat(cip1);
}
else if( "VERNAM".equals(t1)){
indx="2";
String pwrd=key1_tfield.getText().toString();
cip1=vernam_encryp(p1,pwrd);
cip1=indx.concat(cip1);
}
else if( "CAESAR".equals(t1)){
indx="3";
String pwrd=key1_tfield.getText().toString();
int password=Integer.parseInt(pwrd);
cip1=caesar_encryp(p1,password);
cip1=indx.concat(cip1);
}
if("RAIL FENCE".equals(t2)){
cip2=rail_encryp(p2);
indx="1";
cip2=cip2.concat(indx);
}
else if( "VERNAM".equals(t2)){
indx="2";
String pwrd=key2_tfield.getText().toString();
cip2=vernam_encryp(p2,pwrd);
cip2=cip2.concat(indx);
}
else if( "CAESAR".equals(t2)){
indx="3";
String pwrd=key2_tfield.getText().toString();
38
int password=Integer.parseInt(pwrd);
cip2=caesar_encryp(p2,password);
cip2=cip2.concat(indx);
}
String ciptxt=cip1.concat(cip2);
fw.write(ciptxt);
f.close();
fw.close();
keyDone_bttn2.setEnabled(false);
keyDone_bttn1.setEnabled(false);
jd1.setVisible(true);
jd1.setPreferredSize(null);
}
catch(IOException e){}
}
void decryp(){
keyDone_bttn1.setEnabled(false);
keyDone_bttn2.setEnabled(false);
jd2.setVisible(true);
jd2.setPreferredSize(null);
try{
File file=new File(browse_tfield.getText());
int len=(int)file.length();
FileReader f=new FileReader(browse_tfield.getText());
String path="DecryptedFile.txt";
FileWriter fw=new FileWriter(path);
char data[]=new char[len];
int charsread=f.read(data);
String txt=new String(data,0,charsread);
StringBuffer sb=new StringBuffer(txt);
String ciphertxt=sb.substring(1,len-1);
tech1=sb.substring(0,1);
tech2=sb.substring(len-1,len);
int p1index=ciphertxt.length()/2;
int p2index=p1index+1;
String p1=ciphertxt.substring(0, p1index);
String p2=ciphertxt.substring(p2index-1,ciphertxt.length());
39
dkey1=key1_tfield.getText();
dkey2=key2_tfield.getText();
if(tech1.equals("1")){
plainp1=rail_decryp(p1);
}
else if(tech1.equals("2")){
plainp1=vernam_decryp(p1,dkey1);
}
else if(tech1.equals("3")){
plainp1=caesar_decryp(p1,dkey1);
}
if(tech2.equals("1")){
plainp2=rail_decryp(p2);
}
else if(tech2.equals("2")){
plainp2=vernam_decryp(p2,dkey2);
}
else if(tech2.equals("3")){
plainp2=caesar_decryp(p2,dkey2);
}
String pText=plainp1.concat(plainp2);
fw.write(pText);
f.close();
fw.close();
}
catch(IOException e){}
}
String rail_encryp(String a){
String output = "";
int len = a.length(),flag = 0;
for(int i=0;i<len;i+=2) {
output += a.charAt(i);
40
}
for(int i=1;i<len;i+=2) {
output += a.charAt(i);
}
return(output);
}
String vernam_encryp(String a,String p){
int j;
String app="";
char[] arText = a.toCharArray();
char[] arCipher = p.toCharArray();
char[] encoded = new char[arText.length];
for (int i = 0; i < arText.length; i++) {
j=i;
if(j>p.length()-1){
j = 0;
}
encoded[i] = (char) (arText[i] ^ arCipher[j]);
app += encoded[i];
}
return(app);
}
String caesar_encryp(String a,int p){
{
String ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY
Z";
String cipherText="";
for(int i=0;i<a.length();i++)
{
char character=a.charAt(i);
String str=String.valueOf(character);
if(str.equals(" ")){
41
char replaceVal = '&';
cipherText += replaceVal;
}
else if(str.equals(".")){
cipherText +=".";
}
else{
int charPosition = ALPHABET.indexOf(a.charAt(i));
int keyVal = (p+charPosition)%52;
char replaceVal = ALPHABET.charAt(keyVal);
cipherText += replaceVal;
}
}
return(cipherText);
}
}
String rail_decryp(String p){
String outputdec = "";
char[] str=p.toCharArray();
int len = p.length(),flag = 0,i,j=0;
char[] out=new char[len];
if(len%2==0){
int mid=len/2;
for(i=0;i<len;i++){
if(i%2==0){
out[i]=str[j];
j += 1;
outputdec += out[i];
}
else{
out[i]=str[mid];
mid += 1;
outputdec += out[i];
}
}
}
42
else if(len%2!=0)
{
int mid=(len/2)+1;
for(i=0;i<len;i++){
if(i%2==0){
out[i]=str[j];
j += 1;
outputdec += out[i];
}
else{
out[i]=str[mid];
mid += 1;
outputdec += out[i];
}
}
}
return(outputdec);
}
String vernam_decryp(String text,String cipher){
int j=0;
String app="";
char[] arText =text.toCharArray();
char[] arCipher = cipher.toCharArray();
char[] decoded = new char[arText.length];
for (int i = 0; i < text.length(); i++) {
j=i;
if(j>cipher.length()-1){
j=0;
}
decoded[i] = (char) (arText[i] ^ arCipher[j]);
app +=decoded[i];
}
return(app);
}
String caesar_decryp(String p,String k){
43
String ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY
Z";
int shiftKey=Integer.parseInt(k);
String plainText="";
for(int i=0;i<p.length();i++)
{
char character=p.charAt(i);
String str=String.valueOf(character);
if(str.equals("&")){
char replaceVal = ' ';
plainText += replaceVal;
}
else if(str.equals(".")){
plainText +=".";
}
else{
int charPosition = ALPHABET.indexOf(p.charAt(i));
int keyVal = (charPosition-shiftKey)%52;
if(keyVal<0)
{
keyVal = ALPHABET.length() + keyVal;
}
char replaceVal = ALPHABET.charAt(keyVal);
plainText += replaceVal;
}}
return(plainText);
}
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EncryptorDecriptor().setVisible(true);
}
});
44
}
// Variables declaration - do not modify
public javax.swing.JButton browse_bttn;
public javax.swing.JTextField browse_tfield;
public javax.swing.JButton close_bttn1;
public javax.swing.JButton close_bttn2;
public javax.swing.JComboBox combox1;
public javax.swing.JComboBox combox2;
public javax.swing.JRadioButton decryp_radio;
public javax.swing.JButton decrypt_ok;
public javax.swing.JRadioButton encryp_radio;
public javax.swing.JButton final_bttn;
public javax.swing.JLabel info_label;
public javax.swing.JLabel info_label2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextField jTextField1;
public javax.swing.JDialog jd1;
public javax.swing.JDialog jd2;
public javax.swing.JTextField key1_tfield;
public javax.swing.JTextField key2_tfield;
public javax.swing.JButton keyDone_bttn1;
public javax.swing.JButton keyDone_bttn2;
public javax.swing.JButton techDone_bttn;
// End of variables declaration
}
class FChooser extends javax.swing.JFrame{
JFileChooser chooser;
45
String FName;
public FChooser(){
chooser=new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int r=chooser.showOpenDialog(new javax.swing.JFrame());
if(r==JFileChooser.APPROVE_OPTION){
FName=chooser.getSelectedFile().getPath();
}
}
}
46
OUTPUT
ENCRYPTION:-
ENCRYPTED FILE:-
47
DECRYPTION
DECRYPTED FILE:-
48
8. FUTURE SCOPE
We used two techniques in our new method to encrypt and decrypt
message and provide security. In future this can be done by using five or
more encryption techniques of cryptography. We tried this technique to
encrypt and decrypt different message and found that in case of large
massage it is time consuming. But in our point of view, in case of small
message this is the best way to provide security. We are working on it to
minimize the time taking disadvantage so that it can be used for
encryption of large message as well.
49
9. CONCLUSION
We have proposed a method for implementing symmetric key
cryptosystem whose security rests in part on the difficulty of encrypting/
decrypting with two different techniques. If the security of our method
proves to be adequate, it permits secure communications to be
established without the use of secure channels to carry keys.
The security of this system needs to be examined in more detail. Using
three or more techniques of cryptography makes the data more secure
rather than using two techniques.
Once the method has withstood all attacks for sufficient length of time it
may be used with a reasonable amount of confidence.
50
10. BIBLIOGRAPHY
Websites:
1. www.google.com
2. www.DreamInCode.com
3. www.stackoverflow.com
4. www.killthecode.com
Books:
1. CRYPTORGAPHY AND NETWORK SECURITY by Atul Kahate
2. CRYPTORGAPHY AND NETWORK SECURITY by B.A. Forouzan
3. JAVA 6 PROGRAMMING BLACK BOOK
51

More Related Content

What's hot

CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYKathirvel Ayyaswamy
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network securityshraddha mane
 
Cryptography full report
Cryptography full reportCryptography full report
Cryptography full reportharpoo123143
 
Cryptography and Network Lecture Notes
Cryptography and Network Lecture NotesCryptography and Network Lecture Notes
Cryptography and Network Lecture NotesFellowBuddy.com
 
BAIT1103 Chapter 3
BAIT1103 Chapter 3BAIT1103 Chapter 3
BAIT1103 Chapter 3limsh
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptographyPavithra renu
 
Encryption presentation final
Encryption presentation finalEncryption presentation final
Encryption presentation finaladrigee12
 
computer-security-and-cryptography-a-simple-presentation
computer-security-and-cryptography-a-simple-presentationcomputer-security-and-cryptography-a-simple-presentation
computer-security-and-cryptography-a-simple-presentationAlex Punnen
 
Cryptography and network security
 Cryptography and network security Cryptography and network security
Cryptography and network securityMahipesh Satija
 
Cryptographic tools
Cryptographic toolsCryptographic tools
Cryptographic toolsCAS
 
A study of cryptography for satellite applications
A study of cryptography for satellite applicationsA study of cryptography for satellite applications
A study of cryptography for satellite applicationsRajesh Ishida
 
Seminar report on symmetric key
Seminar report on symmetric keySeminar report on symmetric key
Seminar report on symmetric keyRajat Tripathi
 
5 Cryptography Part1
5 Cryptography Part15 Cryptography Part1
5 Cryptography Part1Alfred Ouyang
 

What's hot (20)

Security and Cryptography
Security and CryptographySecurity and Cryptography
Security and Cryptography
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
Encryption and Key Distribution Methods
Encryption and Key Distribution MethodsEncryption and Key Distribution Methods
Encryption and Key Distribution Methods
 
Cryptography
Cryptography Cryptography
Cryptography
 
Public key cryptography
Public key cryptographyPublic key cryptography
Public key cryptography
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
Cryptography full report
Cryptography full reportCryptography full report
Cryptography full report
 
Cryptography and Network Lecture Notes
Cryptography and Network Lecture NotesCryptography and Network Lecture Notes
Cryptography and Network Lecture Notes
 
BAIT1103 Chapter 3
BAIT1103 Chapter 3BAIT1103 Chapter 3
BAIT1103 Chapter 3
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptography
 
Network security
Network securityNetwork security
Network security
 
Encryption presentation final
Encryption presentation finalEncryption presentation final
Encryption presentation final
 
computer-security-and-cryptography-a-simple-presentation
computer-security-and-cryptography-a-simple-presentationcomputer-security-and-cryptography-a-simple-presentation
computer-security-and-cryptography-a-simple-presentation
 
Cryptography and network security
 Cryptography and network security Cryptography and network security
Cryptography and network security
 
Cryptographic tools
Cryptographic toolsCryptographic tools
Cryptographic tools
 
cryptography
cryptographycryptography
cryptography
 
A study of cryptography for satellite applications
A study of cryptography for satellite applicationsA study of cryptography for satellite applications
A study of cryptography for satellite applications
 
Network Security
Network SecurityNetwork Security
Network Security
 
Seminar report on symmetric key
Seminar report on symmetric keySeminar report on symmetric key
Seminar report on symmetric key
 
5 Cryptography Part1
5 Cryptography Part15 Cryptography Part1
5 Cryptography Part1
 

Similar to MAJOR PROJECT FORMAT--2013(new 1)

Bt0088 cryptography and network security1
Bt0088 cryptography and network security1Bt0088 cryptography and network security1
Bt0088 cryptography and network security1Techglyphs
 
Cryptography- "A Black Art"
Cryptography- "A Black Art"Cryptography- "A Black Art"
Cryptography- "A Black Art"Aditya Raina
 
A Survey on Cryptographic Techniques for Network Security.pdf
A Survey on Cryptographic Techniques for Network Security.pdfA Survey on Cryptographic Techniques for Network Security.pdf
A Survey on Cryptographic Techniques for Network Security.pdfYasmine Anino
 
Computer Security (Cryptography) Ch01
Computer Security (Cryptography) Ch01Computer Security (Cryptography) Ch01
Computer Security (Cryptography) Ch01Saif Kassim
 
Cryptography and E-Commerce
Cryptography and E-CommerceCryptography and E-Commerce
Cryptography and E-CommerceHiep Luong
 
Cryptography by manisha jha
Cryptography by manisha jhaCryptography by manisha jha
Cryptography by manisha jhaManishaJha43
 
Cryptography by Durlab Kumbhakar
Cryptography by Durlab KumbhakarCryptography by Durlab Kumbhakar
Cryptography by Durlab KumbhakarDurlove Kumbhakar
 
Introduction to Cryptography Week4 Part1-ISrevisionSu.docx
Introduction to Cryptography  Week4 Part1-ISrevisionSu.docxIntroduction to Cryptography  Week4 Part1-ISrevisionSu.docx
Introduction to Cryptography Week4 Part1-ISrevisionSu.docxmariuse18nolet
 
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptx
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptxSecret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptx
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptxjibonjibon5
 
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUES
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUESA REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUES
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUESValerie Felton
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
DES- Data Encryption Standard
DES- Data Encryption StandardDES- Data Encryption Standard
DES- Data Encryption StandardIRJET Journal
 

Similar to MAJOR PROJECT FORMAT--2013(new 1) (20)

Bt0088 cryptography and network security1
Bt0088 cryptography and network security1Bt0088 cryptography and network security1
Bt0088 cryptography and network security1
 
Cryptography- "A Black Art"
Cryptography- "A Black Art"Cryptography- "A Black Art"
Cryptography- "A Black Art"
 
A Survey on Cryptographic Techniques for Network Security.pdf
A Survey on Cryptographic Techniques for Network Security.pdfA Survey on Cryptographic Techniques for Network Security.pdf
A Survey on Cryptographic Techniques for Network Security.pdf
 
Computer Security (Cryptography) Ch01
Computer Security (Cryptography) Ch01Computer Security (Cryptography) Ch01
Computer Security (Cryptography) Ch01
 
Cryptography and E-Commerce
Cryptography and E-CommerceCryptography and E-Commerce
Cryptography and E-Commerce
 
Cryptography by manisha jha
Cryptography by manisha jhaCryptography by manisha jha
Cryptography by manisha jha
 
Cryptography by Durlab Kumbhakar
Cryptography by Durlab KumbhakarCryptography by Durlab Kumbhakar
Cryptography by Durlab Kumbhakar
 
Unit-2-IS (1).pdf
Unit-2-IS (1).pdfUnit-2-IS (1).pdf
Unit-2-IS (1).pdf
 
Introduction to Cryptography Week4 Part1-ISrevisionSu.docx
Introduction to Cryptography  Week4 Part1-ISrevisionSu.docxIntroduction to Cryptography  Week4 Part1-ISrevisionSu.docx
Introduction to Cryptography Week4 Part1-ISrevisionSu.docx
 
Cryptography
CryptographyCryptography
Cryptography
 
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptx
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptxSecret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptx
Secret-Key-Cryptography-ppt-by-alljobs.co_.in_.pptx
 
Cns 1
Cns 1Cns 1
Cns 1
 
groupWork.pptx
groupWork.pptxgroupWork.pptx
groupWork.pptx
 
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUES
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUESA REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUES
A REVIEW STUDY OF CRYPTOGRAPHY TECHNIQUES
 
Cryptography
CryptographyCryptography
Cryptography
 
Unit 1 QB.docx
Unit 1 QB.docxUnit 1 QB.docx
Unit 1 QB.docx
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
DES- Data Encryption Standard
DES- Data Encryption StandardDES- Data Encryption Standard
DES- Data Encryption Standard
 
chapter 7.pptx
chapter 7.pptxchapter 7.pptx
chapter 7.pptx
 
Data encryption
Data encryptionData encryption
Data encryption
 

MAJOR PROJECT FORMAT--2013(new 1)

  • 1. Table of ContentsTable of Contents 1. Introduction……………………………………………………. 2 2. Purpose of Cryptography…………………………………….... 3 3. Encryption and decryption…………………………………….. 4 4. Encryption Algorithms………………………………………… 5 4.1. Symmetric Algorithm……………………………….. 5 4.2. Asymmetric Algorithm……………………………… 6 5. Encryption & Decryption Technique………………………….. 7 5.1. Caesar Cipher………………………………………. 7 5.1.1. Advantage & Disadvantage……………………. 8 5.2. Rail Fence………………………………………….... 9 5.2.1. Advantage & Disadvantage……………………. 10 5.3. Vernam Cipher……………………………………… 11 5.3.1. Advantage & Disadvantage……………………. 12 5.4. Advanced Encryption Standard……………………... 13 5.4.1. Advantage & Disadvantage……………………. 14 5.5. Data Encryption Standard………………………….... 15 5.5.1. Advantage & Disadvantage…………………….. 16 6. Modified Encryption Technique……………………………… 17 6.1. Advantage & Disadvantage……………………… 19 7. Working Code………………………………………………… 20 8. Future Scope………………………………………………….. 49 9. Conclusion……………………………………………………. 50 10. Bibliography………………………………………………… 51 1
  • 2. 1. INTRODUCTION Cryptography is a method of storing and transmitting data in a form that only those it is intended for can read and process. It is a science of protecting information by encoding it into an unreadable format. Cryptography is an effective way of protecting sensitive information as it is stored on media or transmitted through network communication paths. Although the ultimate goal of cryptography, and the mechanisms that make it up, is to hide information from unauthorized individuals, most algorithms can be broken and the information can be revealed if the attacker has enough time, desire, and resources. So a more realistic goal of cryptography is to make obtaining the information too work- intensive to be worth it to the attacker. The first encryption methods date back to 4,000 years ago and were considered more of an ancient art. As encryption evolved, it was mainly used to pass messages through hostile environments of war, crisis, and for negotiation processes between conflicting groups of people. Throughout history, individuals and governments have worked to protect communication by encrypting it. As time went on, the encryption algorithms and the devices that used them increased in complexity, new methods and algorithms were continually introduced, and it became an integrated part of the computing world. 2
  • 3. 2. PURPOSE OF CRYPTOGRAPHY Cryptography provides a number of security goals to ensure the privacy of data, non-alteration of data and so on. Due to the great security advantages of cryptography it is widely used today. Following are the various goals of cryptography. • Confidentiality:-Information in computer is transmitted and has to be accessed only by the authorized party and not by anyone else. • Authentication:-The information received by any system has to check the identity of the sender that whether the information is arriving from a authorized person or a false identity. • Integrity:-Only the authorized party is allowed to modify the transmitted information. No one in between the sender and receiver are allowed to alter the given message. • Non Repudiation:-Ensures that neither the sender, nor the receiver of message should be able to deny the transmission. • Access Control:-Only the authorized parties are able to access the given information. 3
  • 4. 3. ENCRYPTION & DECRYPTION Data that can be read and understood without any special measures is called plaintext or cleartext. The method of disguising plaintext in such a way as to hide its substance is called encryption. Encrypting plaintext results in unreadable gibberish called ciphertext. We use encryption to ensure that information is hidden from anyone for whom it is not intended, even those who can see the encrypted data. The process of reverting ciphertext to its original plaintext is called decryption. 4
  • 5. 4. ENCRYPTION ALGORITHM 4.1. SYMMETRIC ALGORITHM Symmetric algorithms (also called private-key encryption or secret-key encryption) involve using the same key for encryption and decryption. The most common private-key algorithms are DES (Data Encryption Standard), Triple-DES, Blowfish, IDEA and AES (Advanced Encryption Standard). Symmetric key systems have very long and strong keys but at the contrary are based on a single key for encryption and decryption with the risk of being intercepted during the key exchange between those involved in the process. 5
  • 6. 4.2. ASYMMETRIC ALGORITHMS The public-key algorithms use two different keys to encrypt and decrypt the message. The keys are generated by a particular algorithm that doesn't allow to obtain one key from another. One of the keys, called public key, is shared and will be used for the encryption process. The other key, called private, must be kept secret and is used to decrypt the messages. If person A wants to send a confidential message to the person B, for example, A encrypts the message with B's public key, being a public key it is of public domain. This means that the message is decipherable only with B's private key, being a private key, it can only be in B's possession. The most common asymmetric key algorithms are RSA (named by their inventors: Rivest, Shamir and Adleman), Diffie-Hellman, DSS (Digital Signature Standard), Rabin, El Gamal, elliptic curve cryptography. 6
  • 7. 5. ENCRYPTION & DECRYPTION TECHNIQUE 5.1. CAESAR CIPHER Caesar cipher The action of a Caesar cipher is to replace each plaintext letter with one fixed number of places down the alphabet. This example is with a left shift of three, so that a E in the plaintext becomes B in the ciphertext. In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence. The encryption step performed by a Caesar cipher is often incorporated as part of more complex schemes, such as the Vigenère cipher, and still has modern application in the ROT13 system. As with all single alphabet substitution ciphers, the Caesar cipher is easily broken and in modern practice offers essentially no communication security. 7
  • 8. 5.1.1. ADVANTAGE 1. Replace each letter l with l +3 mod 26 5.1.1. DISADVANTAGES 1. Algorithm: Shift characters by a fixed amount 2. Key: the fixed amount. 3. Knowing the algorithm (but not the key) makes this cipher much easier to crack 26 possibilities vs. 26! 4. Word structure is preserved. 5. An attacker that knows the block size can separate out characters encoded with different keys. 6. Key length is shorter than the message. 8
  • 9. 5.2. RAIL FENCE TECHNIQUE Rail Fence Cipher (also called a zigzag cipher) generally refers to a form of transposition cipher. It derives its name from the way in which it is encoded. In the rail fence cipher, the plaintext is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. When we reach the top rail, the message is written downwards again until the whole plaintext is written out. The message is then read off in rows. For example, if we have 3 "rails" and a message of 'WE ARE DISCOVERED. FLEE AT ONCE', the cipherer writes out: T . . . I . . . M . . . R . . . J . . . . H . S . S . Y . A . O . P . O . E . T . . I . . . M . . . J . . . R . . . C . Then reads off to get the ciphertext: TIMRJ HSSYA OPOET IMJRC 9
  • 10. 5.2.1. ADVANTAGE 1. The advantage of the Rail Fence cipher over other transposition ciphers like the sawtooth cipher is that there is a variable distance between consecutive letters. What we mean by variable distance is that the letters need not be arranged in fixed vertical columns that descends, but it can also be arranged in a zig zag manner. Therefore, this increases the difficulty of cracking the code. 2. As we can see, the rail fence cipher is being decrypted by reading it in arranging it in columns or rows before reading it. therefore, it is quite a easy and fast process, and it is less prone to mistakes. 5.2.1. DISADVANTAGE 1. One of the problems that the rail fence cipher face is that the security of the code is dependent on the fact that a cryptanalyst does not know the method of encryption. Hence, once the method of encryption is broken, the code is broken already. 2. Another problem with the rail fence cipher is that is not very strong. This means that the number of possible solutions are so small that a cryptanalyst can try them all by hand. Therefore, the rail fence cipher is very easy to break as we only have to test all the possible divisors up to half the length of the text. 10
  • 11. 5.3. VERNAM CIPHER In cryptography, the one-time pad (OTP) is a type of encryption which has been proven to be impossible to crack if used correctly. Each bit or character from the plaintext is encrypted by a modular addition with a bit or character from a secret random key (or pad) of the same length as the plaintext, resulting in a ciphertext. If the key is truly random, as large as or greater than the plaintext, never reused in whole or part, and kept secret, the ciphertext will be impossible to decrypt or break without knowing the key. It has also been proven that any cipher with the perfect secrecy property must use keys with effectively the same requirements as OTP keys. However, practical problems have prevented one-time pads from being widely used. Example: SENDING ------- message: 0 0 1 0 1 1 0 1 0 1 1 1 ... pad: 1 0 0 1 1 1 0 0 1 0 1 1 ... XOR ------------------------------------------ cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ... RECEIVING --------- cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ... pad: 1 0 0 1 1 1 0 0 1 0 1 1 ... XOR ---------------------------------------- message: 0 0 1 0 1 1 0 1 0 1 1 1 ... This cipher is unbreakable in a very strong sense. The intuition is that any message can be transformed into any cipher (of the same length) by a pad, and all transformations are equally likely. Given a two letter message, there is a pad which adds to the message to give OK, and another pad which adds to the message to give NO. Since either of these pads are equally likely, the message is equally likely to be OK or NO. 11
  • 12. 5.3.1. ADVANTAGE 1. Theoretically unbreakable. 2. Attacker can do no better than guessing. 3. Ciphertext gives no information about plaintext. 5.3.1. DISADVANTAGE 1. The key is as long as the message, this doubles the amount of data. 2. The key must be known by sender and receiver; the key must be transmitted somehow to the receiver and then we have the same problem, because it makes no difference whether to send the message or the key (It is very difficult to produce big amounts of truly random keys). 12
  • 13. 5.4. AES (ADVANCED ENCRYPTION STANDARD) The Advanced Encryption Standard (AES) is an encryption algorithm for securing sensitive but unclassified material by U.S. Government agencies and, as a likely consequence, may eventually become the de facto encryption standard for commercial transactions in the private sector. (Encryption for the US military and other classified communications is handled by separate, secret algorithms.) AES is based on a design principle known as a substitution-permutation network, and is fast in both software and hardware. Unlike its predecessor DES, AES does not use a Feistel network. AES is a variant of Rijndael which has a fixed block size of 128 bits, and a key size of 128, 192, or 256 bits. By contrast, the Rijndael specification per se is specified with block and key sizes that may be any multiple of 32 bits, both with a minimum of 128 and a maximum of 256 bits. AES operates on a 4×4 column-major order matrix of bytes, termed the state, although some versions of Rijndael have a larger block size and have additional columns in the state. Most AES calculations are done in a special finite field. The key size used for an AES cipher specifies the number of repetitions of transformation rounds that convert the input, called the plaintext, into the final output, called the ciphertext. The number of cycles of repetition are as follows: • 10 cycles of repetition for 128-bit keys. • 12 cycles of repetition for 192-bit keys. • 14 cycles of repetition for 256-bit keys. Each round consists of several processing steps, including one that depends on the encryption key itself. A set of reverse rounds are applied to transform ciphertext back into the original plaintext using the same encryption key. 13
  • 14. 5.4.1. ADVANTAGE 1. Advanced Encryption Standard not only assures security but also improves the performance in a variety of settings such as smartcards, hardware implementations etc. 2. AES is federal information processing standard and there are currently no known non-brute-force direct attacks against AES. 3. AES is strong enough to be certified for use by the US government for top secret information 4. High efficiency ,not complex ,high secure. 5.4.1 DISADVANTAGE 1. It need more processing. 2. It require more rounds of communication as compare to DES. 14
  • 15. 5.5. DES (DATA ENCRYPTIONE STANDARD) The Data Encryption Standard is a previously predominant algorithm for the encryption of electronic data. It was highly influential in the advancement of modern cryptography in the academic world. Developed in the early 1970s at IBM and based on an earlier design by Horst Feistel, the algorithm was submitted to the National Bureau of Standards (NBS) following the agency's invitation to propose a candidate for the protection of sensitive, unclassified electronic government data. In 1976, after consultation with the National Security Agency (NSA), the NBS eventually selected a slightly modified version, which was published as an official Federal Information Processing Standard (FIPS) for the United States in 1977. The publication of an NSA-approved encryption standard simultaneously resulted in its quick international adoption and widespread academic scrutiny. Controversies arose out of classified design elements, a relatively short key length of the symmetric-key block cipher design, and the involvement of the NSA, nourishing suspicions about a backdoor. The intense academic scrutiny the algorithm received over time led to the modern understanding of block ciphers and their cryptanalysis. Data Encryption Standard The Feistel function (F function) of DES 15
  • 16. 5.5.1. ADVANTAGE 1. It is a step-by-step rep. of a solution to a given problem ,which is very easy to understand 2. It has got a definite procedure. 3. It easy to first developed an algorithm, then convert it into a flowchart &then into a computer program. 4. It is independent of programming language. 5. It is easy to debug as every step is got its own logical sequence. 5.5.1. DISADVANTAGE 1. The 56-bit key size is the biggest defect of DES. Chips to perform one million of DES encrypt or decrypt operations a second are available (in 1993). A $1 million DES cracking machine can search the entire key space in about 7 hours. 2. Hardware implementations of DES are very fast; DES was not designed for software and hence runs relatively slowly. 16
  • 17. 6.MODIFIED ENCRYPTION TECHNIQUE After studying different techniques of encryption and decryption in symmetric key cryptography we found some disadvantage in every method. So, to reduce the disadvantage and make the data more secure from unauthorized user, we developed a new technique of encryption and decryption. In this technique we used three methods of encryption and decryption technique viz. Ceaser cipher , Rail fence, Vernam cipher. Sender can encrypt message by using any two mention methods and receiver can only decrypt the message by using the same methods in the same order. This can confuse any hacker that which two method is used from three and which one is used first. In our technique we used only advantage of the three technique used and tried to design a unique method which is more secure then any of the three individual method. Let us consider an example of encrypting a text message from our new technique. Plaintext: hello world 17
  • 18. Encrypted File Ciphertext: 3ifmmp olwrd1 Decrypted File 18
  • 19. 6.1. ADVANTAGE 1. More secure because ,more than one techniques used on a single file. 2. Attacker must know both the techniques as well as the keys to decrypt a file. 6.1. DISADVANTAGE 1. Very time consuming when implemented on large files. 19
  • 20. 7. WORKING CODE MODIFIED ENCRYPTION TECHNIQUE import java.awt.Dialog.ModalityType; import javax.swing.JFileChooser; import java.io.*; public class EncryptorDecriptor extends javax.swing.JFrame { /** Creates new form EncryptorDecriptor */ int flag=0; boolean r,v,ca,co,a,d; String indx,cip1,cip2,tech1="",tech2="",plainp1,plainp2, key1pwrd, key2pwrd,temp,ALPHABET = "abcdefghijklmnopqrstuvwxyz"; String dkey1="",dkey2=""; public EncryptorDecriptor() { initComponents(); } // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jTextField1 = new javax.swing.JTextField(); jd1 = new javax.swing.JDialog(); jLabel6 = new javax.swing.JLabel(); close_bttn1 = new javax.swing.JButton(); jd2 = new javax.swing.JDialog(); jLabel7 = new javax.swing.JLabel(); close_bttn2 = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); browse_tfield = new javax.swing.JTextField(); browse_bttn = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jSeparator2 = new javax.swing.JSeparator(); techDone_bttn = new javax.swing.JButton(); combox2 = new javax.swing.JComboBox(); combox1 = new javax.swing.JComboBox(); 20
  • 21. jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); info_label = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); keyDone_bttn1 = new javax.swing.JButton(); keyDone_bttn2 = new javax.swing.JButton(); info_label2 = new javax.swing.JLabel(); final_bttn = new javax.swing.JButton(); encryp_radio = new javax.swing.JRadioButton(); decryp_radio = new javax.swing.JRadioButton(); key1_tfield = new javax.swing.JTextField(); key2_tfield = new javax.swing.JTextField(); decrypt_ok = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jTextField1.setText("jTextField1"); jd1.setAlwaysOnTop(true); jd1.setBounds(new java.awt.Rectangle(225, 225, 400, 145)); jd1.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_M ODAL); jd1.setResizable(false); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel6.setText("FILE SUCCESSSFULLY ENCRYPTED!!!"); close_bttn1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N close_bttn1.setText("OK"); close_bttn1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { close_bttn1ActionPerformed(evt); } }); 21
  • 22. javax.swing.GroupLayout jd1Layout = new javax.swing.GroupLayout(jd1.getContentPane()); jd1.getContentPane().setLayout(jd1Layout); jd1Layout.setHorizontalGroup( jd1Layout.createParallelGroup(java x.swing.GroupLayout.Alignment.LEADING) .addGroup(jd1Layout.createSequentialGroup() .addGroup(jd1Layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(jd1Layout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)) .addGroup(jd1Layout.createSequentialGroup() .addGap(152, 152, 152) .addComponent(close_bttn1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); jd1Layout.setVerticalGroup( jd1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGroup(jd1Layout.createSequentialGroup() .addGap(41, 41, 41) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) 22
  • 23. .addComponent(close_bttn1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(38, Short.MAX_VALUE)) ); jd2.setBounds(new java.awt.Rectangle(225, 225, 400, 145)); jd2.setModal(true); jd2.setResizable(false); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel7.setText("FILE SUCCESSSFULLY DECRYPTED!!!"); close_bttn2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N close_bttn2.setText("OK"); close_bttn2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { close_bttn2ActionPerformed(evt); } }); javax.swing.GroupLayout jd2Layout = new javax.swing.GroupLayout(jd2.getContentPane()); jd2.getContentPane().setLayout(jd2Layout); jd2Layout.setHorizontalGroup( jd2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGroup(jd2Layout.createSequentialGroup() .addGroup(jd2Layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(jd2Layout.createSequentialGroup() .addGap(25, 25, 25) 23
  • 24. .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)) .addGroup(jd2Layout.createSequentialGroup() .addGap(155, 155, 155) .addComponent(close_bttn2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); jd2Layout.setVerticalGroup( jd2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGroup(jd2Layout.createSequentialGroup() .addGap(41, 41, 41) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) .addComponent(close_bttn2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(35, Short.MAX_VALUE)) ); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_C LOSE); browse_tfield.setEditable(false); browse_tfield.setFont(new java.awt.Font("Rod", 0, 11)); browse_tfield.setText("SELECT FILE TO BE ENCRYPTED"); browse_bttn.setFont(new java.awt.Font("Tahoma", 1, 11)); browse_bttn.setText("BROWSE"); 24
  • 25. browse_bttn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browse_bttnActionPerformed(evt); } }); jLabel1.setFont(new java.awt.Font("Verdana", 1, 12)); jLabel1.setText("CHOOSE ANY TWO ENCRYPTION TECHNIQUE"); techDone_bttn.setFont(new java.awt.Font("Tahoma", 1, 11)); techDone_bttn.setText("DONE"); techDone_bttn.setEnabled(false); techDone_bttn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { techDone_bttnActionPerformed(evt); } }); combox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RAIL FENCE", "VERNAM", "CAESAR" })); combox2.setEnabled(false); combox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RAIL FENCE", "VERNAM", "CAESAR" })); combox1.setEnabled(false); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabel2.setText("TECHNIQUE 1"); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabel3.setText("TECHNIQUE 2"); info_label.setForeground(new java.awt.Color(255, 51, 0)); 25
  • 26. jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabel4.setText("KEY 1 :"); jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabel5.setText("KEY 2 :"); keyDone_bttn1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N keyDone_bttn1.setText("DONE"); keyDone_bttn1.setEnabled(false); keyDone_bttn1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { keyDone_bttn1ActionPerformed(evt); } }); keyDone_bttn2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N keyDone_bttn2.setText("DONE"); keyDone_bttn2.setEnabled(false); keyDone_bttn2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { keyDone_bttn2ActionPerformed(evt); } }); info_label2.setForeground(new java.awt.Color(255, 51, 0)); final_bttn.setForeground(new java.awt.Color(255, 255, 255)); final_bttn.setBorder(null); final_bttn.setBorderPainted(false); final_bttn.setFocusPainted(false); final_bttn.setFocusable(false); final_bttn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final_bttnActionPerformed(evt); 26
  • 27. } }); encryp_radio.setFont(new java.awt.Font("Tahoma", 1, 11)); encryp_radio.setSelected(true); encryp_radio.setText("ENCRYPTION"); encryp_radio.setEnabled(false); encryp_radio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { encryp_radioActionPerformed(evt); } }); decryp_radio.setFont(new java.awt.Font("Tahoma", 1, 11)); decryp_radio.setText("DECRYPTION"); decryp_radio.setEnabled(false); decryp_radio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { decryp_radioActionPerformed(evt); } }); key1_tfield.setEnabled(false); key2_tfield.setEnabled(false); decrypt_ok.setText("Decrypt"); decrypt_ok.setEnabled(false); decrypt_ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { decrypt_okActionPerformed(evt); } }); jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N 27
  • 28. jLabel8.setText("FILE ENCRYPTER/DECRYPTER"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(browse_tfield, javax.swing.GroupLayout.PREFERRED_SIZE, 498, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(47, 47, 47) .addComponent(browse_bttn) .addGap(77, 77, 77)) .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE) .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(95, 95, 95) 28
  • 29. .addComponent(info_label, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED)) .addGroup(layout.createSequentialGroup() .addGap(36, 36, 36) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) .addComponent(combox1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED, 80, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(22, 22, 22))) .addComponent(combox2, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(30, 30, 30)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(111, 111, 111) .addComponent(encryp_radio) .addGap(227, 227, 227) .addComponent(decryp_radio))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) 29
  • 30. .addComponent(techDone_bttn, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(84, 84, 84)) .addGroup(layout.createSequentialGroup() .addGap(74, 74, 74) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.TRAILING) .addComponent(jLabel4) .addComponent(jLabel5)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.TRAILING) .addComponent(info_label2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE) .addComponent(key2_tfield, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE) .addComponent(key1_tfield, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)) .addGap(36, 36, 36) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.TRAILING, false) .addComponent(keyDone_bttn1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 30
  • 31. .addComponent(keyDone_bttn2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE) .addComponent(decrypt_ok, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(85, 85, 85) .addComponent(final_bttn, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(47, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(174, 174, 174) .addComponent(jLabel1) .addContainerGap(248, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(157, 157, 157) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(163, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.BASELINE) 31
  • 32. .addComponent(browse_tfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(browse_bttn)) .addGap(27, 27, 27) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.BASELINE) .addComponent(decryp_radio) .addComponent(encryp_radio)) .addGap(29, 29, 29) .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(combox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(techDone_bttn) .addComponent(combox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) 32
  • 33. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) .addComponent(info_label, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.BASELINE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(key1_tfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(keyDone_bttn1)) .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.BASELINE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(keyDone_bttn2) .addComponent(key2_tfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 33
  • 34. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.REL ATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(decrypt_ok) .addContainerGap()) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Align ment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(final_bttn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap(40, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGap(14, 14, 14) .addComponent(info_label2, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())))) ); pack(); }// </editor-fold> private void browse_bttnActionPerformed(java.awt.event.ActionEvent evt) { FChooser frame=new FChooser(); browse_tfield.setText(frame.FName); combox1.setEnabled(true); combox2.setEnabled(true); techDone_bttn.setEnabled(true); encryp_radio.setEnabled(true); decryp_radio.setEnabled(true); } 34
  • 35. private void techDone_bttnActionPerformed(java.awt.event.ActionEvent evt) { String c1=combox1.getSelectedItem().toString(); String c2=combox2.getSelectedItem().toString(); if(c1.equals(c2)){ info_label.setText("** MUST SELECT TWO DIFFERENT TECHNIQUES **"); } if(c1=="VERNAM" || c1=="CAESAR") {info_label.setText(""); key1_tfield.setEnabled(true); keyDone_bttn1.setEnabled(true); } if(c2=="VERNAM" || c2=="CAESAR") { info_label.setText(""); key2_tfield.setEnabled(true); keyDone_bttn2.setEnabled(true); info_label2.setText(""); } } private void keyDone_bttn1ActionPerformed(java.awt.event.ActionEvent evt) { String c1=combox1.getSelectedItem().toString(); String c2=combox2.getSelectedItem().toString(); int key1len=key1_tfield.getText().length(); if(key1len==0){ info_label2.setText("** MUST ENTER KEY 1 **"); } else if(key1len>0){ info_label2.setText(""); if(c2=="VERNAM" || c2=="CAESAR") { key2_tfield.setEnabled(true); keyDone_bttn2.setEnabled(true); 35
  • 36. } else if(c2!="VERNAM" || c2!="CAESAR"){ final_bttn.doClick(); } } } private void keyDone_bttn2ActionPerformed(java.awt.event.ActionEvent evt) { int key2len=key2_tfield.getText().length(); if(key2len==0){ info_label2.setText("** MUST ENTER KEY 2 **"); } else{ info_label2.setText(" "); final_bttn.doClick(); } } private void encryp_radioActionPerformed(java.awt.event.ActionEvent evt) { decryp_radio.setSelected(false); encryp_radio.setSelected(true); combox1.setEnabled(true); combox2.setEnabled(true); techDone_bttn.setEnabled(true); } private void decryp_radioActionPerformed(java.awt.event.ActionEvent evt) { encryp_radio.setSelected(false); decryp_radio.setSelected(true); combox1.setEnabled(false); combox2.setEnabled(false); techDone_bttn.setEnabled(false); key1_tfield.setEnabled(true); key2_tfield.setEnabled(true); decrypt_ok.setEnabled(true); 36
  • 37. } private void final_bttnActionPerformed(java.awt.event.ActionEvent evt) { boolean sel=encryp_radio.isSelected(); if(sel==true){ encryp(); } } private void decrypt_okActionPerformed(java.awt.event.ActionEvent evt) { decryp(); } private void close_bttn1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jd1.dispose(); } private void close_bttn2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jd2.dispose(); } void encryp() { try{ File file=new File(browse_tfield.getText()); int len=(int)file.length(); FileReader f=new FileReader(browse_tfield.getText()); FileWriter fw=new FileWriter("EncryptedFile.txt"); char data[]=new char[len]; int charsread=f.read(data); String txt=new String(data,0,charsread); int p1index=txt.length()/2; int p2index=p1index+1; 37
  • 38. String p1=txt.substring(0, p1index); String p2=txt.substring(p2index-1,txt.length()); String t1=combox1.getSelectedItem().toString(); String t2=combox2.getSelectedItem().toString(); if("RAIL FENCE".equals(t1)){ cip1=rail_encryp(p1); indx="1"; cip1=indx.concat(cip1); } else if( "VERNAM".equals(t1)){ indx="2"; String pwrd=key1_tfield.getText().toString(); cip1=vernam_encryp(p1,pwrd); cip1=indx.concat(cip1); } else if( "CAESAR".equals(t1)){ indx="3"; String pwrd=key1_tfield.getText().toString(); int password=Integer.parseInt(pwrd); cip1=caesar_encryp(p1,password); cip1=indx.concat(cip1); } if("RAIL FENCE".equals(t2)){ cip2=rail_encryp(p2); indx="1"; cip2=cip2.concat(indx); } else if( "VERNAM".equals(t2)){ indx="2"; String pwrd=key2_tfield.getText().toString(); cip2=vernam_encryp(p2,pwrd); cip2=cip2.concat(indx); } else if( "CAESAR".equals(t2)){ indx="3"; String pwrd=key2_tfield.getText().toString(); 38
  • 39. int password=Integer.parseInt(pwrd); cip2=caesar_encryp(p2,password); cip2=cip2.concat(indx); } String ciptxt=cip1.concat(cip2); fw.write(ciptxt); f.close(); fw.close(); keyDone_bttn2.setEnabled(false); keyDone_bttn1.setEnabled(false); jd1.setVisible(true); jd1.setPreferredSize(null); } catch(IOException e){} } void decryp(){ keyDone_bttn1.setEnabled(false); keyDone_bttn2.setEnabled(false); jd2.setVisible(true); jd2.setPreferredSize(null); try{ File file=new File(browse_tfield.getText()); int len=(int)file.length(); FileReader f=new FileReader(browse_tfield.getText()); String path="DecryptedFile.txt"; FileWriter fw=new FileWriter(path); char data[]=new char[len]; int charsread=f.read(data); String txt=new String(data,0,charsread); StringBuffer sb=new StringBuffer(txt); String ciphertxt=sb.substring(1,len-1); tech1=sb.substring(0,1); tech2=sb.substring(len-1,len); int p1index=ciphertxt.length()/2; int p2index=p1index+1; String p1=ciphertxt.substring(0, p1index); String p2=ciphertxt.substring(p2index-1,ciphertxt.length()); 39
  • 40. dkey1=key1_tfield.getText(); dkey2=key2_tfield.getText(); if(tech1.equals("1")){ plainp1=rail_decryp(p1); } else if(tech1.equals("2")){ plainp1=vernam_decryp(p1,dkey1); } else if(tech1.equals("3")){ plainp1=caesar_decryp(p1,dkey1); } if(tech2.equals("1")){ plainp2=rail_decryp(p2); } else if(tech2.equals("2")){ plainp2=vernam_decryp(p2,dkey2); } else if(tech2.equals("3")){ plainp2=caesar_decryp(p2,dkey2); } String pText=plainp1.concat(plainp2); fw.write(pText); f.close(); fw.close(); } catch(IOException e){} } String rail_encryp(String a){ String output = ""; int len = a.length(),flag = 0; for(int i=0;i<len;i+=2) { output += a.charAt(i); 40
  • 41. } for(int i=1;i<len;i+=2) { output += a.charAt(i); } return(output); } String vernam_encryp(String a,String p){ int j; String app=""; char[] arText = a.toCharArray(); char[] arCipher = p.toCharArray(); char[] encoded = new char[arText.length]; for (int i = 0; i < arText.length; i++) { j=i; if(j>p.length()-1){ j = 0; } encoded[i] = (char) (arText[i] ^ arCipher[j]); app += encoded[i]; } return(app); } String caesar_encryp(String a,int p){ { String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY Z"; String cipherText=""; for(int i=0;i<a.length();i++) { char character=a.charAt(i); String str=String.valueOf(character); if(str.equals(" ")){ 41
  • 42. char replaceVal = '&'; cipherText += replaceVal; } else if(str.equals(".")){ cipherText +="."; } else{ int charPosition = ALPHABET.indexOf(a.charAt(i)); int keyVal = (p+charPosition)%52; char replaceVal = ALPHABET.charAt(keyVal); cipherText += replaceVal; } } return(cipherText); } } String rail_decryp(String p){ String outputdec = ""; char[] str=p.toCharArray(); int len = p.length(),flag = 0,i,j=0; char[] out=new char[len]; if(len%2==0){ int mid=len/2; for(i=0;i<len;i++){ if(i%2==0){ out[i]=str[j]; j += 1; outputdec += out[i]; } else{ out[i]=str[mid]; mid += 1; outputdec += out[i]; } } } 42
  • 43. else if(len%2!=0) { int mid=(len/2)+1; for(i=0;i<len;i++){ if(i%2==0){ out[i]=str[j]; j += 1; outputdec += out[i]; } else{ out[i]=str[mid]; mid += 1; outputdec += out[i]; } } } return(outputdec); } String vernam_decryp(String text,String cipher){ int j=0; String app=""; char[] arText =text.toCharArray(); char[] arCipher = cipher.toCharArray(); char[] decoded = new char[arText.length]; for (int i = 0; i < text.length(); i++) { j=i; if(j>cipher.length()-1){ j=0; } decoded[i] = (char) (arText[i] ^ arCipher[j]); app +=decoded[i]; } return(app); } String caesar_decryp(String p,String k){ 43
  • 44. String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY Z"; int shiftKey=Integer.parseInt(k); String plainText=""; for(int i=0;i<p.length();i++) { char character=p.charAt(i); String str=String.valueOf(character); if(str.equals("&")){ char replaceVal = ' '; plainText += replaceVal; } else if(str.equals(".")){ plainText +="."; } else{ int charPosition = ALPHABET.indexOf(p.charAt(i)); int keyVal = (charPosition-shiftKey)%52; if(keyVal<0) { keyVal = ALPHABET.length() + keyVal; } char replaceVal = ALPHABET.charAt(keyVal); plainText += replaceVal; }} return(plainText); } public static void main(String args[]) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new EncryptorDecriptor().setVisible(true); } }); 44
  • 45. } // Variables declaration - do not modify public javax.swing.JButton browse_bttn; public javax.swing.JTextField browse_tfield; public javax.swing.JButton close_bttn1; public javax.swing.JButton close_bttn2; public javax.swing.JComboBox combox1; public javax.swing.JComboBox combox2; public javax.swing.JRadioButton decryp_radio; public javax.swing.JButton decrypt_ok; public javax.swing.JRadioButton encryp_radio; public javax.swing.JButton final_bttn; public javax.swing.JLabel info_label; public javax.swing.JLabel info_label2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JTextField jTextField1; public javax.swing.JDialog jd1; public javax.swing.JDialog jd2; public javax.swing.JTextField key1_tfield; public javax.swing.JTextField key2_tfield; public javax.swing.JButton keyDone_bttn1; public javax.swing.JButton keyDone_bttn2; public javax.swing.JButton techDone_bttn; // End of variables declaration } class FChooser extends javax.swing.JFrame{ JFileChooser chooser; 45
  • 46. String FName; public FChooser(){ chooser=new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int r=chooser.showOpenDialog(new javax.swing.JFrame()); if(r==JFileChooser.APPROVE_OPTION){ FName=chooser.getSelectedFile().getPath(); } } } 46
  • 49. 8. FUTURE SCOPE We used two techniques in our new method to encrypt and decrypt message and provide security. In future this can be done by using five or more encryption techniques of cryptography. We tried this technique to encrypt and decrypt different message and found that in case of large massage it is time consuming. But in our point of view, in case of small message this is the best way to provide security. We are working on it to minimize the time taking disadvantage so that it can be used for encryption of large message as well. 49
  • 50. 9. CONCLUSION We have proposed a method for implementing symmetric key cryptosystem whose security rests in part on the difficulty of encrypting/ decrypting with two different techniques. If the security of our method proves to be adequate, it permits secure communications to be established without the use of secure channels to carry keys. The security of this system needs to be examined in more detail. Using three or more techniques of cryptography makes the data more secure rather than using two techniques. Once the method has withstood all attacks for sufficient length of time it may be used with a reasonable amount of confidence. 50
  • 51. 10. BIBLIOGRAPHY Websites: 1. www.google.com 2. www.DreamInCode.com 3. www.stackoverflow.com 4. www.killthecode.com Books: 1. CRYPTORGAPHY AND NETWORK SECURITY by Atul Kahate 2. CRYPTORGAPHY AND NETWORK SECURITY by B.A. Forouzan 3. JAVA 6 PROGRAMMING BLACK BOOK 51