Tag Archives: Java

Setting Up Eureka Server Using Spring Cloud (Part 1)

This is a quick example for setting up Eureka server using Spring Cloud.

You can download the whole project by using following link.

For this tutorial, we will be creating a New Maven Project. To keep thing more simple we will be creating a simple maven project i.e. we will be skipping archetype selection.

New Maven Project Wizard – Creating a simple project
Continue reading Setting Up Eureka Server Using Spring Cloud (Part 1)

Implementing JPEG Algorithm in Java

This Java code demonstrates the core steps of the JPEG compression algorithm. It implements the Discrete Cosine Transform (DCT), quantization, zigzag scan, and a simplified entropy encoding. These are fundamental processes for compressing digital images, reducing file size by transforming and encoding image data.

This example provides an educational look at the key stages of JPEG compression.

Continue reading Implementing JPEG Algorithm in Java

Demonstrating Transposition Cipher in Java

A transposition cipher is a method of encryption where the positions of characters are shifted according to a certain system, without changing the actual characters themselves. It rearranges the characters in a message to create ciphertext, and the same method in reverse restores the original message.

This post walks you through how a transposition cipher works using a Java program. This particular example arranges characters into a matrix and reads them column-wise (for encryption) or row-wise (for decryption).


How the Transposition Cipher Works

  1. Encryption:
    • Fill a matrix column-wise with characters of the message.
    • Read the characters row-wise to get the encrypted message.
    • The operation is repeated twice for added confusion.
  2. Decryption:
    • Reverse the above process by filling the matrix row-wise.
    • Read it column-wise to retrieve the original message.
Continue reading Demonstrating Transposition Cipher in Java

Java Program to Demonstrating RSA

In the world of cryptography, RSA (Rivest–Shamir–Adleman) is a popular public-key cryptosystem widely used for secure data transmission. It’s based on the principle that while multiplying large prime numbers is computationally easy, factoring their product is not — which ensures security.

This post will walk you through how RSA encryption and decryption work using a simple Java program. You’ll learn how the sender encrypts a message using the recipient’s public key, and how the receiver decrypts it using their private key.


What Happens Under the Hood?

The RSA algorithm follows these steps:

  1. Key Generation
    • Choose two large prime numbers p and q.
    • Compute N = p * q.
    • Compute the totient function: phi = (p-1)(q-1).
    • Choose an integer e such that 1 < e < phi and gcd(e, phi) = 1.
    • Compute d, the modular inverse of e modulo phi.
  2. Encryption
    • The sender uses the recipient’s public key (e, N) to compute ciphertext: c = m^e mod N.
  3. Decryption
    • The recipient uses their private key (d, N) to decrypt: m = c^d mod N.
Continue reading Java Program to Demonstrating RSA