LailaTabourit / RSA-Factoring-Challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RSA Image

RSA Factoring Challenge

RSA-Factoring-Challenge is a repository dedicated to exploring the fascinating world of RSA encryption and decryption. RSA (Rivest-Shamir-Adleman) is the most widely used public-key cryptography algorithm globally, renowned for its robust security and versatility.

Introduction

RSA is not just an encryption algorithm; it also serves as a foundation for digital signatures and key exchange. Developed in the 1970s by Ron Rivest, Adi Shamir, and Len Adleman, RSA revolutionized the field of cryptography by leveraging the difficulty of factoring large numbers.

How RSA Works

RSA utilizes a public-key cryptosystem, employing two keys: a public key and a private key. The public key, known to everyone, is used for encryption, while the private key, held only by the owner, enables decryption. The asymmetric nature of RSA means that the encryption and decryption keys are distinct.

To generate RSA keys, two large prime numbers (p and q) are selected. The modulus (n) is calculated as the product of p and q. Additionally, the totient of n (φ(n)) is computed as (p-1)(q-1).

An integer e is chosen, satisfying the conditions 1 < e < φ(n) and gcd(e, φ(n)) = 1, where gcd(a, b) denotes the greatest common divisor of a and b. This e is referred to as the public exponent and is used for encryption.

The final step is determining d such that ed = 1 mod φ(n). d, known as the private exponent, is used for decryption.

Encryption and Decryption

With the RSA keys established, the message can be encrypted and decrypted. Encryption involves the computation of the ciphertext (c) using the following formula:

c = m^e mod n

Here, c represents the ciphertext, m denotes the message to be encrypted, and e is the public exponent.

To decrypt the ciphertext, the following formula is used:

m = c^d mod n

Here, m signifies the decrypted message, c represents the ciphertext, and d is the private exponent.

Tasks:

This repository contains a program for factorizing numbers into a product of two smaller numbers. The challenge includes two tasks: factorizing arbitrary numbers and the RSA Factoring Challenge. The program can run without any dependencies and has a time limit of 5 seconds.

Task 0: Factorize all the things!

The task is to factorize as many numbers as possible into a product of two smaller numbers. The program takes a file containing natural numbers to factor, with one number per line. The numbers in the file are assumed to be valid natural numbers greater than 1, and there will be no empty lines or spaces before/after the valid number. The output format for each factorization is n = p * q (where n is the input number and p, q are the factors).

Usage

To run the program for Task 0, use the following command:

factors <file>

Replace <file> with the path to the file containing the numbers to factor.

Example

Input file (numbers.txt):

15
21
35

Output:

15 = 3 * 5
21 = 3 * 7
35 = 5 * 7

Task 1: RSA Factoring Challenge

RSA Laboratories states that for each RSA number n, there exist prime numbers p and q such that n = p × q. The challenge is to find these two primes given only n. This task is similar to Task 0, but with the following differences:

  • p and q are always prime numbers.
  • There is only one number in the input file.

The goal is to factorize the given number in less than 5 seconds.

Repository Contents

This repository contains the following files:

  1. factors: The executable program for both Task 0 and Task 1.
  2. README.md: This readme file providing an overview of the repository and its contents.

Feel free to explore the code and use it to participate in the RSA Factoring Challenge or factorize other numbers as required.

Conclusion

RSA remains the most widely adopted public-key algorithm due to its robust security and versatility. While it relies on the difficulty of factoring large numbers, the algorithm is not without weaknesses. Safeguarding the private key and employing a reliable random number generator are crucial to ensuring its strength.

Discover the power of RSA encryption and decryption, and unlock the realm of secure communication and data protection.

Resources

To delve deeper into the realm of RSA, consider exploring the following resources:

Note: This repository is intended for educational purposes and should not be used for production systems without proper security considerations.

About