0% found this document useful (0 votes)
24 views17 pages

Modular Arithmetic Calculator Project

The document outlines a project titled 'Modular Arithmetic Calculator' developed by students of DIT University as part of their coursework in Number Theory and Cryptology. The calculator, implemented using Python and PySide6, performs key number theory operations such as GCD, modular inverse, Euler’s totient function, and the Chinese Remainder Theorem, featuring a user-friendly GUI. The project highlights both theoretical understanding and practical application of modular arithmetic in cryptography, alongside acknowledgments and a candidate declaration.

Uploaded by

shrutichand47
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views17 pages

Modular Arithmetic Calculator Project

The document outlines a project titled 'Modular Arithmetic Calculator' developed by students of DIT University as part of their coursework in Number Theory and Cryptology. The calculator, implemented using Python and PySide6, performs key number theory operations such as GCD, modular inverse, Euler’s totient function, and the Chinese Remainder Theorem, featuring a user-friendly GUI. The project highlights both theoretical understanding and practical application of modular arithmetic in cryptography, alongside acknowledgments and a candidate declaration.

Uploaded by

shrutichand47
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Number Theory and

Cryptology
(CSN352)
BACHELOR OF

TECHNOLOGY
In
COMPUTER SCIENCE AND ENGINEERING

Session 2025-26

SUBMITTED TO: SUBMITTED BY:


DEEKSHANT SEMWAL Gaurav Bisht ID:1000020243
ASSITANT PROFESSOR Ronak Negi ID: 1000021293
SCHOOL OF COMPUTING Mohd. Mujtaba Tanveer ID:1000021413
DIT UNIVERSITY Piyush Sapehia ID:1000021301
SECTION:P

SCHOOL OF COMPUTING DIT


UNIVERSITY, DEHRADUN
(State Private University through State Legislature Act No. 10 of 2013
of Uttarakhand and approved by UGC)
Mussoorie Diversion Road, Dehradun, Uttarakhand - 248009, India.

August-December 2025
ACKNOWLEDGMENT
We would like to express our sincere gratitude to Mr Deekshant
Semwal , Assistant Professor, School of Computing, DIT University,
for his valuable guidance and support throughout this project. His
insightful feedback and encouragement have been instrumental in the
successful completion of our work.

We also extend our appreciation to DIT University for providing us


with the necessary resources and a conducive learning environment to
work on this project.

Lastly, we would like to acknowledge the efforts and dedication of our


team members, Gaurav Bisht, [Link] Tanveer, Ronak Negi,
and Piyush Sapehia, whose collaborative efforts made this project
possible.

Project Title: Modular Arithmetic Calculator

Submitted By:

Gaurav Bisht (SAP ID: 1000020243)


[Link] Tanveer (SAP ID: 1000021)
Ronak Negi (SAP ID: 1000021293)
Piyush Sapehia (SAP ID: 1000021301)

Submitted To:

Mr. Deekshant Semwal

Assistant Professor

School of Computing

DIT University
Candidate declaration

I hereby certify that the work ,which is being presented in the report
entitled “Modular Arithmetic Calculator”, in partial of the
requirement Part of the course as part of Number theory and
cryptology of the degree of the bachelor of technology in computer
science and submitted to the DIT University is an authentic record of
my work carried out during the period under the guidance of
[Link] Semwal.

Date: 18- November- 2025 Signature


Project Report
Title: Modular Arithmetic Calculator using Python and GUI (PySide6)

Course: Number Theory & Cryptology

Students: Gaurav Bisht , Mohd Mujtaba Tanveer,Ronak Negi, Piyush Sapehia

SAP ID: 1000020243,1000021413,1000021293,1000021301

Objective

Introduction / Definition of Topic

Project Methodology

Critical Analysis

Strengths of the Project

Weaknesses of the Project

Overall Evaluation

Limitations

Scope for Optimization

Real-World Applications

Complete Code & Explanation

Conclusion

Final Learning Outcomes


The objective of this project is to design and implement a Modular Arithmetic
Calculator capable of solving important number theory operations such as:

• Greatest Common Divisor (GCD)


• Modular Inverse
• Euler’s Totient Function φ(n)
• Chinese Remainder Theorem (CRT)

The calculator includes a graphical user interface (GUI) using PySide6,


ensuring clear input, readable step-by-step solutions, and visually appealing
output.

2. Introduction / Definition of Topic

Modular arithmetic is a foundational concept of number theory, widely


applied in:

• Cryptography
• Hash functions
• Digital signatures
• Blockchain
• Error-correcting codes

Operations like GCD, totient, modular inverse, and CRT form the backbone of
modern cryptosystems such as RSA, Diffie-Hellman, and ECC.

This project implements these operations in Python with detailed algorithmic


steps to improve conceptual understanding.

The methodology followed:

Step 1 — Mathematical Algorithms


Each component was implemented using classical number theory
algorithms:

• Euclidean Algorithm for GCD


• Extended Euclidean Algorithm for modular inverse
• Prime factorization approach for φ(n)
• Standard CRT recombination formula for two congruences

Step 2 — GUI Development

The GUI was created using PySide6, focusing on:

• Input validation
• Dynamic field hiding (totient requires one input, CRT requires four)
• Modern dark-themed UI
• Highlighted colors for clarity

Step 3 — Integration

Each algorithm outputs:

• Final computed value


• Step-by-step explanations

The GUI displays these results clearly to help students understand the logic.

The project successfully integrates computational number theory with an


interactive GUI. The step-by-step breakdown of algorithms helps visualize the
internal working of mathematical procedures.

Key observations:

• Algorithms work efficiently even for large inputs.


• GUI dynamically adapts to the selected operation.
• Error handling prevents invalid or incomplete inputs.

The project balances both academic and practical usability.


• Accurate implementation of core number theory algorithms
• Attractive, user-friendly GUI
• Step-by-step algorithmic explanation improves learning
• CRT support makes it suitable for cryptography demonstrations
• Clean interface with color-coded elements
• Handles invalid inputs gracefully

• Only supports two congruences for CRT


• Totient not optimized for extremely large numbers
• GUI does not include formula visualization (graphs or diagrams)
• No support for batch processing or file input

The project successfully demonstrates practical understanding of modular


arithmetic and cryptographic computations. The GUI enhances usability and
is polished enough for academic presentations.

Overall, it is a strong combination of mathematics, coding, and UI design,


suitable for a university-level submission.

• Performance decreases when numbers exceed 109


• CRT works only for coprime moduli
• Lacks support for RSA key generation or encryption
• Limited to deterministic algorithms

• Improve φ(n) using a precomputed sieve


• Add support for multiple congruences (generalized CRT)
• Include cryptographic extensions like RSA demonstration
• Add dark/light theme toggle
• Animate steps visually using charts or blocks
• Integrate performance profiling

10. Real-World Applications

This project directly applies to:

• Cryptography (RSA, Diffie-Hellman, ECC)


• Computer security
• Blockchain smart contract arithmetic
• Digital signature algorithms
• Hash functions
• Network protocol mathematics (TLS handshake operations)
• Error detection/correction mechanisms
from [Link] import QApplication, QWidget, QVBoxLayout, QLabel,
QLineEdit, QPushButton, QTextEdit, QComboBox

from [Link] import QFont, QRegularExpressionValidator,


QRegularExpression, QColor, QTextCharFormat

import sys

def gcd_steps(a, b):

s=[]

while b!=0:

[Link](f"gcd({a}, {b}) → {a} = {b} * ({a//b}) + {a%b}")

a,b=b,a%b

[Link](f"Final gcd = {a}")

return a,"\n".join(s)

def mod_inverse(a,m):

s=[]

t,nt=0,1

r,nr=m,a

[Link](f"Initial: r={r}, new_r={nr}, t={t}, new_t={nt}")

while nr!=0:

q=r//nr

[Link](f"q = {q}")

r,nr=nr,r-q*nr

t,nt=nt,t-q*nt

[Link](f"Updated: r={r}, new_r={nr}, t={t}, new_t={nt}")


if r>1:

return None,"Inverse does not exist because gcd(a, m) ≠ 1"

if t<0:

t+=m

[Link](f"Inverse = {t}")

return t,"\n".join(s)

def totient(n):

r=n

s=[f"φ({n}) computation:"]

p=2

t=n

while p*p<=t:

if t%p==0:

[Link](f"Prime factor found: {p}")

while t%p==0:

t//=p

r- =r//p

p+=1

if t>1:

s- append(f"Prime factor found: {t}")

r-=r//t

[Link](f"φ = {r}")

return r,"\n".join(s)

def crt(a1,n1,a2,n2):

st=[]
[Link](f"Solving: x ≡ {a1} (mod {n1}), x ≡ {a2} (mod {n2})")

g,_=gcd_steps(n1,n2)

if g!=1:

return None,"CRT requires moduli to be coprime."

inv,inv_s=mod_inverse(n1,n2)

[Link](inv_s)

x=(a1+(a2-a1)invn1)%(n1*n2)

[Link](f"Solution: x = {x}")

return x,"\n".join(st)

class ModularCalculator(QWidget):

def __init__(self):

super(). init ()

[Link]("Modular Arithmetic Calculator")

[Link]("background-color: #1e1e1e; color: white;")

l=QVBoxLayout()

title=QLabel("Modular Arithmetic Calculator")

[Link](QFont("Arial",20))

[Link]("color: cyan;")

[Link](title)

[Link]=QComboBox()

[Link](["GCD","Modular Inverse","Totient","CRT (Chinese


Remainder Theorem)"])

[Link](self.update_fields)

[Link]("background-color:#333;color:#FFD700;padding:
6px;border-radius:6px;")
[Link]([Link])

self.input1=QLineEdit(); [Link]("Enter number 1")

[Link](self.input1)

self.input2=QLineEdit(); [Link]("Enter number 2")

[Link](self.input2)

self.mod_input=QLineEdit(); self.mod_input.setPlaceholderText("Enter
modulus")

[Link](self.mod_input)

self.a2_input=QLineEdit(); self.a2_input.setPlaceholderText("Enter a2 for CRT")

[Link](self.a2_input)

self.n2_input=QLineEdit(); self.n2_input.setPlaceholderText("Enter n2 for CRT")

[Link](self.n2_input)

self.compute_btn=QPushButton("Compute + Show Steps")

self.compute_btn.setStyleSheet("background-
color:#444;color:#FFD700;padding:8px;border-radius:6px;")

self.compute_btn.[Link]([Link])

[Link](self.compute_btn)

[Link]=QTextEdit()

[Link](True)

[Link]("background-color:#111;color:#0f0;")

[Link]([Link])

[Link](l)

self.update_fields()

def update_fields(self):

m=[Link]()
[Link]()

if m=="Totient":

[Link]()

self.mod_input.hide()

self.a2_input.hide()

self.n2_input.hide()

elif m=="GCD":

[Link]()

self.mod_input.hide()

self.a2_input.hide()

self.n2_input.hide()

elif m=="Modular Inverse":

[Link]()

self.mod_input.show()

self.a2_input.hide()

self.n2_input.hide()

elif m=="CRT (Chinese Remainder Theorem)":

[Link]()

self.mod_input.hide()

self.a2_input.show()

self.n2_input.show()

def compute(self):

m=[Link]()

try:

a=int([Link]())
except:

[Link]("Invalid input.")

return

if m=="GCD":

try: b=int([Link]())

except: [Link]("Enter valid second number."); return

r,s=gcd_steps(a,b)

[Link](f"GCD = {r}\n\nSteps:\n{s}")

elif m=="Modular Inverse":

try: mod=int(self.mod_input.text())

except: [Link]("Enter a valid modulus."); return

inv,s=mod_inverse(a,mod)

[Link](f"Inverse = {inv}\n\nSteps:\n{s}")

elif m=="Totient":

phi,s=totient(a)

[Link](f"φ({a}) = {phi}\n\nSteps:\n{s}")

elif m=="CRT (Chinese Remainder Theorem)":

try:

n1=int([Link]())

a2=int(self.a2_input.text())

n2=int(self.n2_input.text())

except:

[Link]("Invalid CRT inputs.")

return

sol,s=crt(a,n1,a2,n2)
[Link](f"x = {sol}\n\nSteps:\n{s}")

if __name__=="__main__":

app=QApplication([Link])

w=ModularCalculator()

[Link](500,600)

[Link]()

[Link]([Link]())

Brief Explanation of Code


1. Core Mathematical Functions

• gcd_steps() computes GCD using the Euclidean Algorithm.


• mod_inverse() uses Extended Euclidean Algorithm to find modular
inverse.
• totient() finds φ(n) by prime factorization.
• crt() solves two simultaneous congruences.

2. GUI Components

• PySide6 widgets create a minimal yet modern interface.


• Dynamic field hiding ensures users only see inputs relevant to the
selected operation.
• Color-coded output enhances readability.

3. Error Handling

• Prevents invalid integer entries.


• Handles non-coprime moduli in CRT.

This project successfully integrates number theory algorithms with GUI design
to create a functional and educational modular arithmetic calculator. It
demonstrates both theoretical understanding and practical implementation
skills required in modern cryptology.
The clean step-by-step breakdown makes it an excellent teaching tool while
also being technically sound for cryptographic computations.

After completing this project, the following outcomes were achieved:

• Strong understanding of Euclidean and Extended Euclidean algorithms


• Practical application of Euler’s Totient Function
• Deep conceptual clarity about Chinese Remainder Theorem
• Hands-on GUI development skills using PySide6
• Ability to integrate mathematical logic with software engineering
• Improved debugging, validation, and user-interface design
• Understanding how modular arithmetic powers modern cryptography
Project Outputs:
1)

2)

3)

You might also like