Git Product home page Git Product logo

linear-congruential-generator's Introduction

Linear Congruential Generator (LCG)

This repository contains a Java implementation of a Linear Congruential Generator (LCG), a type of pseudorandom number generator. The LCG is commonly used for generating a sequence of randomized numbers with a specified range.

Features

  1. LCG: The LCG class includes a constructor that sets the modulus, multiplier, increment, and seed parameters for the generator. The next() method is used to generate the next number in the sequence.
  2. Prime Number Generation: The program includes a method isPrime(int n) that checks if a number is prime. It also includes a method getNthPrimeFromLcg(Lcg lcg, int n) that generates the nth prime number from the LCG sequence.
  3. Text Encryption and Decryption: The program includes methods encrypt(String plainText) and decrypt(String base64EncodedValue) that use the LCG to encrypt and decrypt text strings.

Usage

To use the LCG, create an instance of the LCG class with the desired parameters. The next() method can then be used to generate the next number in the sequence.

To find the nth prime number in the LCG sequence, use the getNthPrimeFromLcg(Lcg lcg, int n) method.

To encrypt a text string, use the encrypt(String plainText) method. The output will be a Base64 encoded string. To decrypt the encoded string, use the decrypt(String base64EncodedValue) method.

In the main method, an example usage of the LCG is shown. An instance of the LCG class is created, and the 100th prime number in the LCG sequence is found. A text string is then encrypted and decrypted.

Example Output

The 100th prime number in the LCG sequence is: 62311
Original text: Hello, world!
Encrypted text: U0dWdlkyZGxZV1JzYjJsa1BJQmpiR0ZqZEhKaFkzVnliR2xqYkc5aFpDQT0=
Decrypted text: Hello, world!

linear-congruential-generator's People

Contributors

adamkeidz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.