<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pranith Hengavalli</title>
    <description>The latest articles on Forem by Pranith Hengavalli (@prnthh).</description>
    <link>https://forem.com/prnthh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F106656%2F29824117-6a03-4146-90c1-c6fb9b53a67a.jpg</url>
      <title>Forem: Pranith Hengavalli</title>
      <link>https://forem.com/prnthh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prnthh"/>
    <language>en</language>
    <item>
      <title>Automate Anything Easily With Applescript</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Fri, 15 Mar 2019 22:12:51 +0000</pubDate>
      <link>https://forem.com/prnthh/automate-anything-easily-with-applescript-2oao</link>
      <guid>https://forem.com/prnthh/automate-anything-easily-with-applescript-2oao</guid>
      <description>&lt;p&gt;If there's a series of actions you find yourself doing really often, it'll probably save a lot of time in the long term to write a script to do it. AppleScript lets you automate just about anything on your Mac, from file I/O to interactive prompts and filling in web browsers. It can even automatically reply to your messages for you!&lt;/p&gt;

&lt;p&gt;Unlike regular programming languages, its deep integration with OSX lets you create rich GUIs and complex actions that would require a lot more effort to do a more universal language like Python. &lt;/p&gt;

&lt;p&gt;Recently I wrote a script that takes the name of my git branch and automatically builds iOS and Android variants, and sends me a notification on Slack when it's all done. This would otherwise involve a lot of manual effort since the builds are started on two separate Jenkins web dashboards. This is something I usually do a few times a day, and I probably save a few minutes cumulatively thanks to the script. 😄&lt;/p&gt;

&lt;p&gt;To start writing a script, open Script Editor on your Mac. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkr9teugxh5m19goj9qyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkr9teugxh5m19goj9qyw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In many cases, you can generate an AppleScript by just pressing the record button and doing the sequence of actions once. The script editor generates code for each action as you perform it. &lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdjxs23aicm33uuzt63za.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdjxs23aicm33uuzt63za.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the cases where AppleScript doesn't work as well is when interacting with the content on web pages. For this I like to execute Javascript directly on the page, which I think is a more powerful approach than detecting elements in the GUI. &lt;/p&gt;




&lt;p&gt;The following snippet defines a function called clickClassName that clicks on the selected element on the page, in this case the 3rd button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;to clickClassName(theClassName, elementnum)
  tell application "Safari"
    do JavaScript "document.getElementsByClassName('" &amp;amp; theClassName &amp;amp; "')[" &amp;amp; elementnum &amp;amp; "].click();" in document 1
  end tell
end clickClassName

clickClassName("button", 3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  User input
&lt;/h2&gt;

&lt;p&gt;You can accept user input in your scripts, and you get these pretty dialog boxes that come with various input type options. This is useful to pick options at the time of running the script.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzviv41j6zm3f5gy0llrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzviv41j6zm3f5gy0llrg.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;display dialog 
    "What website do you want to see?" buttons {"Dev.to", "StackOverflow", "Hacker News"}
set theSite to button returned of result
display dialog theSite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Persistent Data
&lt;/h2&gt;

&lt;p&gt;Properties are saved between launches, and can be used to remember your last input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;property variable : 0
display dialog variable
set variable to 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will show 0 on the first run and 100 on the second run.&lt;/p&gt;




&lt;p&gt;A surprising number of applications support automation. Go to File &amp;gt; Open Dictionary to see a list of installed applications that support AppleScript control, as well as documentation about supported commands.&lt;/p&gt;

&lt;p&gt;Finally, you'll need to save it as an application so it won't open the script editor each time you try to run it. Go to File &amp;gt; Export &amp;gt; Set the file format to 'Application' &amp;gt; Save. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn2aq0ggatysr0zslgxbr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn2aq0ggatysr0zslgxbr.png"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;The best scripts are the ones you write for yourself, but here are some useful scripts to get you started:&lt;br&gt;
&lt;a href="https://www.computerworld.com/article/2524645/10-applescripts-to-make-you-love-your-mac--even-more-.html" rel="noopener noreferrer"&gt;https://www.computerworld.com/article/2524645/10-applescripts-to-make-you-love-your-mac--even-more-.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.smashingmagazine.com/2009/05/mac-hacks-17-applescripts-to-make-your-life-easier/" rel="noopener noreferrer"&gt;https://www.smashingmagazine.com/2009/05/mac-hacks-17-applescripts-to-make-your-life-easier/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://drago86.wixsite.com/scripting/scripts" rel="noopener noreferrer"&gt;https://drago86.wixsite.com/scripting/scripts&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>productivity</category>
      <category>applescript</category>
    </item>
    <item>
      <title>Best way to partition repetitive static html?</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Mon, 03 Dec 2018 15:25:17 +0000</pubDate>
      <link>https://forem.com/prnthh/best-way-to-partition-repetitive-static-html-1fgm</link>
      <guid>https://forem.com/prnthh/best-way-to-partition-repetitive-static-html-1fgm</guid>
      <description>&lt;p&gt;I want to make multiple pages for a site, and they all have common header and footer segments. What is the best way to write this code so I won't have to make the same change across multiple html files?&lt;/p&gt;

&lt;p&gt;I guess the modern approach is to go with React-router, declaring the repeated header and footer as components and then using something like Gatsby to render it server side. &lt;/p&gt;

&lt;p&gt;I also came across &lt;a href="https://handlebarsjs.com/"&gt;handlebars.js&lt;/a&gt; which appears to be what I'm looking for, but I want to  choose a method with the most minimal initial setup, or at least an environment that is easy to reproduce. &lt;/p&gt;

</description>
      <category>askdev</category>
    </item>
    <item>
      <title>Deploy Static Websites Instantly on dragdrop.site</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Wed, 21 Nov 2018 10:28:37 +0000</pubDate>
      <link>https://forem.com/prnthh/i-made-a-super-simple-static-site-hosting-service-44kp</link>
      <guid>https://forem.com/prnthh/i-made-a-super-simple-static-site-hosting-service-44kp</guid>
      <description>&lt;p&gt;I'm a huge fan of Glitch. I've used it at &lt;a href="https://glitch.com/@prnthh" rel="noopener noreferrer"&gt;countless hackathons&lt;/a&gt; to quickly host Node.js projects without having to worry about deploying a server, and the online editor with autosave has been an amazing way to work with teams when quickly building a prototype app. &lt;/p&gt;

&lt;p&gt;However, I took a web design class recently where were asked to host our project sites on the internet, but many of my peers had no experience with things like XAMPP and would constantly ask me for help.&lt;/p&gt;

&lt;p&gt;This lead me to create &lt;a href="http://dragdrop.site/" rel="noopener noreferrer"&gt;dragdrop.site&lt;/a&gt;. &lt;br&gt;
It's a simple service that lets you create a static website by dragging html, css and js files from your computer into the browser window. It instantly returns a new subdomain that looks like 'xyzab.dragdrop.site', which you can use to share your project with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbk552w207oz911nmhofl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbk552w207oz911nmhofl.jpg" alt="How to use dragdrop.site" width="600" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I guess a key benefit of doing it this way is that you can develop it locally on your favourite tools, and deploy it in a very visually distinct way. It worked great for my classmates. &lt;/p&gt;

&lt;p&gt;I encourage them to try services like Firebase to set up backend functions for forms ands stuff.&lt;/p&gt;

&lt;p&gt;I'm looking for some feedback and ideas to make the service more useful. I hope to add support for HTTPS using LetsEncrypt soon, as well as allowing users to pick their own subdomain names. Also eventually user accounts so you can switch between computers. Also eventually middleware if people want it. &lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>ELI5: a quantum web app (in Javascript)</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Fri, 16 Nov 2018 15:35:12 +0000</pubDate>
      <link>https://forem.com/prnthh/imagine-a-quantum-web-app-in-javascript-l2d</link>
      <guid>https://forem.com/prnthh/imagine-a-quantum-web-app-in-javascript-l2d</guid>
      <description>&lt;p&gt;&lt;em&gt;I was having a conversation with a friend who is studying Quantum Programming as a part of his Masters degree. As he described the concept of state entanglement to me, I started to feel like the concept is very close to Redux and state management on the web. So, I wrote this post to elaborate some of my thoughts.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a quantum programming language?
&lt;/h2&gt;

&lt;p&gt;A quantum programming language is really a specific type of machine code targeting a quantum computer, which is based on quantum mechanics compared to classical mechanics. &lt;/p&gt;

&lt;p&gt;A classical computer has a memory made up of bits, where each bit is represented by either a 0 or a 1. &lt;/p&gt;

&lt;p&gt;A quantum computer, on the other hand, maintains a sequence of qubits, which can represent a 0, a 1, or any quantum superposition of those two qubit states.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F61ktx7iozg418c6j5o90.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F61ktx7iozg418c6j5o90.jpg" alt="A classical bit vs. a qubit" width="620" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quantum computers may be able to efficiently solve problems which are not practically feasible on classical computers, and thanks to the Church–Turing thesis, we know that a classical computer can technically simulate a quantum algorithm.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Quantum Programming?
&lt;/h2&gt;

&lt;p&gt;IBM has unveiled it's cloud quantum computer for public use, Microsoft has revealed the Q# quantum programming language, and D-Wave Systems partnered with NASA to release the D-Wave-2. It looks like Quantum Computing is becoming a reality!&lt;/p&gt;

&lt;p&gt;Since quantum programming is based on quantum mechanics, it benefits from some of the cool phenomena associated with it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum entanglement&lt;/strong&gt; is a physical phenomenon which occurs when a group of particles interacts in ways such that the quantum state of each particle cannot be described independently of the state of the others, even when the particles are separated by a large distance. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u3590vnq1bzxzxjglo4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u3590vnq1bzxzxjglo4.gif" alt="Two particles share their state through quantum entanglement." width="500" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s say we have two particles A and B. Both particles are in superposition of possible states — in this case they both turn red and blue at the same time. If we measure the colour of A, and it picks red, and someone else an instant later measures B — B will always be blue.&lt;/p&gt;

&lt;p&gt;Entanglement means that somehow B knew, instantaneously, what A picked, regardless of the distance between A and B.&lt;/p&gt;
&lt;h2&gt;
  
  
  States in Web Applications
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zv8rakm27d5u0djok4v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zv8rakm27d5u0djok4v.jpg" alt="State management in a web application" width="404" height="433"&gt;&lt;/a&gt;&lt;br&gt;
In web applications today, we face a similar challenge in maintaining the same state on the front end and the back end. With growing use of various modern hacks such as Redux/Flux, it is clear that we need a more elegant solution to state management across physical distance.&lt;/p&gt;
&lt;h2&gt;
  
  
  Quantum State Entanglement
&lt;/h2&gt;

&lt;p&gt;How is the actual data represented? This is done based on a process called superdense coding. Superdense coding is a method of sending two traditional bits of information (00, 01, 10, or 11) using a single qubit.&lt;/p&gt;

&lt;p&gt;Lets assume the state of our web app is encoded into an array of such qubits. Our goal would be to entangle the state from the server side with the state on the client side.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We add the Hadamard gate (H) with 1 qubit for adding superposition property.&lt;/li&gt;
&lt;li&gt;We add Controlled-NOT gate (CX) , a two-qubit gate that flips the target qubit if the control is in state 1. This gate generates entanglement.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9tguyt19njqe4no2tc6x.png" alt="Attaining quantum entanglement of states." width="385" height="147"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The combination of these two quantum logic operations brings our pair of qubits to a Bell state.&lt;/p&gt;
&lt;h3&gt;
  
  
  Bell State
&lt;/h3&gt;

&lt;p&gt;The Bell states are specific quantum states of two qubits that represent the simplest examples of quantum entanglement. &lt;/p&gt;
&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;The following code can really only run on a quantum computer :P&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Assuming we have two qubits, qr[0] and qr[1]
# Add the H gate in the Qubit 1, putting this qubit in superposition.
qc.h(qr[1])

# Add the CX gate on control qubit 1 and target qubit 0, putting the qubits in a Bell state i.e entanglement
qc.cx(qr[1], qr[0])

# Add a Measure gate to see the state.
qc.measure(qr[0],cr[0])
qc.measure(qr[1],cr[1])

# Compile and execute the Quantum Program, since it needs to be simulated
results = qp.execute(['HelloWorldCircuit'], backend,timeout=2400)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quantum programming is still a highly theoretical field, and we won't really see the performance improvements from it until we build a much more practical quantum processor. However, I hope that being more aware of the paradigms makes you have more to worry about in your future work and projects. :D&lt;/p&gt;

</description>
      <category>quantum</category>
      <category>web</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Designing A Voting System For 1 Billion on the Blockchain (Part 2) - How To Keep A Secret</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Fri, 19 Oct 2018 12:32:56 +0000</pubDate>
      <link>https://forem.com/prnthh/designing-a-voting-system-for-1-billion-on-the-blockchain-part-2---how-to-keep-a-secret-1l1g</link>
      <guid>https://forem.com/prnthh/designing-a-voting-system-for-1-billion-on-the-blockchain-part-2---how-to-keep-a-secret-1l1g</guid>
      <description>&lt;p&gt;&lt;em&gt;This post is part two of a series about large scale voting on the Blockchain. In my &lt;a href="https://dev.to/prnthh/muchain---designing-a-voting-system-for-1-billion-on-the-blockchain---part-1-4ab1"&gt;previous post&lt;/a&gt;, we discussed what a large network would look like, and how consensus could be achieved with so many votes placed at the same time. This post focuses on how it works from the perspective of a single voter.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of the key features of Blockchain as we know it is the 'decentralised ledger', a public store of every single block that is synchronised across all participants. This system was traditionally designed to allow for data to be open and publicly verifiable, but this could have negative impacts on elections. For instance, being able to tally the votes privately before the election is finished could lead to confirmation bias in minds of the voters. &lt;/p&gt;

&lt;p&gt;Some of the key considerations from the voters' perspective are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Choice of candidate must remain secret&lt;/li&gt;
&lt;li&gt;Vote counting should be public and accountable&lt;/li&gt;
&lt;li&gt;Tamper proof by a third party&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The ancient system of dropping papers in a ballot box is really great at this. All the votes are mixed up in the box, no secret votes were present before they started, and at the end, all they have to do is count all the papers in public. One could add that thanks to VVPAT (Indian voting machines print each vote on a slip and drop them into a sealed box), one simply has to follow their vote until the counting rooms to be sure that their vote was indeed placed. Too bad they don't actually count the printed papers, and the error begins with the manual uploading of votes from each voting machine, 3840 votes at a time. Entire batches could be misrepresented or misplaced. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ATdFkLUJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qr3zhyuouqtslra98eeu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ATdFkLUJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qr3zhyuouqtslra98eeu.jpg" alt="The VVPAT machine printing out receipts."&gt;&lt;/a&gt;&lt;br&gt;
        &lt;em&gt;A VVPAT machine printing out a ballot&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The blockchain-based voting procedure could look a little like this:&lt;/p&gt;

&lt;h2&gt;
  
  
  A. EVM Initialisation
&lt;/h2&gt;

&lt;p&gt;In India, voters are each registered to areas known as constituencies, where they are allowed to cast a vote. This makes it much easier to verify that an individual exists on paper, something that becomes increasingly difficult in remote areas without active network connectivity. &lt;/p&gt;

&lt;p&gt;In the case of a Blockchain EVM, it would be initialised before the starting of each election. It receives a &lt;strong&gt;list of eligible voters&lt;/strong&gt; for that region, as well as a &lt;strong&gt;unique key&lt;/strong&gt; that is used to sign votes while casting them. This can be done at the last possible minute before elections begin, while network is still available. &lt;/p&gt;

&lt;h2&gt;
  
  
  B. Voter Authentication
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sVKfEYOD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e8inq9uy4e8o07pppoa0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sVKfEYOD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e8inq9uy4e8o07pppoa0.png" alt="Voter authentication on the blockchain."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a voter identifies themselves with a voter ID, it is verified against the local voter list. If the ID is present, a &lt;strong&gt;key-pair is generated&lt;/strong&gt; for the voter, with the 'opening' private key stored against their name and the public key used to encrypt or 'seal' their vote choice. This sealed choice is then stored on the local ledger, ready to be sent to the central voting nodes.&lt;/p&gt;

&lt;h2&gt;
  
  
  C. Vote Accumulation
&lt;/h2&gt;

&lt;p&gt;One of the biggest problems faced in India is the communication barrier experienced by people living in remote regions. Though network coverage has greatly improved, it still isn't reliable enough in remote areas to handle too much traffic. This is why the current EVMs still need to be physically shifted to the Election Commission for counting. &lt;/p&gt;

&lt;p&gt;With better connectivity, I suggest a more hybrid approach to this, where votes are &lt;strong&gt;stored in chunks locally&lt;/strong&gt; until a stable connection is established. Chunking votes also makes it harder to place individual fraudulent votes from a rogue machine. &lt;/p&gt;

&lt;h2&gt;
  
  
  D. Vote Casting
&lt;/h2&gt;

&lt;p&gt;When enough votes accumulate and a stable internet connection is established, a &lt;strong&gt;chunk of votes is pushed&lt;/strong&gt; to the delegated voting servers. These chunks are signed by the EVM with the key that was created during initialisation. The chunks can be sent to any of the available delegates, which can then add them to the longest available vote chain. &lt;/p&gt;

&lt;h2&gt;
  
  
  E. Vote Counting
&lt;/h2&gt;

&lt;p&gt;When the voting period is declared closed, a signal is sent from the voting servers to EVMs, requesting the 'opening' private keys for all the 'sealed' votes. Since votes from each constituency are grouped in chunks, it is easier to find chunks from a particular EVM and unseal all corresponding votes with the matching private keys. Any votes that were placed by unauthorised EVMs would remain unopened as they would be unable to send opening values to the voting servers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ManETZX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r1zxjvkjzg4xb41fsp4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ManETZX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r1zxjvkjzg4xb41fsp4k.png" alt="The whole process of placing a single vote."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the primary advantages of this method is that there is much more accountability for each vote, as the vote cannot be counted until the second round of confirmation when the votes are unsealed. Since the Voter ID is not sent back from the EVMs, it becomes impossible to associate the choice made and the voter ID from the perspective of the counting servers. &lt;/p&gt;

&lt;p&gt;Finally, the unsealed votes are counted and we can conclude how many votes were placed for each candidate.&lt;/p&gt;

&lt;p&gt;Of course, practical implementation of such a system could take a long time. We would need to design robust hardware, conduct practical tests, and address the fact that the new system would create a whole new set of vulnerabilities. The cost of manufacturing alone would encourage policy makers to prefer a solution which can be built on top of the existing voting infrastructure. However, I hope we can spark a conversation about how blockchain design concepts present us with a brand new way of building systems that are performant and secure at massive scale. &lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>opensource</category>
      <category>architecture</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Designing A Voting System For 1 Billion on the Blockchain (Part 1)</title>
      <dc:creator>Pranith Hengavalli</dc:creator>
      <pubDate>Wed, 10 Oct 2018 15:35:06 +0000</pubDate>
      <link>https://forem.com/prnthh/muchain---designing-a-voting-system-for-1-billion-on-the-blockchain---part-1-4ab1</link>
      <guid>https://forem.com/prnthh/muchain---designing-a-voting-system-for-1-billion-on-the-blockchain---part-1-4ab1</guid>
      <description>&lt;p&gt;The system of voting to (s)elect the the governing body of a nation is the core concept of Democracy. In the earliest of its forms, the Spartans would democratically elect their leaders by casting stones into marked bowls. Today, we use "cutting-edge" technology to conduct these vital election procedures, but since the prize at stake is control of the population, elections continue to be an easy target for a malicious candidate who is intent on seizing power. With the recent revival of Blockchain and increased interest in decentralisation, consensus and Merkle trees, perhaps we are now better equipped with techniques to solve large scale voting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Voting in the Past
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fnewsmobile.in%2Fwp-content%2Fuploads%2F2017%2F03%2FEVM_B_7122015.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fnewsmobile.in%2Fwp-content%2Fuploads%2F2017%2F03%2FEVM_B_7122015.jpg" alt="An EVM used in the Indian national elections."&gt;&lt;/a&gt;&lt;br&gt;
In India, nation-scale elections are conducted using an Electronic Voting Machine (EVM) that is distributed to various voting regions(we call them constituencies), spanning from large metropolitan cities to remote villages with no connectivity. Each machine can hold 3840 votes, and the voting machines are manually transported to the central voting commission for counting. This process is difficult and time consuming, and there have also been reports that the procedure is prone to manual error or intentional miscounting&lt;a href="https://www.firstpost.com/politics/how-does-india-count-its-millions-of-votes-all-you-need-to-know-1523733.html" rel="noopener noreferrer"&gt;1&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;More recently the Election Commission of India has devised a system called the 'Voter Verifiable Paper Audit Trail' (VVPAT), which involves the voter's choice being printed on a physical receipt which is displayed briefly before being dropped into a sealed box. This allows the voter to know that the vote was placed correctly and addressed previous concerns that votes were being cast to a default candidate on a potentially rigged machine. Further, the paper trail would add more accountability in the counting process, unless, somehow, a huge number of them were to go missing :^).&lt;/p&gt;

&lt;p&gt;The key benefits of this system are:&lt;br&gt;
a. The hardware is designed to be extremely robust, and can be run off a 6 volt alkaline battery even in remote regions without power.&lt;br&gt;
b. The polling is offline, and all machines are returned to the election commission who is responsible for preventing voter fraud.&lt;br&gt;
c. Indians have more faith in a paper verifiable system, as they feel purely software based solutions would be more vulnerable to manipulation.&lt;/p&gt;

&lt;p&gt;It doesn't stop there. Nepal, Bhutan, Namibia and Kenya have purchased India-manufactured EVMs with the intent of employing them in national elections. I begin to worry that being more reliant on labour-intensive manual counting processes might not be the best way forward. &lt;/p&gt;

&lt;p&gt;Further, the manual authentication method of physically identifying yourself in your registered voting constituency is also something that we should avoid, potentially allowing people to place votes for a candidate in their home state even if they are travelling, which can drastically increase voter turnout.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software Based Voting
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fv7f85emdhx93d746ksp0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fv7f85emdhx93d746ksp0.jpg" alt="A traditional software based voting architecture."&gt;&lt;/a&gt;&lt;br&gt;
In traditional voting systems, votes are cast on a client (either dedicated or through a website), and the choice is then submitted to a server where a central database keeps track of all the cast votes. Each individual vote is stored in the database, so it is possible to re-count all the votes, instead of merely tracking the votes with a counter for each candidate. This makes it easier to verify that no voter fraud has occurred, such that there were no duplicate votes or if a vote failed to be cast. Since votes are not placed until they are sent to the server, we can ensure that the server validates the voter's identity and choice to prevent fraud.&lt;/p&gt;

&lt;p&gt;While any of the more obvious security concerns of a software application could apply, some of the more domain-specific ones are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A single voting server would not be able to handle the load from many votes being placed at once. We would need to use sharding or allow voters to place votes to one of many servers.&lt;/li&gt;
&lt;li&gt;As the number of voting servers increase, it becomes more difficult to ensure that no duplicate votes are placed across servers.&lt;/li&gt;
&lt;li&gt;An attacker could spoof a voting machine's signature over the network and place unauthorised votes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why use the blockchain?
&lt;/h2&gt;

&lt;p&gt;Blockchain architecture provides great solutions to many of our key problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;High volume: Since voting is decentralised, votes can be placed across nodes on the network, without requiring a single central server taking all the load. &lt;/li&gt;
&lt;li&gt;Merkle trees: Can ensure that only the longest chain of verified votes is accepted, making it difficult to place unauthorised votes or to modify a vote that has already been placed.&lt;/li&gt;
&lt;li&gt;Redundancy: There are multiple exact replicas of the voting results, created at the time of voting. It would be necessary to fake a vote on all of the redundant servers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The original implementation of the Blockchain in Satoshi Nakamoto's Bitcoin used a technique called Proof of Work to add new blocks to the chain. This method requires all miners on the network to solve a difficult mathematical problem for a reward, while also adding all previous transactions to the chain. This can be very intensive, and one of my professors smugly told me that it would cost Rs. 250 to propagate a vote in a PoW blockchain across the nation.&lt;/p&gt;

&lt;p&gt;Consensus is the process of making sure that every node can agree on all the votes that have been placed, and that their ledgers are exactly the same and updated. Achieving faster consensus at scale is one of the problems in the spotlight of various ICOs and Cryptocurrency focused startups. This would lead to faster confirmation of transactions which could probably bring us one step closer to the perfect solution. Right now, it takes 15-30 minutes to confirm a Bitcoin transaction, which is a whole half hour of wondering if you sent it to the wrong address, or at least that much time in which the receiving party will have to wait before they can access it. Visa, in comparison, can handle an estimated 24,000 transactions per second. That's more like it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delegated Proof of Stake
&lt;/h2&gt;

&lt;p&gt;Delegated Proof of Stake (DPoS) is one of the faster consensus algorithms, as used by the EOS token. They claim to confirm 3,000 transactions a second across 21 'delegated' servers. The catch with Proof of Stake is that EOS doesn't aim to achieve consensus on all available nodes. In each confirmation round (known as an epoch), a random server is chosen to be the 'block producer', the node responsible for creating the new block and sending it to all the other delegates. The block producer then tallies all votes that were placed on it and sends it to every other delegate to confirm it. If any unauthorised node tries to propose a block out of turn, the block is rejected by it's peers since only the chosen delegate for each epoch is allowed to propose a block. &lt;/p&gt;

&lt;p&gt;A similar architecture can be proposed for voting, with the voting machines acting as regular nodes and a set of dedicated servers acting as delegates for vote confirmation.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqp8u0e1mo5dd7x1jhiot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqp8u0e1mo5dd7x1jhiot.png" alt="Delegated Proof of Stake applied to voting server nodes across the nation."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the network adds a block of votes to the chain, one of the ‘delegates’ is randomly chosen to confirm the validity of the votes that make up the current block. This block is then propagated to all the other delegates to achieve consensus on the votes that have been placed. A malicious actor would have to bypass the voter authentication method and successfully place the invalid vote on the randomly chosen delegate server. &lt;/p&gt;

&lt;p&gt;By distributing the vote confirmation effort across multiple delegates, we can evenly spread the load faced during balloting. Through deterministic selection of the block producer in each epoch, we can ensure that the system maintains redundancy in the case of certain delegates experiencing excess load or unexpected failure. In this manner we will design a fault tolerant system that will significantly streamline the balloting process.&lt;/p&gt;

&lt;p&gt;I've never really written a piece like this before, and I'm not too sure how to write a conclusion so I'm looking for suggestions and feedback :)&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://dev.to/prnthh/designing-a-voting-system-for-1-billion-on-the-blockchain-part-2---how-to-keep-a-secret-1l1g"&gt;part 2&lt;/a&gt;, we discuss the voting process, including voter authentication, biometric hashing, offline voting.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>opensource</category>
      <category>architecture</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
