Evgeny Piratinsky
This is my college project, which demonstrates how cryptographic practices can be applied to a voting system. The system assumes we have voters and centers responsible for counting votes. Using multiple counting centers ensures voter anonymity and prevents collusion among centers to manipulate vote results. Voters can only choose between two candidates. To avoid political discussions, let's assume we're simulating the US political system where the only candidates are Democrats and Republicans. In our project, we store the keys of voting centers and voters as regular files within the system. In reality, such data would be stored as key-cards and election invitations.
Implemented using ZKP with a private-public key pair (RSA encryption). We encrypt a "master phrase" using the public key (election invitation) and decode it using the private key (key-card for voting). This ensures only authorized voters in the database with valid public keys can vote.
Also implemented using ZKP with RSA encryption. If someone has already voted, the encrypted master phrase is stored in the database, preventing them from voting again.
Implemented using RSA encryption. Each vote is encrypted using the public key of the voting center and can only be decrypted with the corresponding private key. The database only stores the selected candidate, not the voter's identity. To ensure encrypted votes look different, we use OAEP, adding random data to the encrypted information.
Due to the implementation of point 2, no one can vote on behalf of someone else.
All the above functions ensure accurate vote counting. Each counting center has its private key, unknown to others. Votes are decrypted using this key for counting.
Implemented using digital signatures (RSA encryption). This cryptographic mechanism allows creating a "signature" for data using a private key. Anyone with the corresponding public key can verify the data's integrity and sender's authenticity.
All the above functions ensure the system's robustness against third-party interference. For verification convenience, an interface thirdparty.py has been implemented, which includes SQL queries to the database (in case of a breach).
Main functions for program operation.
Executes SQL query and returns the result.
Aesthetic function to clear the console.
Formats error messages. Takes an error text and returns a rich-panel displaying the error.
Returns a list of all voting centers.
Returns a list of all candidates.
Fetches a voter using their passport number.
Fetches a voting center using its ID.
Function for voting. Takes the voter's passport number, serialized private key, candidate ID, and voting center ID.
Function for vote tallying. Takes voting center ID and its private key. Conducts necessary checks, counts votes, records results in the "tally_results" table, and signs the results using a digital signature.
This function serves multiple purposes: it displays voting results in a user-friendly format and verifies center signatures, ensuring vote results in the database remain unaltered.
Displays voting results in the console in plain text (for simulation purposes).
SQLite DB settings file. Contains a single function, db_setup(), to create database tables according to schemas.
Generates data in the database. Contains the data_generation() function, which populates the database with random and preset data.
Functions for cryptography.
Generates a master phrase for ZKP implementation. It's a unique 32-byte random sequence.
Generates public and private keys. Returns both keys.
Serializes the private key. Returns a byte stream.
Serializes the public key similarly.
Digitally signs voting results using the private key of the counting centers. Returns the signature in base64 format.
Verifies the signature. Returns True if genuine, and False if altered.
Encrypts the vote. Returns the encrypted vote in base64 format.
Decrypts the vote.
Implements the voting simulation. Contains the voting_simulation() function, which sequentially goes through all voting stages.
Implements the program's main logic. Deletes the current database, removes current private keys, recreates the database, populates it with random data, and then conducts a voting simulation.
Voter interface. A console application with a simple graphic interface to cast votes. Contains the menu() function for information display, input, and processing.
Interface for vote counting centers. A console application to count votes and display results.
Displays voting results for each center and overall results in a table format.
Main interface function for information display, input, and processing.
"Third-party" file. A console application to directly query the database and receive responses.
Queries the database, returns the result or a formatted error message.
Main interface function for information display, input, and processing.
-
Clone the repository (use these commands in the terminal):
git clone https://github.com/piratinskii/votes_project.git
cd votes_project
-
(Optional) Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the program
python interface.py
orpython3 interface.py