Decentralized E-Voting System Based On Blockchain
Decentralized E-Voting System Based On Blockchain
Decentralized E-Voting System Based On Blockchain
BLOCKCHAIN
A PROJECT REPORT
Submitted by
ABIRAMI.R (412416205002)
NEVATHA.N (412416205052)
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
2019-2020
ANNA UNIVERSITY: CHENNAI 600 025
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
3. NEVATHA N
The Report of the project work submitted by the above students in partial
fulfillment for the award of Bachelor of Technology Degree in Information
technology of Anna University, Chennai were evaluated and confirmed to be
report of the work done by the above students.
i
ABSTRACT
Voting is a major factor to change the country’s future. With 800 million voters
and nearly 2,000 political parties taking part, India's elections are a staggeringly
challenging exercise.The major issues in the current voting system are vote
rigging, hacking of the EVM (Electronic voting machine) and election
manipulation.In 2017, in Rajasthan, it was found that eighteen EVMs were
registering votes for the wrong party. There have been several similar cases in the
country.To overcome these issues we suggest a decentralized system to be
integrated with the voting system .One of those decentralized systems is block
chain. This paper aims to evaluate the application of block chain as service to
implement distributed electronic voting systems.The proposed model has a more
prominent security as in voter high security secret word is affirmed before the
vote is acknowledged in the primary database of Election Commission of
India.Using block chain technique we can improve security as well as it helps to
implement our online voting system without malicious user.
ii
TABLE OF CONTENTS
ACKNOWLEDGEMENT I
ABSTRACT ii
LIST OF ABBREVIATIONS vi
1 INTRODUCTION 1
2 LITERATURE SURVEY 4
3 SYSTEM ANALYSIS 7
4 REQUIREMENTS SPECIFICATION 9
4.1 Introduction 9
4.3.4 XML 20
4.3.5 IDE 21
4.3.6 My SQL 24
4.3.7 RMI 25
4.3.8 Ganache 26
5 SYSTEM DESIGN 27
6 MODULE DESIGN 36
6.1 Modules 36
8 SOURCE CODE 48
9 SCREENSHOTS 70
10 CONCLUSION 78
11 REFERENCES 79
LIST OF ABBREVATIONS
vi
CHAPTER 1
INTRODUCTION
Blockchain technology that shines sort of a star once the doorway and
widespread acceptance of Bitcoin, the terribly 1st cryptocurrency in peoples’
lifestyle, has become a trending topic in today's package world. In a democracy ,
government is chosen by voting in an election and the security of an election is
a matter of national security.Election security refers to the protection of
elections and voting infrastructure from cyberattack or cyber threat.Cyber
attacks or threats including the tampering with or infiltration of voting
machines and equipment,election office networks and voter registration
databases.Voting fraud is not either present everywhere or absent
everywhere. In our country,there have always been allegation of fraud by all
the losing political parties.A malicious voting system created and distributed
by one vendor to hundreds of polling booths, can systematically falsify
millions of votes. Blockchain is a distributed ledger that can record
transactions between two parties efficiently and in a verifiable manner. A
blockchain is a growing list of blocks that are linked using cryptography. The
three main features of blockchain are :
[1] Immutability :
1
[2] Decentralized consensus:
[3] Verifiability:
At the start, Blockchain was solely used for financial transactions and trade,
however studies have began to recommend that it will be employed in more areas
over time, as a result of there's a high degree of transparency during this system.
For instance, in Bitcoin, since the wallets area unit in an exceedingly distributed
structure, the whole quantity of coins and instant group action volume within the
world will be followed momentarily and clearly. There’s no would like for a
central authority to approve or complete the operations on this P2P-based system.
3
CHAPTER 2
LITERATURE SURVEY
4
➢ Project Title: E-Voting with Blockchain: An E-Voting Protocol with
Apostolos Gioulis,
Konstantinos Markantonakis
5
➢ Project Title: Blockchain-Based E-Voting System
Gunnlaugur K. Hreiðarsson,
Mohammad Hamdaqa,
Gísli Hjálmtýsson
6
CHAPTER 3
SYSTEM ANALYSIS
Electronic Voting is the voting system where electronic devices are used
to cast and count the votes. In this system, standalone Electronic Voting Machines
(EVM).
In 2017, in Rajasthan, it was found that eighteen EVMs were registering votes for
the wrong party. There have been several similar cases in the country.
Considering the aforementioned examples, it can be said that the E-Voting system
poses the following threats.
2. It is not secure as there have been many instances where the confidential
information of the voters was leaked.
3. The current sphere of voting is not an open process. Its internal workings are
accessible only to certain people as opposed to it being open to the public.
5. The current election process is a very expensive affair that requires heavy prior
planning, organization of police officials and other election officials.
7
3.2 PROPOSED SYSTEM
The first transaction added to the block will be a special transaction that
represents the candidate.
• When this transaction is created it will include the candidate's name and will
serve as the foundation block, with every vote for that specific candidate placed on
top of it. Unlike the other transactions, the foundation will not count as a vote, and
it will only contain the name of the candidate.
• Our e-Voting system will allow a protest vote, where the voter may return a
blank vote to demonstrate dissatisfaction with all candidates or a refusal of the
current political system and/or election.
• Every time a person votes the transaction gets will be recorded and the
blockchain will be updated.
To ensure that the system is secure, the block will contain the previous voter’s
information. If any of the blocks were compromised, then it would be easy to find
out since all blocks are connected to each other. The blockchain is decentralized
and cannot be corrupted, no single point of failure exists. The blockchain is where
the actual voting takes place. The user’s vote gets sent to one of the nodes on the
system, and the node then adds the vote to the blockchain. The voting system will
have a node in each district to ensure the system is decentralized.
8
CHAPTER 4
REQUIREMENT SPECIFICATIONS
4.1 INTRODUCTION
9
4.2.2 SOFTWARE REQUIREMENTS
• Tool : Metamask
• Front End : HTML, CSS, Javascript
• Database Connectivity : JDBC
Initially the language was called as “oak” but it was renamed as “java” in
1995.The primary motivation of this language was the need for a platform-
independent(i.e. architecture neutral)language that could be used to create
software to be embedded in various consumer electronic devices.
Java has been around since 1991, developed by a small team of Sun
Microsystems developers in a project originally called the Green project. The
intent of the project was to develop a platform-independent software technology
10
that would be used in the consumer electronics industry. The language that the
team created was originally called Oak.
The first implementation of Oak was in a PDA-type device called Star
Seven (*7) that consisted of the Oak language, an operating system called
GreenOS, a user interface, and hardware. The name *7 was derived from the
telephone sequence that was used in the team's office and that was dialed in order
to answer any ringing telephone from any other phone in the office.
Around the time the First Person project was floundering in consumer
electronics, a new craze was gaining momentum in America; the craze was called
"Web surfing." The World Wide Web, a name applied to the Internet's millions of
linked HTML documents was suddenly becoming popular for use by the masses.
The reason for this was the introduction of a graphical Web browser called Mosaic,
developed by ncSA. The browser simplified Web browsing by combining text and
graphics into a single interface to eliminate the need for users to learn many
confusing UNIX and DOS commands. Navigating around the Web was much
easier using Mosaic.
It has only been since 1994 that Oak technology has been applied to the
Web. In 1994, two Sun developers created the first version of Hot Java, and then
called Web Runner, which is a graphical browser for the Web that exists today.
The browser was coded entirely in the Oak language, by this time called Java.
Soon after, the Java compiler was rewritten in the Java language from its original C
code, thus proving that Java could be used effectively as an application language.
Sun introduced Java in May 1995 at the Sun World 95 convention.
Web surfing has become an enormously popular practice among
millions of computer users. Until Java, however, the content of information on the
Internet has been a bland series of HTML documents. Web users are hungry for
11
applications that are interactive, that users can execute no matter what hardware or
software platform they are using, and that travel across heterogeneous networks
and do not spread viruses to their computers. Java can create such applications.
a) WORKING OF JAVA
• Programming language
• Platform
12
b) Cloud Computing
• Users need not have knowledge of, expertise in, or control over the
technology infrastructure in the "cloud" that supports them.
• They consume resources as a service and pay only for resources that
they use.
13
c) THE JAVA PROGRAMMING LANGUAGE
• Simple
• Object-oriented
• Distributed
• Interpreted
• Robust
• Secure
• Architecture-neutral
• Portable
• High-performance
• Multithreaded
• Dynamic
➢ Simple:
Java was designed to be easy for the Professional programmer to learn and to
use effectively. If you are an experienced C++ Programmer. Learning Java will
oriented features of C++ . Most of the confusing concepts from C++ are either
left out of Java or implemented in a cleaner, more approachable manner. In Java
there are a small number of clearly defined ways to accomplish a given task.
➢ OBJECT ORIENTED:
Java was not designed to be source-code compatible with any other language.
This allowed the Java team the freedom to design with a blank state. One
14
outcome of this was a clean usable, pragmatic approach to objects. The object
model in Java is simple and easy to extend, while simple types, such as integers,
are kept as high-performance non-objects.
➢ ROBUST
Fig.4.3.1(a)
15
You can think of Java byte codes as the machine code instructions for the Java
Virtual Machine (JVM). Every Java interpreter, whether it’s a Java
development tool or a Web browser that can run Java applets, is an
implementation of JVM. That JVM 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 any platform that
has a Java compiler. The byte codes can then be run on any implementation of
the JVm. For example, that same Java program can e run on Windows NT,
Solaris and Macintos
16
d) THE JAVA PLATFORM
You’ve already been introduced to the JVM. It’s the base for the Java
platform and is ported onto various hardware-based platforms.
Fig.4.3.1(c)
17
As a platform-independent environment, Java can be a bit slower than native
code. However, smart compliers, weel-tuned interpreters, and just-in-time byte
complilers can bring Java’s performance close to that of native code without
threatening protability.
Using Servlets, you can collect input from users through web page forms, present
records from a database or another source, and create web pages dynamically.
Java Servlets often serve the same purpose as programs implemented using the
Common Gateway Interface (CGI). But Servlets offer several advantages in
comparison with the CGI. Performance is significantly better. Servlets execute
within the address space of a Web server. It is not necessary to create a separate
process to handle each client request. Servlets are platform-independent because
they are written in Java. Java security manager on the server enforces a set of
restrictions to protect the resources on a server machine. So servlets are trusted.
The full functionality of the Java class libraries is available to a servlet. It can
communicate with applets, databases, or other software via the sockets and RMI
mechanisms that you have seen already.
18
SERVLET ARCHITECTURE:
Fig.4.3.2
4.3.3. APACHE TOMCAT SERVER
Apache Tomcat (formerly under the Apache Jakarta Project; Tomcat is now
a top level project) is a web container developed at the Apache Software
Foundation. Tomcat implements the servlet and the JavaServer Pages (JSP)
specifications from Sun Microsystems, providing an environment for Java code to
run in cooperation with a web server. It adds tools for configuration and
management but can also be configured by editing configuration files that are
normally XML-formatted. Because Tomcat includes its own HTTP server
internally, it is also considered a standalone web server.
➢ Environment
Tomcat is a web server that supports servlets and JSPs. Tomcat comes
with the Jasper compiler that compiles JSPs into servlets.
Since its developers wrote Tomcat in Java, it runs on any operating system
that has a JVM.
➢ Product features
• Coyote connector
• Java Management Extensions (JMX),JSP&Struts-based
administrationTomcat 5.x
• Implements the Servlet 2.4 and JSP 2.0 specifications
• Reduced garbage collection, improved performance and scalability
• Native Windows and Unix wrappers for platform integration
• Faster JSP paring
➢ History
Tomcat started off as a servlet specification implementation by James
Duncan Davidson, a software architect at Sun. He later helped make the project
open source and played a key role in its donation by Sun to the Apache Software
Foundation.
20
Davidson had initially hoped that the project would become open-sourced
and, since most open-source projects had O'Reilly books associated with them featuring
an animal on the cover, he wanted to name the project after an animal. He came up with
Tomcat since he reasoned the animal represented something that could take care of and
fend for itself. His wish to see an animal cover eventually came true when O'Reilly
published their Tomcat book with a tomcat on the cover.
4.3.4. XML:
XML tags identify the data and are used to store and organize the data, rather
than specifying how to display it like HTML tags, which are used to display the data.
XML is not going to replace HTML in the near future, but it introduces new
possibilities by adopting many successful features of HTML. There are three important
characteristics of XML that make it useful in a variety of systems and solutions:
• XML carries the data, does not present it: XML allows you to store the
data irrespective of how it will be presented.
21
A short list of XML usage says it all:
• XML can work behind the scene to simplify the creation of HTML
documents for large web sites.
• XML can be used to store and arrange the data, which can customize your
data handling needs.
• XML can easily be merged with style sheets to create almost any desired
output.
4.3.5. IDE:
22
➢ Net beans:
Net Beans IDE is the official IDE for Java 8. With its editors, code analyzers, and
converters, you can quickly and smoothly upgrade your applications to use new Java 8
language constructs, such as lambdas, functional operations, and method references.
Batch analyzers and converters are provided to search through multiple applications at
the same time, matching patterns for conversion to new Java 8 language constructs.
With its constantly improving Java Editor, many rich features and an extensive range of
tools, templates and samples, Net Beans IDE sets the standard for developing with
cutting edge technologies out of the box.
➢ Eclipse:
In computer programming, Eclipse is an integrated development
environment (IDE). It contains a base workspace and an extensible plug-in system for
customizing the environment. Written mostly in Java, Eclipse can be used to develop
applications. By means of various plug-INS, Eclipse may also be used to develop
applications in other programming languages: Ada, ABAP,
C, C++, COBOL, FORTRAN, Haskell, JavaScript, Lasso, Natural, Perl, PHP, Prolog, P
ython, R, Ruby (including RubyonRails framework), Scala, Clojure, Groovy, Scheme,
and Erlang. It can also be used to develop packages for the softwareMathematica.
Development environments include the Eclipse Java development tools (JDT) for Java
and Scala, Eclipse CDT for C/C++ and Eclipse PDT for PHP, among others. The
initial codebase originated from IBM VisualAge. The Eclipse software development
kit (SDK), which includes the Java development tools, is meant for Java developers.
Users can extend its abilities by installing plug-ins written for the Eclipse Platform,
such as development toolkits for other programming languages, and can write and
contribute their own plug-in modules. Released under the terms of the Eclipse Public
23
License, Eclipse SDK is free and open source software (although it is incompatible with
the GNU General Public License). It was one of the first IDEs to run under GNU Class
path and it runs without problems under Iced Tea.
4.3.6. MY SQL:
MySQL is (as of March 2014) the world's second most widely used open-
source relational database management system (RDBMS). It is named after co-
founder Michael Widenius's daughter, My. The SQL phrase stands for Structured Query
Language.The MySQL development project have made its source code available under
the terms of the GNU General Public License, as well as under a variety
of proprietary agreements. MySQL was owned and sponsored by a single for-
profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
MySQL is a popular choice of database for use in web applications, and is a central
component of the widely used LAMP open source web application software stack (and
other 'AMP' stacks). LAMP is an acronym for "Linux, Apache, MySQL, and
Perl/PHP/Python." Free-software-open source projects that require a full-featured
database management system often use MySQL. For proprietary use, several paid
editions are available, and offer additional functionality. Applications which use
MySQL databases include: TYPO3, MODx, Joomla, Word
Press, phpBB, MyBB, Drupal and other software. MySQL is also used in many high-
profile, large-scale websites, including Google (though not for searches), Face
book, Twitter, Flickr, and YouTube.
24
➢ SQL YOG:
SQLyog is a GUI tool for the RDBMS MySQL. It is developed by Webyog, Inc.
based out of Bangalore, India and Santa Clara, California. SQLyog is being used by
more than 30,000 customers worldwide and has been downloaded more than 2,000,000
times.
4.3.7. RMI:
The Java Remote Method Invocation (Java RMI) is a Java API that performs
the object-oriented equivalent of remote procedure calls (RPC), with support for direct
transfer of serialized Java classes and distributed garbage collection.
Usage of the term RMI may denote solely the programming interface or may signify
both the API and JRMP, whereas the term RMI-IIOP (read: RMI over IIOP) denotes the
RMI interface delegating most of the functionality to the
supporting CORBA implementation.
Fig.4.3.7
25
4.3.8. GANACHE:
Ganache, previously Testrpc, is a virtual blockchain which sets up 10 default
Etheruem addresses, complete with private keys and all, and pre-loads them with 100
simulated Ether each. There is no "mining" per-se with Ganache - instead, it
immediately confirms any transaction coming its way. This makes iterative
development possible - you can write unit tests for your code which execute on this
simulated blockchain, deploy smart contracts, play around, call functions, and then
tear it all down for further simulation or new tests, returning all addresses to their
initial state of 100 Ether.
➢ Remix:
The browser based IDE for writing and deploying Solidity code for the
Ethereum blockchain - is fine and all, but it can be slow to develop on. It is a browser
based system and as such, tooling is limited.
When working with EVM (Ethereum Virtual Machine) code that's going to
end up in production, you're going to need inheritance, tests, auto-completion, helper
tools like linters and validators and much more.
26
CHAPTER 5
5. ARCHITECTURE DIAGRAM
Fig 5
27
5.1 Sequence Diagram:
1 : SIGNUP()
2 : BLOCK i+2()
3 : LOGIN()
4 : LOGIN()
7 : DETAILS()
9 : FIRST BLOCK() 8 : CANDIDATE LIST()
13 : BLOCK i-1()
14 : CLOUD LEDGER()
15 : BALLOT BLOCK()
17 : RESULT()
18 : VOTER SIGNUP()
Fig.5.1
28
5.2 Use Case Diagram:
LOGIN
ELECTION COMMISION
MINER
BALLOT BLOCK
SIGNUP
LOG-IN
DETAILS
CANDIDATE LIST
RESULT
VOTER
CLOUD LEDGER
GANACHE
VOTER SIGNUP
FIRST BLOCK
BLOCK i+2
BLOCK i+1
BLOCK i
BLOCK i-1
Fig.5.2
29
5.3 Activity Diagram:
LOGIN
BLOC K F OR VOTING
BA LLOT BLOC K
LOG-IN
DETA ILS
C A NDIDA TE LIST
RESULT
C LOUD LEDGER
VOTER SIGNUP
F IRST BLOC K
BLOC K i+2
BLOC K i+1
BLOC K i
BLOC K i-1
Fig.5.3
30
5.4 Collaboration Diagram:
VOTER
18 : VOTER SIGNUP()
11 : BLOCK i()
MINER 17 : RESULT()
10 : BLOCK CREATION i+1()
12 : BLOCK FOR VOTING()
Fig.5.4
31
5.5 Dataflow Diagram
Level 0
Register
VOTERS LOGIN
MINERS
ELECTION LOGIN
COMMISION
Fig.5.5(a)
Level 1
UPLOAD ELECTION
ELECTION NOMINEES
COMMISION
BALLOT MINER
CREATION
Fig.5.5(b)
32
Level 2
NODE
BLOCKCHAIN
CLIENT
DATA
STORAGE
Fig.5.5(c)
Level 3
GANACH
E
DATABASE
BLOCK i+2 BLOCK i+1
BLOCK i
DATABASE
Fig.5.5(d)
33
Level 4
Fig5.5(d)
34
5.6 Class Diagram
+LOGIN +SIGNUP
+BLOCK CREATOR i+2 +LOG-IN
+BLOCK CREATION i+1 +DETAILS
+BLOCK FOR VOTING +CANDIDATE LIST
+BALLOT BLOCK +RESULT
+CLOUD LEDGER
+GANACHE()
+BLOCK i+2() +VOTER()
+BLOCK i+1() +VOTER SIGNUP()
+BLOCK() +FIRST BLOCK()
+BLOCK i-1() +HASH KEY GENERATION()
Fig.5.6
35
CHAPTER 6
MODULE DESIGN
6.1 MODULES
✓ Requesting to vote
✓ Casting a vote
✓ Encrypting votes
✓ Adding the vote to the Blockchain
➢ Requesting to vote
The user will have to log in to the voting system using his credentials- in
this case, the e-voting system will use his Social Security Number, his address, and
the voting confirmation number provided to registered voters by the local
authorities. The system will check all information entered and, if matched with a
valid voter, the user will be authorized to cast a vote. Our e-Voting system will not
allow participants to generate their own identities and register to vote. Systems that
allow identities to be arbitrarily generated are usually vulnerable to the Sybil attack
where attackers claim a large number of fake identities and stuff the ballot box
with illegitimate votes.
➢ Casting a vote
Voters will have to choose to either vote for one of the candidates or cast a
protest vote. Casting the vote will be done through a friendly user interface. For
each voter a token is generated known as Ethereum, with initial Boolean value one,
36
once a vote is casted it becomes 0. A voter can cast a vote if and only if Ethereum
value is 1. In this way revoting problem is resolved.
➢ Encrypting votes
After the user casts his vote, the system will generate an input that
contains the voter identification number followed by the complete name of the
voter as well as the hash of the previous vote. This way each input will be unique
and ensure that the encrypted output will be unique as well. The encrypted
information will be recorded in the block header of each vote cast. The information
related to each vote will be encrypted using SHA one-way hash function that has
no known reverse to it. The only theoretically possible way to reverse the hash
would be to guess the seed data and the encryption method and then hash it to see
if the results match. This way of hashing votes makes it nearly impossible to
reverse engineer, therefore there would be no way voters' information could be
retrieved.
37
CHAPTER 7
• Naming conventions
• Value conventions
38
7.1.2.1.Class names
Class names are problem domain equivalence and begin with capital letter
and have mixed cases.
Member function and data member name begins with a lowercase letter
with each subsequent letters of the new words in uppercase and the rest of letters in
lowercase.
Value conventions ensure values for variable at any point of time. This
involves the following:
39
7.1.5 MESSAGE BOX FORMAT
➢ SYSTEM TESTING
System testing is simply testing the system as a whole; it gets all the integrated
modules of the various components from the integration testing phase and
combines all the different parts into a system which is then tested. Testing is then
done on the system as all the parts are now integrated into one system the testing
phase will now have to be done on the system to check and remove any errors or
bugs.
40
7.3 TEST DATA AND OUTPUT
It is the first and the most basic level of Software Testing, in which a
single unit (i.e. a smallest testable part of a software) is examined in isolation from
the remaining source code. Unit Testing is done to verify whether a unit is
functioning properly. In other words, it checks the smallest units of code and
proves that the particular unit can work perfectly in isolation. However, one needs
to make sure that when these units are combined, they work in a cohesive manner.
This directs us to other levels of software testing.
Functional test cases involved exercising the code with nominal input
values for which the expected results are known, as well as boundary values and
special values, such as logically related inputs, files of identical elements, and
empty files.
• Performance Test
• Stress Test
• Structure Test
41
7.3.3 PERFORMANCE TEST
Stress Test is those test designed to intentionally break the unit. A Great
deal can be learned about the strength and limitations of a program by examining
the manner in which a programmer in which a program unit breaks.
42
associated with interfacing. i.e., integration testing is the complete testing of the set
of modules which makes up the product. The objective is to take untested modules
and build a program structure tester should identify critical modules. Critical
modules should be tested as early as possible. One approach is to wait until all the
units have passed testing, and then combine them and then tested. This approach is
evolved from unstructured testing of small programs. Another strategy is to
construct the product in increments of tested units. A small set of modules are
integrated together and tested, to which another module is added and tested in
combination. And so on. The advantages of this approach are that, interface
dispenses can be easily found and corrected.
The major error that was faced during the project is linking error. When
all the modules are combined the link is not set properly with all support files.
Then we checked out for interconnection and the links. Errors are localized to the
new module and its intercommunications. The product development can be staged,
and modules integrated in as they complete unit testing. Testing is completed when
the last module is integrated and tested. It can be performed in two ways-
43
o Sandwich Testing: this approach is the hybrid of Top-Down Testing and
Bottom-Up Testing
o Big Bang Testing: in this approach, most or all of the software modules are
put together at once, and then tested. Even though Big Bang testing saves a
lot of time, the results recorded are not always accurate. This might result in
complications and prevent the developing team to achieve their testing goals.
a)TESTING
The software testing process commences once the program is created and the
documentation and related data structures are designed. Software testing is
essential for correcting errors. Otherwise the program or the project is not said to
be complete. Software testing is the critical element of software quality assurance
and represents the ultimate the review of specification design and coding. Testing
is the process of executing the program with the intent of finding the error. A good
44
test case design is one that as a probability of finding an yet undiscovered error. A
successful test is one that uncovers an yet undiscovered error. Any engineering
product can be tested in one of the two ways:
45
• Equivalence partitioning
• Boundary value analysis
• Comparison testing
f) PROGRAM TESTING:
The logical and syntax errors have been pointed out by program
testing. A syntax error is an error in a program statement that in violates one or
more rules of the language in which it is written. An improperly defined field
dimension or omitted keywords are common syntax error. These errors are shown
through error messages generated by the computer. A logic error on the other hand
deals with the incorrect data fields, out-off-range items and invalid combinations.
Since the compiler s will not deduct logical error, the programmer must examine
the output. Condition testing exercises the logical conditions contained in a
module. The possible types of elements in a condition include a Boolean operator,
Boolean variable, a pair of Boolean parentheses A relational operator or on
arithmetic expression. Condition testing method focuses on testing each condition
in the program the purpose of condition test is to deduct not only errors in the
condition of a program but also other a errors in the program.
g) SECURITY TESTING
h) VALIDATION TESTING
48
i) USER ACCEPTANCE TESTING
User acceptance of the system is key factor for the success of any
system. The system under consideration is tested for user acceptance by constantly
keeping in touch with prospective system and user at the time of developing and
making changes whenever required. This is done in regarding to the following
points.
8 SOURCE CODE:
FRONT END:
UploadCandidatesData
49
<%
String nam = session.getAttribute("name").toString();
String hash = session.getAttribute("hash").toString();
%>
<div style="width: 1350px;height: 100px;background-color: seagreen">
<div style="margin-left: 400px;">
<a class="active" href="ElectionHome.jsp"><button class="btn btn-
primary">Home</button></a>
<a href="UploadCandidatesData.jsp"><button class="btn btn-primary">Upload
Candidate Data</button></a>
<!-- <a href="File Upload.jsp"><button class="btn btn-primary">File
Upload</button></a>-->
<!--<a href="AdminRequest.jsp"><button class="btn btn-primary">Admin
Request</button></a>-->
<!-- <a href="DoctorDescription.jsp"><button class="btn btn-primary">Doctor
Description</button></a>-->
<a href="index.html"><button class="btn btn-primary">Logout</button></a>
</div>
</div>
<h4>Your Hash ---> <%=hash%></h4>
<h3>Upload Candidate Details</h3>
<br>
<br>
<form action="UploadCandidates" method="post">
<div class="container">
<div class="row">
50
<div class="col col-md-6">
<div class=" alert alert-info">
<div class="form-group">
<h5>Upload candidate data</h5>
<br>
<br>
<input type="hidden" name="hash" value="<%=hash%>">
<input type="text" class="form-control" name="name" required=""
placeholder="UserName">
<br>
<input type="text" class="form-control" name="fname" required=""
placeholder="fatherName"><br>
<input type="text" class="form-control" name="age" required=""
placeholder="Age">
<br>
<input type="file" class="form-control" name="filename" required=""
placeholder="Choosefile">
<br>
<input type="file" class="form-control" name="sym" required=""
placeholder="ChooseSymbol">
<br>
<input type="text" class="form-control" name="address" required=""
placeholder="Address">
<br>
<input type="text" class="form-control" name="district" required=""
placeholder="District">
<br>
51
<input type="state" class="form-control" name="state" required=""
placeholder="State">
<br>
<input type="submit" class="form-control" placeholder="Upload">
<br>
</div>
</div>
</form>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UT<meta http-
equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script src="js/bootstrap.min.js" type="text/javascript"></scrip<script
src="js/bootstrap.bundle.min.js" type="text/javascript"></script>
</head>
<body>
<%
String nam = session.getAttribute("name").toString();
String hash = session.getAttribute("hash").toString();
%><div style="width: 1350px;height: 100px;background-color: seagreen">
<div style="margin-left: 400px;">
<a class="active" href="ElectionHome.jsp"><button class="btn btn-
primary">Home</button></a>
<a href="UploadCandidatesData.jsp"><button class="btn btn-primary">Upload
Candidate Data</button></a>
52
<!-- <a href="File Upload.jsp"><button class="btn btn-primary">File
Upload</button></a>-->
<!--<a href="AdminRequest.jsp"><button class="btn btn-primary">Admin
Request</button></a>-->
<!-- <a href="DoctorDescription.jsp"><button class="btn btn-primary">Doctor
Description</button></a>-->
<a href="index.html"><button class="btn btn-primary">Logout</button></a>
</div>
</div>
<h4>Your Hash ---> <%=hash%></h4>
<h3>Upload Candidate Details</h3>
<br>
<br>
<form action="UploadCandidates" method="post">
<div class="container">
<div class="row">
<div class="col col-md-6">
<div class=" alert alert-info">
<div class="form-group">
<h5>Upload candidate data</h5>
<br>
<br>
<input type="hidden" name="hash" value="<%=hash%>">
<input type="text" class="form-control" name="name" required=""
placeholder="UserName">
53
<br>
<input type="text" class="form-control" name="fname" required=""
placeholder="fatherName"><br>
<input type="text" class="form-control" name="age" required=""
placeholder="Age">
<br>
<input type="file" class="form-control" name="filename" required=""
placeholder="Choosefile">
<br>
<input type="file" class="form-control" name="sym" required=""
placeholder="ChooseSymbol">
<br>
<input type="text" class="form-control" name="address" required=""
placeholder="Address">
<br>
<input type="text" class="form-control" name="district" required=""
placeholder="District">
<br>
<input type="state" class="form-control" name="state" required=""
placeholder="State">
<br>
<input type="submit" class="form-control" placeholder="Upload">
<br>
</div>
</div>
</form>
54
</body>
</html>
USER SIGNUP:
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
<script src="public/js/analytics.js"></script>
<script src="public/js/jquery-3.2.1.min.js"></script>
<script src="public/js/truffle-contract.js"></script>
<script src="public/js/web3.min.js"></script>
<script src="public/js/truffle-config.js"></script>
</head>
<body>
55
<div style="width: 1350px;height: 100px;background-color: lightblue">
</div>
</div>
<br>
<center>
</table>
</form>
<br><br>
<span id="status"></span>
<br>
</center>
</body>
</html>
WEB3 CONNECTER
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.concurrent.CountDownLatch;
57
import java.util.concurrent.TimeUnit;
import io.reactivex.Single;
import io.reactivex.disposables.Disposable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.Transaction;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;
public Web3jConnect() {
log.info("Doing simpleFilterExample");
simpleFilterExample();
log.info("Doing blockInfoExample");
blockInfoExample();
58
log.info("Doing countingEtherExample");
countingEtherExample();
log.info("Doing clientVersionExample");
clientVersionExample();
System.exit(0); }
new Web3jConnect().run();
}, Throwable::printStackTrace);
TimeUnit.MINUTES.sleep(2);
subscription.dispose();
.take(COUNT)
59
.subscribe(ethBlock -> {
block.getTimestamp()
.longValueExact()).atZone(ZoneId.of("UTC")).toLocalDateTime();
log.info(
);
countDownLatch.countDown();
}, Throwable::printStackTrace);
countDownLatch.await(10, TimeUnit.MINUTES);
subscription.dispose();
60
CountDownLatch countDownLatch = new CountDownLatch(1);
.take(COUNT)
.map(Transaction::getValue)
.reduce(BigInteger.ZERO, BigInteger::add);
countDownLatch.countDown();
}, Throwable::printStackTrace);
countDownLatch.await(10, TimeUnit.MINUTES);
subscription.dispose();
countDownLatch.countDown();
});
61
countDownLatch.await();
subscription.dispose();
BACK END:
WRITE TO FILE:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;
62
}
try {
a.add(cd);
a.add(cd1);
a.add(pat1);
a.add(pat2);
a.add(pat3);
a.add(pat4);
if (!file.exists()) {
file.createNewFile();
63
for (int j = 0; j < a.size(); j++) {
bw.write((String) a.get(j));
bw.newLine();
bw.close();
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
SHA 256:
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class SHA256 {
MessageDigest md = MessageDigest.getInstance("SHA-256");
return md.digest(input.getBytes(StandardCharsets.UTF_8));
64
public static String toHexString(byte[] hash) {
hexString.insert(0, '0');
return hexString.toString();
try {
String s2 = args;
System.out.println(toHexString(getSHA(s2)));
output = toHexString(getSHA(s2));
} catch (NoSuchAlgorithmException e) {
return output;
65
Data Read
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
arrayListConstructor("D://data.txt");
System.out.println(data);
BufferedReader br = null;
66
while (line != null) {
if (map.get(line) == null) {
data.add(line);
map.put(line, line)
} else {
if (line.equals("arun")) {
boolean a = true;
System.out.println(a);
} else {
boolean b = false;
System.out.println(b);
line = br.readLine();
br.close();
BLOCK CHAIN:
import com.google.gson.GsonBuilder;
67
import java.util.ArrayList;
//
// System.out.println(blockchainJson);
return blockchainJson;
//
// System.out.println(blockchainJson);
68
return blockchainJson;
69
9. SCREENSHOTS:
70
71
72
73
74
75
76
77
10. CONCLUSION:
78
11. REFERENCES
[5] C.D. Clack, V.A. Bakshi, and L. Braine, “Smart contract templates:
foundations, design landscape and research directions”, Mar 2017,
arXiv:1608.00771.
79
[7] U.C. Çabuk, A. Çavdar, and E. Demir, "E-Demokrasi:
YeniNesilDo÷rudanDemokrasiveTürkiye’dekiUygulanabilirli÷i", [Online]
Available:https://www.researchgate.net/profile/Umut_Cabuk/publication/3087962
30_EDemocracy_The_Next_Generation_Direct_Democracy_and_Applicability_in
_Turkey/links/5818a6d408a ee7cdc685b40b/E-Democracy-The-Next-Generation-
DirectDemocracy-andApplicability-in-Turkey.pdf.
[9] F. Hao and P.Y.A. Ryan, Real-World Electronic Voting: Design, Analysis and
Deployment, CRC Press, pp. 143-170, 2017.
80