We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,845 Members — Technology Publication meets Social Media

# Need help with making a RSA encryption program.

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:

2
Contributors
1
1 Hour
Discussion Span
1 Year Ago
Last Updated
3
Views
MasterHacker110
Junior Poster
179 posts since Dec 2011
Reputation Points: 6
Skill Endorsements: 0

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 :)

Moschops
Practically a Posting Shark
887 posts since Sep 2008
Reputation Points: 297
Skill Endorsements: 5

Post: Markdown Syntax: Formatting Help

You
View similar articles that have also been tagged: