# janagiram-kumar/cns-new architecture

> Architecture diagram of the GitHub repository janagiram-kumar/cns-new, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/janagiram-kumar/cns-new
- Repository: https://github.com/janagiram-kumar/cns-new

## Overview

#### Purpose and Execution Model
This is a collection of standalone Java cryptography exercises, organized by assignment (`EX1`–`EX7`). There is no shared application framework, build system, README guidance, or central launcher. Each class is expected to be compiled and run independently, likely through its own `main` method and console input/output.

#### Number-Theory Foundations
`EX1` contains the arithmetic primitives and primality testing used conceptually by later public-key exercises:
- Euclidean GCD variants: `EX1/GCD.java`, `EX1/GCDE.java`
- Extended Euclidean algorithm: `EX1/ExtendedEuclid.java`
- Euler totient computation: `EX1/EulerTotient.java`
- Miller–Rabin probabilistic primality testing: `EX1/MillerRabin.java`

These programs establish modular arithmetic, coprimality, inverses, and prime validation boundaries needed for RSA, Diffie–Hellman, and ElGamal.

#### Classical Cipher Implementations
`EX2` implements substitution and polyalphabetic cipher workflows, generally transforming plaintext to ciphertext and reversing the process from user-provided keys:
- `EX2/CaesarCipher.java`
- `EX2/VigenereCipher.java`
- `EX2/PlayfairCipher.java`
- `EX2/HillCipher.java`
- `EX2/OneTimePad.java`

The main boundary is text normalization and key handling: these algorithms operate on character sequences rather than shared domain models or persisted data.

#### Transposition Cipher Stage
`EX3` isolates positional rearrangement ciphers:
- `EX3/RailFenceCipher.java`
- `EX3/RowColumnTranspositionCipher.java`

Unlike substitution ciphers, these preserve character identities while changing ordering. They are independent console-oriented implementations, with no indicated integration into the `EX2` cipher classes.

#### Symmetric-Key Demonstration
`EX4/SDES.java` implements Simplified DES, representing the repository’s block-cipher / symmetric-encryption exercise. Its architecture is expected to center on bit-level permutation, key scheduling, round functions, and encrypt/decrypt control paths, rather than production DES interoperability.

#### Public-Key Key Agreement and Encryption
The public-key exercises separate major cryptographic roles:
- `EX5/RSA.java` covers RSA key construction and modular-exponentiation encryption/decryption.
- `EX6/DiffeHellman.java` models Diffie–Hellman key agreement between parties.

These components depend on externally supplied or generated numeric parameters; no certificate authority, keystore, network transport, or secure randomness infrastructure is represented in the tree.

#### Digital Signature Workflow
`EX7/ElGamalSignature.java` implements ElGamal signing and verification. It forms the repository’s authentication/integrity stage: private-key-based signature generation and public-parameter-based verification. Its trust boundary is the supplied message, key material, and domain parameters; there is no external identity service or persistence layer.

#### Runtime and Infrastructure Boundaries
The material runtime is Java source compiled directly with a JDK. The repository has no declared package hierarchy, dependency manager, test suite, service runtime, database, network API, or external cloud/service integration. Each exercise is therefore an isolated educational executable rather than a deployable cryptographic system.

Main entry points: [`EX1/MillerRabin.java`](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/MillerRabin.java) (Miller–Rabin), [`EX1/ExtendedEuclid.java`](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/ExtendedEuclid.java) (Extended Euclid), [`EX5/RSA.java`](https://github.com/janagiram-kumar/cns-new/blob/main/EX5/RSA.java) (RSA), [`EX1/GCD.java`](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/GCD.java) (GCD)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundations["EX1 Number Theory"]
  node_gcd["GCD<br/>console executable<br/>[GCD.java]"]
  node_gcde["Euclidean GCD<br/>console executable<br/>[GCDE.java]"]
  node_extended_euclid["Extended Euclid<br/>console executable"]
  node_totient["Euler Totient<br/>console executable<br/>[EulerTotient.java]"]
  node_miller_rabin["Miller–Rabin<br/>console executable<br/>[MillerRabin.java]"]
end

subgraph group_classical["EX2 Classical Ciphers"]
  node_caesar["Caesar Cipher<br/>console executable<br/>[CaesarCipher.java]"]
  node_vigenere["Vigenère Cipher<br/>console executable"]
  node_playfair["Playfair Cipher<br/>console executable"]
  node_hill["Hill Cipher<br/>console executable<br/>[HillCipher.java]"]
  node_one_time_pad["One-Time Pad<br/>console executable<br/>[OneTimePad.java]"]
end

subgraph group_transposition["EX3 Transposition"]
  node_rail_fence["Rail Fence Cipher<br/>console executable"]
  node_row_column["Row-Column Transposition<br/>console executable"]
end

subgraph group_symmetric["EX4 Symmetric Encryption"]
  node_sdes["S-DES Control<br/>console executable<br/>[SDES.java]"]
  node_key_schedule["Key Schedule<br/>S-DES layer"]
  node_round_function["Permutation &amp; Rounds<br/>S-DES layer"]
end

subgraph group_publickey["EX5–EX7 Public Key"]
  node_rsa["RSA<br/>console executable<br/>[RSA.java]"]
  node_diffie_hellman["Diffie–Hellman<br/>console executable<br/>[DiffeHellman.java]"]
  node_elgamal_signature["ElGamal Signature<br/>console executable"]
end

node_sdes -->|"derives round keys"| node_key_schedule
node_sdes -->|"encrypts / decrypts through"| node_round_function
node_key_schedule -->|"round keys"| node_round_function
node_gcd -.->|"extends coprimality arithmetic"| node_extended_euclid
node_extended_euclid -.->|"modular inverse foundation"| node_rsa
node_totient -.->|"key construction foundation"| node_rsa
node_miller_rabin -.->|"prime validation foundation"| node_rsa
node_gcd -.->|"number-theory foundation"| node_diffie_hellman
node_miller_rabin -.->|"prime parameter foundation"| node_diffie_hellman
node_extended_euclid -.->|"modular arithmetic foundation"| node_elgamal_signature
node_miller_rabin -.->|"prime parameter foundation"| node_elgamal_signature

click node_gcd "https://github.com/janagiram-kumar/cns-new/blob/main/EX1/GCD.java"
click node_gcde "https://github.com/janagiram-kumar/cns-new/blob/main/EX1/GCDE.java"
click node_extended_euclid "https://github.com/janagiram-kumar/cns-new/blob/main/EX1/ExtendedEuclid.java"
click node_totient "https://github.com/janagiram-kumar/cns-new/blob/main/EX1/EulerTotient.java"
click node_miller_rabin "https://github.com/janagiram-kumar/cns-new/blob/main/EX1/MillerRabin.java"
click node_caesar "https://github.com/janagiram-kumar/cns-new/blob/main/EX2/CaesarCipher.java"
click node_vigenere "https://github.com/janagiram-kumar/cns-new/blob/main/EX2/VigenereCipher.java"
click node_playfair "https://github.com/janagiram-kumar/cns-new/blob/main/EX2/PlayfairCipher.java"
click node_hill "https://github.com/janagiram-kumar/cns-new/blob/main/EX2/HillCipher.java"
click node_one_time_pad "https://github.com/janagiram-kumar/cns-new/blob/main/EX2/OneTimePad.java"
click node_rail_fence "https://github.com/janagiram-kumar/cns-new/blob/main/EX3/RailFenceCipher.java"
click node_row_column "https://github.com/janagiram-kumar/cns-new/blob/main/EX3/RowColumnTranspositionCipher.java"
click node_sdes "https://github.com/janagiram-kumar/cns-new/blob/main/EX4/SDES.java"
click node_rsa "https://github.com/janagiram-kumar/cns-new/blob/main/EX5/RSA.java"
click node_diffie_hellman "https://github.com/janagiram-kumar/cns-new/blob/main/EX6/DiffeHellman.java"
click node_elgamal_signature "https://github.com/janagiram-kumar/cns-new/blob/main/EX7/ElGamalSignature.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gcd,node_gcde,node_extended_euclid,node_totient,node_miller_rabin toneBlue
class node_caesar,node_vigenere,node_playfair,node_hill,node_one_time_pad toneAmber
class node_rail_fence,node_row_column toneMint
class node_sdes,node_key_schedule,node_round_function toneRose
class node_rsa,node_diffie_hellman,node_elgamal_signature toneIndigo
```

## Components

### EX1 Number Theory

Standalone arithmetic and primality exercises.

- [GCD](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/GCD.java): console executable · `EX1/GCD.java`
- [Euclidean GCD](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/GCDE.java): console executable · `EX1/GCDE.java`
- [Extended Euclid](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/ExtendedEuclid.java): console executable · Computes Bézout coefficients and modular inverses. · `EX1/ExtendedEuclid.java`
- [Euler Totient](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/EulerTotient.java): console executable · `EX1/EulerTotient.java`
- [Miller–Rabin](https://github.com/janagiram-kumar/cns-new/blob/main/EX1/MillerRabin.java): console executable · Probabilistic prime validation. · `EX1/MillerRabin.java`

### EX2 Classical Ciphers

Independent text and key driven cipher programs.

- [Caesar Cipher](https://github.com/janagiram-kumar/cns-new/blob/main/EX2/CaesarCipher.java): console executable · `EX2/CaesarCipher.java`
- [Vigenère Cipher](https://github.com/janagiram-kumar/cns-new/blob/main/EX2/VigenereCipher.java): console executable · `EX2/VigenereCipher.java`
- [Playfair Cipher](https://github.com/janagiram-kumar/cns-new/blob/main/EX2/PlayfairCipher.java): console executable · `EX2/PlayfairCipher.java`
- [Hill Cipher](https://github.com/janagiram-kumar/cns-new/blob/main/EX2/HillCipher.java): console executable · `EX2/HillCipher.java`
- [One-Time Pad](https://github.com/janagiram-kumar/cns-new/blob/main/EX2/OneTimePad.java): console executable · `EX2/OneTimePad.java`

### EX3 Transposition

Independent positional rearrangement ciphers.

- [Rail Fence Cipher](https://github.com/janagiram-kumar/cns-new/blob/main/EX3/RailFenceCipher.java): console executable · `EX3/RailFenceCipher.java`
- [Row-Column Transposition](https://github.com/janagiram-kumar/cns-new/blob/main/EX3/RowColumnTranspositionCipher.java): console executable · `EX3/RowColumnTranspositionCipher.java`

### EX4 Symmetric Encryption

Simplified DES demonstration.

- [S-DES Control](https://github.com/janagiram-kumar/cns-new/blob/main/EX4/SDES.java): console executable · Drives simplified block encryption and decryption. · `EX4/SDES.java`
- **Key Schedule**: S-DES layer · Derives round keys from supplied key bits.
- **Permutation & Rounds**: S-DES layer · Applies bit permutations and Feistel-style round processing.

### EX5–EX7 Public Key

Independent encryption, agreement, and signature exercises.

- [RSA](https://github.com/janagiram-kumar/cns-new/blob/main/EX5/RSA.java): console executable · Key construction plus modular-exponentiation encryption/decryption. · `EX5/RSA.java`
- [Diffie–Hellman](https://github.com/janagiram-kumar/cns-new/blob/main/EX6/DiffeHellman.java): console executable · Two-party shared-secret agreement from numeric parameters. · `EX6/DiffeHellman.java`
- [ElGamal Signature](https://github.com/janagiram-kumar/cns-new/blob/main/EX7/ElGamalSignature.java): console executable · Signs messages and verifies with public parameters. · `EX7/ElGamalSignature.java`

## Connections

- S-DES Control → Key Schedule: derives round keys
- S-DES Control → Permutation & Rounds: encrypts / decrypts through
- Key Schedule → Permutation & Rounds: round keys
- GCD → Extended Euclid: extends coprimality arithmetic
- Extended Euclid → RSA: modular inverse foundation
- Euler Totient → RSA: key construction foundation
- Miller–Rabin → RSA: prime validation foundation
- GCD → Diffie–Hellman: number-theory foundation
- Miller–Rabin → Diffie–Hellman: prime parameter foundation
- Extended Euclid → ElGamal Signature: modular arithmetic foundation
- Miller–Rabin → ElGamal Signature: prime parameter foundation
