I have been programming in C++ for a while now. I heard about RSA Encryption algorithm, and i have read many online sites on how it works. But i still cant grasp how the algorithm works. i have tried to make programs with RSA, but they doesnt encrypt.

If you could please explain the algorithm and how to use it in a program that encrypt files in c++ or c.

Thankyou...

:icon_neutral:

This is the exponentiation cypher, upon which RSA is based. Let's start with this.

Pick a prime number, p. Pick another prime number e (smaller than p), making sure that e and (p-1) are relatively prime.

Now, take your plaintext. Replace each letter by numerical equivalent (00 for A and 25 for Z would be one such method, for example - it's what I'll use, but if you want spaces and other symbols, you'll need something different) ending up with a two digit number for every letter.

Write these all out, and split them into blocks of length 2n (i.e. there are n letters in each block, and each block has 2n digits in). The number n is the largest possible integer such that the largest possible value of a block of length 2n is less than p.

i.e. if p is between 25 and 2525, then n would have to be one (such that the largest block value, which will be 2n long, which is two digits, is 25), and if p was greater than 2525 and less than 252525, then n would be 2 (making a largest block value, 2*n = 4 digits long, of 2525).

Take each of the blocks. Call a block P. The corresponding cypherblock is P^e (mod p).

This is the encryption side. When you've got that, I'll cover decryption :)

commented: extremely clear. +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.