Symmetric Cryptography Using Nural Networks
Symmetric Cryptography Using Nural Networks
Symmetric Cryptography Using Nural Networks
MASTER OF TECHNOLOGY
(Computer Science & Engineering)
Submitted
By
Abstract:
Cryptography is a skill of sending the data in such a form that only those for whom it is
intended can read it. There are number of methods to perform cryptography, one of such method
is Neural Cryptography.
Neural Cryptography is an emergent field that aims to combine cryptography with Neural
Networks for applications in cryptanalysis and encryption. In this paper,I show Neural Networks
is capable of performing symmetric encryption in an adversarial setting and improve on the
known literature on this topic. I also show that Neural Networks is capable of detecting known
cryptographically insecure communication.
Introduction:
Symmetric encryption is a form of encryption in which the sender and receiver use the
same key to encrypt a plaintext and decrypt the corresponding cipher text. Traditionally,
symmetric encryption algorithms have used either block or stream ciphers. However, it has been
demonstrated that in a system of neural networks, with end-to-end adversarial training, they can
learn how to perform forms of ‘encryption’ and ‘decryption’ without the use of a specific
cryptographic algorithm.
The parity machine (PM) is a neural network applied in cryptography to generate a secret
key. It is also used for a key exchange protocol. The TPM network is in fact an FNN that has
input layer neurons constructed in the McCulloh-Pitts model (Protić, 2015), (Dolecki and
Kozera, 2015). In the second layer, the network has neurons with specific activation functions.
The outcome of the output neuron is the results of the entire PM network. Each PM network is
described by three parameters: the number of hidden neurons - K, the number of input neurons
connected to each hidden neuron - N, and the maximum value for weight {-L, ... L}. A PM
consists of KN random input elements xji = ±1, j = 1…N, K binary hidden units σi = ±1, i =
1,…, K, and one binary output unit τ=Πiσi, where σi is determined via the function σi =
sign(Σjwjixji). A PM that has three neurons in the hidden layer (K=3) is called the three parity
machine.
The advantage of neural cryptography is that the algorithm used in generating a secret
key can be a simple perception of the Tree Parity Machine (TPM). Synchronization of TPMs by
mutual learning only works if both machines receive a common sequence of (random) input
vectors. For that purpose, each communication party uses a separate, but identical pseudo-
random number generator (PRNG). By mutual learning, two parties synchronize their networks
without transmitting inputs over a public channel. Having reached full synchronization, parties
can authenticate each other by knowing weight vectors which are identical, and represent a secret
key.
Conclusion:
In the last decade, mutual learning based on the parity machine has become popular to be
used for cryptography. In this paper, a three parity machine that is a special type of a feed
forward neural network with three artificial neurons in the hidden layer, one output neuron and
KN input elements is presented. Inputs to the network are binary numbers, while the weights
between inputs and hidden neurons take predefined values. The output of the hidden neuron is
calculated as a weighted sum of all multiplications of inputs and weights. If the scalar product is
zero, the output of the hidden neuron is mapped to -1, otherwise it is mapped to 1, in order to
ensure a binary output from the network. The output bit of the network is a product of the three
bits of the hidden units. Mutual learning is used for synchronization between two parties that
communicate across a public or private channel. During the synchronization, both
communication parties use the same tree parity machines, receive common binary inputs
generated randomly from the same random number generator, and exchange output bits.
Adjusting the weights according to the learning rules leads to full synchronization in a finite
number of steps. Networks trained on their mutual inputs synchronize to an identical time
dependant weight vectors. This phenomenon is used to generate a secret key.
System Configuration:-
H/W System Configuration:-
Language : JAVA
JDK : JDK 8
EXISTING SYSTEM:
The basic need to provide security is using cryptography. Cryptosystem are commonly
used for protecting the integrity, confidentiality, and authenticity of information resources. The
design of cryptography algorithm is complicated by the fact that a variety of cryptanalytic attacks
are available that can often be successfully used to recover the key or the plaintext. Cryptography
has two style of encrypting data; symmetrical and asymmetrical. Symmetric encryptions use the
same key for encryption and decryption process, and also can be defined as a secret-key, shared-
key, and private-key. Asymmetric cryptography uses different encryption keys for encryption
and decryption process. In this case an end user on a network, public or private, has a pair of key;
one for encryption and one for decryption. These keys can be identical as a public and a private
key. Key generation is the most significant issue in cryptography technique. In recent times wide
ranges of techniques are developed to protect data and information from eavesdropper.
PROPOSED SYSTEM:
i. Two identical dynamic systems, starting from different initial condition can be
synchronized by a common external signal which is coupled to the two systems. Two networks
which are trained on their mutual output can synchronize to a time dependent state of identical
synaptic weights. ii. This phenomenon is also applied to cryptography. Neural networks learn
from examples. Training means, that synaptic weights adopt by simple rules to the input/output
pairs. After the training phase the neural network is able to generalize: it can classify the input
pattern which does not belong to the training set. iii. The two patterns A and B do not have to
share the common secret key but use their identical weights as a secret key need for encryption.
iv. In neural network an attacker E who knows all the details of the algorithm and record any
communication transmitted through this channel finds it difficult to synchronize with the parties,
and hence to calculate the common secret key.
2. Neural Key Exchange: The most used protocol for key exchange between two parties A and
B in the practice is Diffie-Hellman protocol. Neural key exchange, which is based on the
synchronization of two tree parity machine, should be a secure replacement.
3. Tree Parity Machine is special type of multi-layer feed-forward neural network. It consist of
one output neuron, K hidden neurons and K*N input neurons. Inputs to the networks take 3
values: xij∈ −1,0,1 The weights between input and hidden neurons take the values: wij∈ −𝐿, …
,0, … . , +𝐿 Output values of each hidden neurons is calculated as a sum of all multiplication of
input neurons and these weights: 𝜎𝑖 = ( 𝑥𝑖𝑗 𝑁 𝑗=1 ) Sig num is a simple function, which returns -
1,0 or 1: Sgn (x)= −1 𝑖𝑓 𝑥 < 0, 0 𝑖𝑓 𝑥 = 0, 1 𝑖𝑓 𝑥 > 0. If the scalar product is 0, the output of the
hidden neuron is mapped to -1 in order to ensure a binary output values. The output of neural
network is then computed as the multiplication of all values produced by hidden elements: 𝜏 = 𝜎𝑖
𝐾 𝑖=1 Output of the tree parity machine is binary. 4. Secret Key Generation The different stages
in the secret key generation procedure which is based on neural networks can be stated as
follows: 1. Determination of neural network parameter: K the number of hidden layers units, n
the input layer units for each hidden layer unit, l the range of synaptic weight values is done by
the two machine A and B. 2. The network weight to be initialized randomly. 3. The following
steps are repeated until synchronization occurs. 4. Inputs are generated by the third party (key
distribution center). 5. The inputs of the hidden units are calculated. 6. The output bit is
generated and exchange between the two machine A and B. 7. If the output vectors of both the
machine agree with each other then the corresponding weights are modified using the learning
rules. 8. When synchronization is finally occurred, the synaptic weights are same for both the
networks. And these weights are used as secret key.
1. INTRODUCTION
other words people have to be assured that the information to be read by only the sender and
receiver. The basic need to provide security is using cryptography. Cryptosystem are
commonly used for protecting the integrity, confidentiality, and authenticity of information
resources. The design of cryptography algorithm is complicated by the fact that a variety of
cryptanalytic attacks are available that can often be successfully used to recover the key or the
plaintext. Cryptography has two style of encrypting data; symmetrical and asymmetrical.
Symmetric encryptions use the same key for encryption and decryption process, and also can
different encryption keys for encryption and decryption process. In this case an end user on a
network, public or private, has a pair of key; one for encryption and one for decryption. These
keys can be identical as a public and a private key. Key generation is the most significant
issue in cryptography technique. In recent times wide ranges of techniques are developed to
protect data and information from eavesdropper. These algorithms have their virtue and
shortcomings. A neural network based approach offers an attractive solution to this problem
in that it provides a suitable framework within which data can be readily code. Neural
networks are non linear statistical data modeling tools. They can be used to model complex
relationship between inputs and outputs or to find patterns in data. A phenomenon of neural
networks is applied in cryptography system. This is used for generating secret key.
cryptography. The model has multi-layer feed-forward neural network which have two tree
parity machine (TPM) that synchronized with a random initial weight act as common secret
key for the encryption and decryption process. The weight can be updated according to the
learning rules only if the output values of the two machines are equal. Throughout the
synchronization process, only the input vectors and the output vectors are transmitted over the
public channel. This paper [3] presented a new modification of the Advanced Encryption
Standard to be immune against some attacks using non linear neural network. The neural
network model performs cryptography processes via a symmetric key cipher that used as the
initial weights for the neural network which trained to its final weight fast and low cost
algorithm. The objective form the network has been selected to equivalent the output of the
AES that have an efficient and recommended security. Simulation results show the proximity
of the result accomplished by the proposed NN-based AES cryptosystem with that of the
normal AES.
This paper [4] proposed multi-layer neural networks in cryptography. The multilayer
propagation. The planned model converted the input message into ASCII code then gets the
sequence of bits for each code which divides into 6 bit blocks are used as input for the
encryption process. The cipher key is the neural network structure contained input layer,
hidden layer, output layer, and updated weights. Experimental results show that the system is
secure. This paper [5] proposed a secret key using neural cryptography, based on
synchronization of Tree Parity Machine (TPMs) by mutual learning. The system has two
identical dynamical system, which starting from different initial conditions and synchronized
by a common input values which are coupled to the two system. The networks received a
common input vector after calculating their output and updated their weight vector according
to the match between their mutual outputs in every time step. The input and output relations
are not exchanged through a public channel until their weight vectors are matched and can be
used as a secret key for encryption and decryption of secret message. The weight vectors of
the two neural networks begin with random number, which are generated by Pseudo-Random
Number Generator (PRNGs). The proposed model fixed the security against numerical
attacks. This paper [6] proposed a secret key over a public channel using artificial neural
network. The artificial neural network contains of two multi layer neural networks trained on
their mutual output bits and able to synchronize. The two network starting from random initial
weights and learning from each other with two multilayer networks relax to the state with
time dependent identical synaptic weights. The partners didn’t exchange any information over
considered as the key generation in cryptography. The common identical weights of the two
partners can be used as a key for key generation over public channels which are not based on
number theory. Experimental result shows that the model is fast, simple, and secure. This
paper [7] presented a secured cryptography secret-key based on neural network in a public
channel. The proposed model has two neural network that are trained on their alternative
synchronization system that starting from different initial condition. The system combined the
neural network with the logistic chaotic map. The both partners used their neural networks as
input for the logistic maps which generated the output bits to be learned, by mutually learning.
The two neural networks approach each other and generated a matching signal to the chaotic
maps. The chaotic synchronization applied in the neural cryptography enhanced the
neural cryptography has two communication networks that received an identical input vector,
generated an output bit and are trained based on output bit. The network model initials the
weight randomly and the outputs bit are generated finally and exchange between partners. The
weight may be modified if the outputs of both partners are matched. The modified weight
after synchronize act as a secret key for the encryption and decryption process. Simulation
results show that the cryptosystem based on ANNs is secure. In this paper [9] a secret key is
generated over a public channel based on neural network. The model has a neural network
machine contains of two partners started with initial weights and different initial condition
which synchronized by a common external signal and received a common random input
vector and learned their mutual output bits. The synaptic weights are used as a secret key over
a pubic channel. Simulation results show that the model are secure and efficiency.
2. SYSTEM STUDY
The feasibility of the project is analyzed in this phase and business proposal is put forth
with a very general plan for the project and some cost estimates. During system analysis the
feasibility study of the proposed system is to be carried out. This is to ensure that the
proposed system is not a burden to the company. For feasibility analysis, some understanding
ECONOMICAL FEASIBILITY
TECHNICAL FEASIBILITY
SOCIAL FEASIBILITY
ECONOMICAL FEASIBILITY:
This study is carried out to check the economic impact that the system will have on the
organization. The amount of fund that the company can pour into the research and development
of the system is limited. The expenditures must be justified. Thus the developed system as well
within the budget and this was achieved because most of the technologies used are freely
TECHNICAL FEASIBILITY:
This study is carried out to check the technical feasibility, that is, the technical
requirements of the system. Any system developed must not have a high demand on the available
technical resources. This will lead to high demands on the available technical resources. This
will lead to high demands being placed on the client. The developed system must have a modest
requirement, as only minimal or null changes are required for implementing this system.
SOCIAL FEASIBILITY:
The aspect of study is to check the level of acceptance of the system by the user. This
includes the process of training the user to use the system efficiently. The user must not feel
threatened by the system, instead must accept it as a necessity. The level of acceptance by the
users solely depends on the methods that are employed to educate the user about the system and
to make him familiar with it. His level of confidence must be raised so that he is also able to
make some constructive criticism, which is welcomed, as he is the final user of the system.
3. SYSTEM DESIGN
INTRODUCTION TO UML:
Unified Modeling Language is the one of the most exciting tools in the world of system
development today. Because UML enables system builders to create blue prints that capture their
visions in a standard, easy to understand way and communicate them to others. The UML is
brain child of Grady Brooch, James Rumbaugh and Ivar Jacobson.
1 Visualizing
2 Specifying
3 Constructing
4 Documenting
These are the artifacts of a software-intensive system.The abbreviation for UML is Unified
Modeling Language and is being brought of a designed to make sure that the existing ER
Diagrams which do not serve the purpose will be replaced by this UML Diagrams where in these
language as its own set of Diagrams.
Some of the Diagrams that help for the Diagrammatic Approach for the Object Oriented
Software Engineering are
Class Diagrams
Use Case Diagrams
Sequence Diagrams
State Chart Diagrams
Activity Diagrams
Using the above mentioned diagrams we can show the entire system regarding the working of
the system or the flow of control and sequence of flow the state of the system and the activities
involved in the system.
3.2.1. Components of the UML:
The UML consists of a number of graphical elements that combine to form diagrams.
Because it’s a language, the UML has rules for combining these elements. The purpose of the
diagrams to present multiple views of the system, and this set of multiple views is called a
Model. A UML Model of a system is something like a scale model of a building. UML model
describes what a system is supposed to do. It doesn’t tell how to implement the system. The
following are the main nine component Diagrams of U M L:
A Class is a category or group of things that has similar attributes and common behavior. A
Rectangle is the icon that represents the class it is divided into three areas. The upper most area
contains the name, the middle area contains the attributes and the lowest areas show the
operations. Class diagrams provides the representation that developers work from. Class
diagrams help on the analysis side, too.
An object is an instance of a class- A specific thing that has specific values of the attributes
and behavior. A Rectangle is the icon that represents the object diagram but the name is
underlined. The name of the specific instance is on the left side of the colon, and the name of the
class is on the right side of the colon.
A Use-Case is a description of a systems behavior from a users stand point. For system
developer this is a valuable tool: it’s a tried-and-true technique for gathering system
requirements from a users point of view. That is important if the goal is to build a system that
real people can use. A little stick figure is used to identify an actor the ellipse represents use-
case.
3.2.5 State Diagram:
At any given time, an object is in particular state. One way to characterize change in a system
is to say that its objects change the state in response to events and to time. The UML State
Diagram captures this kinds of changes it presents the states an object can be in along with the
transitions between the states, and shows the starting point and end point of a sequence of state
changes.
A Rounded Rectangle represents a state, along with the solid line and arrow head that
represents a transition. The arrow head points to the state being transition into. The solid circle
symbolizes starting point and the bulls eye that symbolizes the end point.
In a functioning system objects interacts with one another and these interactions occur over
time. The UML Sequence Diagrams shows the time based dynamics of the interaction. The
sequence diagrams consists of objects represented in the usual way-as named rectangles (If the
name underlined), messages represented as solid line arrows and time represented as a vertical
progression.
The state diagram shows the states of an object and represents activities as arrows connecting
the states. The Activity Diagram highlights the activities. Each activity is represented by a
rounded rectangle-narrower and more oval-shaped than the state icon. An arrow represents the
transition from the one activity to the next. The activity diagram has a starting point represented
by filled-in circle, and an end point represented by bulls eye.
3.2.8Collaboration Diagram:
An object diagram shows the objects and their relationships with one another. A collaboration
Diagram is an extension of the object diagram. In addition to the associations among objects, the
collaboration diagram shows the messages the objects and each other.
3.3 Use cases:
The functional model, represented in UML with use case diagrams, describes the
functionality of the system from the user’s point of view. Use cases are used during
requirements elicitation and analysis to represent the functionality of the system. A use
case describes a function provided by the system that yields a visible result for an actor.
An actor describes any entity that interacts with the system. An actor can be human or an
external system. In this proposed system actors are Administrator, Manager, Technical person
and Customer.
Use cases consist of elements that lie inside the system and are responsible for the working
i.e. the functionality and behavior of the system. Therefore, use cases are nothing but the actions
that the system performs to generate results requested by the actors of the system.
Kinds of classifiers:
4.3.1 USE CASE DIAGRAMS:
UML provides the use case diagram to facilitate the process of requirements gathering. The
Use case diagram models the interactions between the system’s external clients and the use cases
of the system. Each use case represents a different capability that the system provides the client.
Stick figure represents an actor.
UML DAIGRAMS:
ACTIVITY DIAGRAM:
Key is generated
Java Technology
Simple
Architecture neutral
Object oriented
Portable
Distributed
High performance
Interpreted
Multithreaded
Robust
Dynamic
Secure
With most programming languages, you either compile or interpret a program so that
you can run it on your computer. The Java programming language is unusual in that a
program is both compiled and interpreted. With the compiler, first you translate a program
into an intermediate language called Java byte codes —the platform-independent codes
interpreted by the interpreter on the Java platform. The interpreter parses and runs each Java
byte code instruction on the computer. Compilation happens just once; interpretation occurs
each time the program is executed. The following figure illustrates how this works.
You can think of Java byte codes as the machine code instructions for the Java Virtual
Machine (Java VM). Every Java interpreter, whether it’s a development tool or a Web browser
that can run applets, is an implementation of the Java VM. Java byte codes help make “write
once, run anywhere” possible. You can compile your program into byte codes on any platform
that has a Java compiler. The byte codes can then be run on any implementation of the Java VM.
That means that as long as a computer has a Java VM, the same program written in the Java
programming language can run on Windows 2000, a Solaris workstation, or on an iMac.
The Java Platform
A platform is the hardware or software environment in which a program runs.
We’ve already mentioned some of the most popular platforms like Windows 2000,
Linux, Solaris, and MacOS. Most platforms can be described as a combination of the
operating system and hardware. The Java platform differs from most other platforms in
that it’s a software-only platform that runs on top of other hardware-based platforms.
The Java API is a large collection of ready-made software components that provide
many useful capabilities, such as graphical user interface (GUI) widgets. The Java API is
grouped into libraries of related classes and interfaces; these libraries are known as
packages. The next section, What Can Java Technology Do? Highlights what
functionality some of the packages in the Java API provide.
The following figure depicts a program that’s running on the Java platform. As the
figure shows, the Java API and the virtual machine insulate the program from the
hardware.
Native code is code that after you compile it, the compiled code
runs on a specific hardware platform. As a platform-independent
environment, the Java platform can be a bit slower than native code.
However, smart compilers, well-tuned interpreters, and just-in-time
byte code compilers can bring performance close to that of native code
without threatening portability.
What Can Java Technology Do?
The most common types of programs written in the Java programming language are
applets and applications. If you’ve surfed the Web, you’re probably already familiar with
applets. An applet is a program that adheres to certain conventions that allow it to run
within a Java-enabled browser.
However, the Java programming language is not just for writing cute, entertaining applets
for the Web. The general-purpose, high-level Java programming language is also a
powerful software platform. Using the generous API, you can write many types of
programs.
An application is a standalone program that runs directly on the Java platform. A special
kind of application known as a server serves and supports clients on a network. Examples
of servers are Web servers, proxy servers, mail servers, and print servers. Another
specialized program is a servlet. A servlet can almost be thought of as an applet that runs
on the server side. Java Servlets are a popular choice for building interactive web
applications, replacing the use of CGI scripts. Servlets are similar to applets in that they
are runtime extensions of applications. Instead of working in browsers, though, servlets
run within Java Web servers, configuring or tailoring the server.
How does the API support all these kinds of programs? It does so with packages of
software components that provides a wide range of functionality. Every full
implementation of the Java platform gives you the following features:
The essentials: Objects, strings, threads, numbers, input and output, data
structures, system properties, date and time, and so on.
Applets: The set of conventions used by applets.
Networking: URLs, TCP (Transmission Control Protocol), UDP (User Data gram
Protocol) sockets, and IP (Internet Protocol) addresses.
Internationalization: Help for writing programs that can be localized for users
worldwide. Programs can automatically adapt to specific locales and be displayed
in the appropriate language.
Security: Both low level and high level, including electronic signatures, public
and private key management, access control, and certificates.
Software components: Known as JavaBeansTM, can plug into existing
component architectures.
Object serialization: Allows lightweight persistence and communication via
Remote Method Invocation (RMI).
Java Database Connectivity (JDBCTM): Provides uniform access to a wide
range of relational databases.
The Java platform also has APIs for 2D and 3D graphics, accessibility, servers,
collaboration, telephony, speech, animation, and more. The following figure depicts what
is included in the Java 2 SDK.
How Will Java Technology Change My Life?
We can’t promise you fame, fortune, or even a job if you learn the Java
programming language. Still, it is likely to make your programs better and requires less effort
than other languages. We believe that Java technology will help you do the following:
AWT is also the GUI toolkit for a number of Java ME profiles. For example, Connected Device
Configuration profiles require Java runtimes on mobile telephones to support AWT.
Swing:
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes
(JFC) — an API for providing a graphical user interface (GUI) for Java programs.
Swing was developed to provide a more sophisticated set of GUI components than the earlier
Abstract Window Toolkit (AWT). Swing provides a native look and feel that emulates the look
and feel of several platforms, and also supports a pluggable look and feel that allows applications
to have a look and feel unrelated to the underlying platform. It has more powerful and flexible
components than AWT. In addition to familiar components such as buttons, check box and
labels, Swing provides several advanced components such as tabbed panel, scroll panes,
trees, tables and lists.
JPanel is Swing’s version of the AWT class Panel and uses the same default layout,
FlowLayout. JPanel is descended directly from JComponent.
· JFrame is Swing’s version of Frame and is descended directly from that class. The
components added to the frame are referred to as its contents; these are managed by the
contentPane. To add a component to a JFrame, we must use its contentPane instead.
· JWindow is Swing’s version of Window and is descended directly from that class. Like
Window, it uses BorderLayout by default.
· JDialog is Swing’s version of Dialog and is descended directly from that class. Like Dialog, it
uses BorderLayout by default. Like JFrame and JWindow,
JDialog contains a rootPane hierarchy including a contentPane, and it allows layered and glass
panes. All dialogs are modal, which means the current
thread is blocked until user interaction with it has been completed. JDialog class is intended as
the basis for creating custom dialogs; however, some
of the most common dialogs are provided through static methods in the class JOptionPane.
· The abstract class AbstractButton extends class JComponent and provides a foundation for a
family of button classes, including
JButton.
· JTextField allows editing of a single line of text. New features include the ability to justify the
text left, right, or center, and to set the text’s font.
· JPasswordField (a direct subclass of JTextField) you can suppress the display of input. Each
character entered can be replaced by an echo character.
This allows confidential input for passwords, for example. By default, the echo character is the
asterisk, *.
· JTextArea allows editing of multiple lines of text. JTextArea can be used in conjunction with
class JScrollPane to achieve scrolling. The underlying JScrollPane can be forced to always or
never have either the vertical or horizontal scrollbar;
JButton is a component the user clicks to trigger a specific action.
· JRadioButton is similar to JCheckbox, except for the default icon for each class. A set of
radio buttons can be associated as a group in which only
one button at a time can be selected.
· JCheckBox is not a member of a checkbox group. A checkbox can be selected and deselected,
and it also displays its current state.
· JComboBox is like a drop down box. You can click a drop-down arrow and select an option
from a list. For example, when the component has focus,
pressing a key that corresponds to the first character in some entry’s name selects that entry. A
vertical scrollbar is used for longer lists.
· JList provides a scrollable set of items from which one or more may be selected. JList can be
populated from an Array or Vector. JList does not
support scrolling directly, instead, the list must be associated with a scrollpane. The view port
used by the scroll pane can also have a user-defined
border. JList actions are handled using ListSelectionListener.
· JTabbedPane contains a tab that can have a tool tip and a mnemonic, and it can display both
text and an image.
· JToolbar contains a number of components whose type is usually some kind of button which
can also include separators to group related components
within the toolbar.
· FlowLayout when used arranges swing components from left to right until there’s no more
space available. Then it begins a new row below it and moves
from left to right again. Each component in a FlowLayout gets as much space as it needs and no
more.
· BorderLayout places swing components in the North, South, East, West and center of a
container. You can add horizontal and vertical gaps between
the areas.
· GridLayout is a layout manager that lays out a container’s components in a rectangular grid.
The container is divided into equal-sized rectangles,
and one component is placed in each rectangle.
· GridBagLayout is a layout manager that lays out a container’s components in a grid of cells
with each component occupying one or more cells,
called its display area. The display area aligns components vertically and horizontally, without
requiring that the components be of the same size.
· JMenubar can contain several JMenu’s. Each of the JMenu’s can contain a series of
JMenuItem ‘s that you can select. Swing provides support for
pull-down and popup menus. s
Scrollable JPopupMenu is a scrollable popup menu that can be used whenever we have
so many items in a popup menu that exceeds the screen visible height.
ODBC
Microsoft Open Database Connectivity (ODBC) is a standard programming interface
for application developers and database systems providers. Before ODBC became a de facto
standard for Windows programs to interface with database systems, programmers had to use
proprietary languages for each database they wanted to connect to. Now, ODBC has made
the choice of the database system almost irrelevant from a coding perspective, which is as it
should be. Application developers have much more important things to worry about than the
syntax that is needed to port their program from one database to another when business needs
suddenly change.
Through the ODBC Administrator in Control Panel, you can specify the particular
database that is associated with a data source that an ODBC application program is written to
use. Think of an ODBC data source as a door with a name on it. Each door will lead you to a
particular database. For example, the data source named Sales Figures might be a SQL
Server database, whereas the Accounts Payable data source could refer to an Access
database. The physical database referred to by a data source can reside anywhere on the
LAN.
The ODBC system files are not installed on your system by Windows 95. Rather, they
are installed when you setup a separate database application, such as SQL Server Client or
Visual Basic 4.0. When the ODBC icon is installed in Control Panel, it uses a file called
ODBCINST.DLL. It is also possible to administer your ODBC data sources through a stand-
alone program called ODBCADM.EXE. There is a 16-bit and a 32-bit version of this program
and each maintains a separate list of ODBC data sources.
From a programming perspective, the beauty of ODBC is that the application can be
written to use the same set of function calls to interface with any data source, regardless of
the database vendor. The source code of the application doesn’t change whether it talks to
Oracle or SQL Server. We only mention these two as an example. There are ODBC drivers
available for several dozen popular database systems. Even Excel spreadsheets and plain text
files can be turned into data sources. The operating system uses the Registry information
written by ODBC Administrator to determine which low-level ODBC drivers are needed to
talk to the data source (such as the interface to Oracle or SQL Server). The loading of the
ODBC drivers is transparent to the ODBC application program. In a client/server
environment, the ODBC API even handles many of the network issues for the application
programmer.
The advantages of this scheme are so numerous that you are probably thinking there
must be some catch. The only disadvantage of ODBC is that it isn’t as efficient as talking
directly to the native database interface. ODBC has had many detractors make the charge
that it is too slow. Microsoft has always claimed that the critical factor in performance is the
quality of the driver software that is used. In our humble opinion, this is true. The availability
of good ODBC drivers has improved a great deal recently. And anyway, the criticism about
performance is somewhat analogous to those who said that compilers would never match the
speed of pure assembly language. Maybe not, but the compiler (or ODBC) gives you the
opportunity to write cleaner programs, which means you finish sooner. Meanwhile,
computers get faster every year.
JDBC
In an effort to set an independent database standard API for Java; Sun Microsystems
developed Java Database Connectivity, or JDBC. JDBC offers a generic SQL database
access mechanism that provides a consistent interface to a variety of RDBMSs. This
consistent interface is achieved through the use of “plug-in” database connectivity modules,
or drivers. If a database vendor wishes to have JDBC support, he or she must provide the
driver for each platform that the database and Java run on.
To gain a wider acceptance of JDBC, Sun based JDBC’s framework on ODBC. As
you discovered earlier in this chapter, ODBC has widespread support on a variety of
platforms. Basing JDBC on ODBC will allow vendors to bring JDBC drivers to market much
faster than developing a completely new connectivity solution.
JDBC was announced in March of 1996. It was released for a 90 day public review
that ended June 8, 1996. Because of user input, the final JDBC v1.0 specification was
released soon after.
The remainder of this section will cover enough information about JDBC for you to know
what it is about and how to use it effectively. This is by no means a complete overview of
JDBC. That would fill an entire book.
JDBC Goals
Few software packages are designed without goals in mind. JDBC is one that,
because of its many goals, drove the development of the API. These goals, in conjunction
with early reviewer feedback, have finalized the JDBC class library into a solid framework
for building database applications in Java.
The goals that were set for JDBC are important. They will give you some insight as to
why certain classes and functionalities behave the way they do. The eight design goals for
JDBC are as follows:
2. SQL Conformance
SQL syntax varies as you move from database vendor to database vendor. In an effort to
support a wide variety of vendors, JDBC will allow any query statement to be passed through
it to the underlying database driver. This allows the connectivity module to handle non-
standard functionality in a manner that is suitable for its users.
5. Keep it simple
This goal probably appears in all software design goal listings. JDBC is no exception.
Sun felt that the design of JDBC should be very simple, allowing for only one method of
completing a task per mechanism. Allowing duplicate functionality only serves to confuse
the users of the API.
Simple Architecture-neutral
Object-oriented Portable
Distributed High-performance
Interpreted multithreaded
Robust Dynamic
Secure
Java is also unusual in that each Java program is both compiled and interpreted.
With a compile you translate a Java program into an intermediate language called
Java byte codes the platform-independent code instruction is passed and run on the
computer.
Compilation happens just once; interpretation occurs each time the program is
executed. The figure illustrates how this works.
Compilers My Program
You can think of Java byte codes as the machine code instructions for the Java
Virtual Machine (Java VM). Every Java interpreter, whether it’s a Java
development tool or a Web browser that can run Java applets, is an implementation
of the Java VM. The Java VM can also be implemented in hardware.
Java byte codes help make “write once, run anywhere” possible. You can
compile your Java program into byte codes on my platform that has a Java
compiler. The byte codes can then be run any implementation of the Java VM. For
example, the same Java program can run Windows NT, Solaris, and Macintosh.
5. SYSTEM TESTING
The purpose of testing is to discover errors. Testing is the process of trying to discover
every conceivable fault or weakness in a work product. It provides a way to check the
functionality of components, sub assemblies, assemblies and/or a finished product It is the
process of exercising software with the intent of ensuring that the
Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each test type addresses a specific testing
requirement.
TYPES OF TESTS
Unit testing:
Unit testing involves the design of test cases that validate that the internal program logic is
functioning properly, and that program inputs produce valid outputs. All decision branches and
internal code flow should be validated. It is the testing of individual software units of the
application .it is done after the completion of an individual unit before integration. This is a
structural testing, that relies on knowledge of its construction and is invasive. Unit tests perform
basic tests at component level and test a specific business process, application, and/or system
configuration. Unit tests ensure that each unique path of a business process performs accurately
to the documented specifications and contains clearly defined inputs and expected results.
Integration testing:
Integration tests are designed to test integrated software components to determine if they
actually run as one program. Testing is event driven and is more concerned with the basic
outcome of screens or fields. Integration tests demonstrate that although the components were
individually satisfaction, as shown by successfully unit testing, the combination of components is
correct and consistent. Integration testing is specifically aimed at exposing the problems that
arise from the combination of components.
Functional test:
Functional tests provide systematic demonstrations that functions tested are available as
specified by the business and technical requirements, system documentation, and user manuals.
System Test:
System testing ensures that the entire integrated software system meets requirements. It tests a
configuration to ensure known and predictable results. An example of system testing is the
configuration oriented system integration test. System testing is based on process descriptions
and flows, emphasizing pre-driven process links and integration points.
White Box Testing:
White Box Testing is a testing in which in which the software tester has knowledge of the
inner workings, structure and language of the software, or at least its purpose. It is purpose. It is
used to test areas that cannot be reached from a black box level.
Black Box Testing is testing the software without any knowledge of the inner workings,
structure or language of the module being tested. Black box tests, as most other kinds of tests,
must be written from a definitive source document, such as specification or requirements
document, such as specification or requirements document. It is a testing in which the software
under test is treated, as a black box .you cannot “see” into it. The test provides inputs and
responds to outputs without considering how the software works.
Unit testing is usually conducted as part of a combined code and unit test phase of the
software lifecycle, although it is not uncommon for coding and unit testing to be conducted as
two distinct phases.
Field testing will be performed manually and functional tests will be written in
detail.
1.
Test objectives
Features to be tested
The task of the integration test is to check that components or software applications, e.g.
components in a software system or – one step up – software applications at the company level –
interact without error.
Test Results: All the test cases mentioned above passed successfully. No defects encountered.
User Acceptance Testing is a critical phase of any project and requires significant
participation by the end user. It also ensures that the system meets the functional requirements.
Test Results: All the test cases mentioned above passed successfully. No defects encountered.
6.SAMPLE CODE
NeuralCrypt
Key.java
package neuralCrypt;
/**
*
* @author
*/
public class Key {
/* return a valid 32 bit key suitable for AES,Serpent,Twofish encryption algorithm */
public static String get32BitKey(String key) {
int length = key.length();
if (length < 32) {
StringBuilder outKey = new StringBuilder(key.toString());
int i = 0;
while (outKey.length() < 32) {
outKey.append(outKey.charAt(i));
i++;
}
return outKey.toString();
} else {
return (key.substring(0, 32));
}
}
}
NeuralCryptMain.java
package neuralCrypt;
@Override
public void run() {
new NeuralCryptMainPanel().setVisible(true);
}
});
}
}
WeightMatrix.java
package neuralCrypt;
import javax.swing.table.AbstractTableModel;
/**
* @descriptions
* A table for displaying the weight matrix in NCryptPanel table GUI
* just for displaying purpose only
* @author
*/
public class WeightMatrix extends AbstractTableModel {
private int row, col;
private Integer[][] data;
private String[] columnNames;
@Override
public int getRowCount() {
return row;
}
@Override
public int getColumnCount() {
return col;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex][columnIndex];
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
data[rowIndex][columnIndex] = (Integer) aValue;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public void fireTableDataChanged() {
super.fireTableDataChanged();
}
NeuralCrypt.cryptography
Base64Coder.java
package neuralCrypt.cryptography;
/**
* Encodes a string into Base64 format.
* No blanks or line breaks are inserted.
* @param s A String to be encoded.
* @return A String containing the Base64 encoded data.
*/
public static String encodeString (String s) {
return new String(encode(s.getBytes())); }
/**
* Encodes a byte array into Base 64 format and breaks the output into lines of 76
characters.
* This method is compatible with
<code>sun.misc.BASE64Encoder.encodeBuffer(byte[])</code>.
* @param in An array containing the data bytes to be encoded.
* @return A String containing the Base64 encoded data, broken into lines.
*/
public static String encodeLines (byte[] in) {
return encodeLines(in, 0, in.length, 76, systemLineSeparator); }
/**
* Encodes a byte array into Base 64 format and breaks the output into lines.
* @param in An array containing the data bytes to be encoded.
* @param iOff Offset of the first byte in <code>in</code> to be processed.
* @param iLen Number of bytes to be processed in <code>in</code>, starting at
<code>iOff</code>.
* @param lineLen Line length for the output data. Should be a multiple of 4.
* @param lineSeparator The line separator to be used to separate the output lines.
* @return A String containing the Base64 encoded data, broken into lines.
*/
public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String lineSeparator)
{
int blockLen = (lineLen*3) / 4;
if (blockLen <= 0) throw new IllegalArgumentException();
int lines = (iLen+blockLen-1) / blockLen;
int bufLen = ((iLen+2)/3)*4 + lines*lineSeparator.length();
StringBuilder buf = new StringBuilder(bufLen);
int ip = 0;
while (ip < iLen) {
int l = Math.min(iLen-ip, blockLen);
buf.append (encode(in, iOff+ip, l));
buf.append (lineSeparator);
ip += l; }
return buf.toString(); }
/**
* Encodes a byte array into Base64 format.
* No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @return A character array containing the Base64 encoded data.
*/
public static char[] encode (byte[] in) {
return encode(in, 0, in.length); }
/**
* Encodes a byte array into Base64 format.
* No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @param iLen Number of bytes to process in <code>in</code>.
* @return A character array containing the Base64 encoded data.
*/
public static char[] encode (byte[] in, int iLen) {
return encode(in, 0, iLen); }
/**
* Encodes a byte array into Base64 format.
* No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @param iOff Offset of the first byte in <code>in</code> to be processed.
* @param iLen Number of bytes to process in <code>in</code>, starting at
<code>iOff</code>.
* @return A character array containing the Base64 encoded data.
*/
public static char[] encode (byte[] in, int iOff, int iLen) {
int oDataLen = (iLen*4+2)/3; // output length without padding
int oLen = ((iLen+2)/3)*4; // output length including padding
char[] out = new char[oLen];
int ip = iOff;
int iEnd = iOff + iLen;
int op = 0;
while (ip < iEnd) {
int i0 = in[ip++] & 0xff;
int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
int o0 = i0 >>> 2;
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
int o3 = i2 & 0x3F;
out[op++] = map1[o0];
out[op++] = map1[o1];
out[op] = op < oDataLen ? map1[o2] : '='; op++;
out[op] = op < oDataLen ? map1[o3] : '='; op++; }
return out; }
/**
* Decodes a string from Base64 format.
* No blanks or line breaks are allowed within the Base64 encoded input data.
* @param s A Base64 String to be decoded.
* @return A String containing the decoded data.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static String decodeString (String s) {
return new String(decode(s)); }
/**
* Decodes a byte array from Base64 format and ignores line separators, tabs and blanks.
* CR, LF, Tab and Space characters are ignored in the input data.
* This method is compatible with
<code>sun.misc.BASE64Decoder.decodeBuffer(String)</code>.
* @param s A Base64 String to be decoded.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static byte[] decodeLines (String s) {
char[] buf = new char[s.length()];
int p = 0;
for (int ip = 0; ip < s.length(); ip++) {
char c = s.charAt(ip);
if (c != ' ' && c != '\r' && c != '\n' && c != '\t')
buf[p++] = c; }
return decode(buf, 0, p); }
/**
* Decodes a byte array from Base64 format.
* No blanks or line breaks are allowed within the Base64 encoded input data.
* @param s A Base64 String to be decoded.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static byte[] decode (String s) {
return decode(s.toCharArray()); }
/**
* Decodes a byte array from Base64 format.
* No blanks or line breaks are allowed within the Base64 encoded input data.
* @param in A character array containing the Base64 encoded data.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static byte[] decode (char[] in) {
return decode(in, 0, in.length); }
/**
* Decodes a byte array from Base64 format.
* No blanks or line breaks are allowed within the Base64 encoded input data.
* @param in A character array containing the Base64 encoded data.
* @param iOff Offset of the first character in <code>in</code> to be processed.
* @param iLen Number of characters to process in <code>in</code>, starting at
<code>iOff</code>.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
*/
public static byte[] decode (char[] in, int iOff, int iLen) {
if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input
string is not a multiple of 4.");
while (iLen > 0 && in[iOff+iLen-1] == '=') iLen--;
int oLen = (iLen*3) / 4;
byte[] out = new byte[oLen];
int ip = iOff;
int iEnd = iOff + iLen;
int op = 0;
while (ip < iEnd) {
int i0 = in[ip++];
int i1 = in[ip++];
int i2 = ip < iEnd ? in[ip++] : 'A';
int i3 = ip < iEnd ? in[ip++] : 'A';
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int b0 = map2[i0];
int b1 = map2[i1];
int b2 = map2[i2];
int b3 = map2[i3];
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
int o0 = ( b0 <<2) | (b1>>>4);
int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
int o2 = ((b2 & 3)<<6) | b3;
out[op++] = (byte)o0;
if (op<oLen) out[op++] = (byte)o1;
if (op<oLen) out[op++] = (byte)o2; }
return out; }
// Dummy constructor.
private Base64Coder() {}
} // end class Base64Coder
Cryptography.java
package neuralCrypt.cryptography;
/**
* encrypt and decrypt using three algorithms AES, Serpent, Twofish
* @author
*/
import gnu.crypto.cipher.BaseCipher;
import gnu.crypto.cipher.Rijndael;
import gnu.crypto.cipher.Serpent;
import gnu.crypto.cipher.Twofish;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.security.InvalidKeyException;
byte[] plainText;
byte[] encryptedText;
// create a key
byte[] keyBytes = key.getBytes();
Object keyObject = crypto.makeKey(keyBytes, 16);
byte[] encryptedText;
byte[] decryptedText;
TreeParityMachine.java
package neuralcryptography.net;
import java.util.ArrayList;
/**
*
* @author
*/
public class TreeParityMachine {
private int[] w, h;
public int K, N, L;
private int output;
/* constructor */
public TreeParityMachine(int n, int k, int l) {
this.K = k;
this.N = n;
this.L = l;
w = new int[k * n];
h = new int[k];
}
/* helper functions */
public static int sigma(double r) {
return (r > 0) ? 1 : -1;
}
public static int equ(int a,int b){
return (a==b)?1:0;
}
/*getter functions */
public int getWeight(int i){
return w[i];
}
}
return key.toString();
}
static final String
ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789abcdefghijklmnopqrstuvwxyz";
}
VectorInput.java
package neuralcryptography.net;
/**
*
* @author
*/
public class VectorInput {
Artificial neural network is an efficient technique which has the ability to implement security
using tree parity machine (i.e. special type of feed forward neural network). One of the primary
aspect in this field of neural cryptography appears to be the discovery of neural architecture with
very high synchronization speed, and design the encoding and entropy of the information
exchanged during mutual learning, to prevent the synchronization of an attacker during the
mutual learning process.
In the last decade, mutual learning based on the parity machine has become popular to be used
for cryptography. In this paper, a three parity machine that is a special type of a feed forward
neural network with three artificial neurons in the hidden layer, one output neuron and KN input
elements is presented. Inputs to the network are binary numbers, while the weights between
inputs and hidden neurons take predefined values. The output of the hidden neuron is calculated
as a weighted sum of all multiplications of inputs and weights. If the scalar product is zero, the
output of the hidden neuron is mapped to -1, otherwise it is mapped to 1, in order to ensure a
binary output from the network. The output bit of the network is a product of the three bits of the
hidden units.
Mutual learning is used for synchronization between two parties that communicate across a
public or private channel. During the synchronization, both communication parties use the same
tree parity machines, receive common binary inputs generated randomly from the same random
number generator, and exchange output bits. Adjusting the weights according to the learning
rules leads to full synchronization in a finite number of steps. Networks trained on their mutual
inputs synchronize to an identical time dependent weight vectors. This phenomenon is used to
generate a secret key.
9. BIBLIOGRAPHY
Sites Referred:
http://java.sun.com
http://www.sourceforge.net
http://www.networkcomputing.com/
http://www.roseindia.com/
http://www.java2s.com/
http://www. javadb.com/
[1] Navita Agarwal, Prachi Agarwal, “Use of Artificial Neural Network in the Field of
Security”, MIT International Journal of Computer Science & Information Technology, Vol.
3, No. 1, 42-44, 2013.
[2] Ajit Singh, Havir Singh, “Cryptography for Secret Key Exchange and Encryption with
AES”, International Journal of Advanced Research in Computer Science and Software
Engineering, Vol. 3, Issue. 5, 376-381, 2013.
[3] Siddeq Y. Ameen, Ali H. Mahdi, “AES Cryptosystem Development using Neural
Networks”, Inernational Journal of Computer and Electrical Engineering, Vol. 3, No. 2, 315-
318, 2011.
[4] Eva Volna, Martin Kotyrba, Vaclav Kocian, Michal Janosek, “Cryptography based on
neural network”, Proceedings 6th European Conference on Modelling and Simulation, 2012.
[9] Pratap Singh, Havir Singh, “Cryptography in Structure adaptable digital neural
networks”, National monthly refereed journal of research in science & technology, Vol. 1,
Issue. 12, 35-44,2012. [10]William Stalling, “ Cryptography and Network Security:
Principles and Practicle, (5th Edition), Prentice Hall, 2010.
[11]M. Arvandi, A. Sadeghian, “On the use of Recurrent Neural Networks to Design
Symmetric Cipher”, IEEE Computational Intelligence Magazine, pp. 42-53, May 2008.
[12]Khalil Shihab, “ A back propagation Neural Network for computer Network Security”,
Journal of computer science 2(9): 710-715, 2006.
[15]Seref S. Neclao, “ Neural Solution for Information Security”, Politeknik Dergisi, Journal
of Polytechnic, Vol. 10, No. 1, 21-25,2007.