0

I'm trying to implement the RSA encryption/decryption algorithm on a text of String. However, everything I have found online either uses Cipher, or they are performing the algorithm on an integer. Could anybody give me a simple guide for implementing this on for example, a sentence? I prefer not to use Cipher or any other libraries because I want to know how it works.

Edit: Thanks for the help everyone. I finally got it to work :)

3
  • Why not have a search on SO, I've found a few questions with this already implemented, such as stackoverflow.com/questions/5818842/… Commented Mar 16, 2013 at 8:27
  • Thanks for that. Oddly enough that did not come out when I searched. All the ones I saw were using Cipher or some other libraries :)) Commented Mar 16, 2013 at 8:31
  • no problems, glad to help Commented Mar 16, 2013 at 9:01

2 Answers 2

1

The best thing for you to do would be to get fimiliar with the algorithm itself. Wikipedia has decent explanation on it. Then you need to implement modular operations. When you accomplish the above simply treat a message you want to encrypt as a number (rather big number in fact) and follow the operations described in wiki. A sentence (or any other character sequence) can be treated as a number as its just sequence of bytes.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes I have read the wikipedia article already. Based on that, I was already able to generate the public keys and private keys and I am able to encrypt and decrypt integers. In converting the string, do I just convert it to a big integer? Also, how do you convert the number back to a string?
To convert character sequence to a big integer simply iterate over it and with each character shift the current value of result by 8 bits left and then add the current character value. To convert the result back to the string do it the other way round: do bitwise and operation with number you are converting with mask 0xFF. Then prepend resulting number as character value to the result and shift the converted number 8 bits right.
This is of course the big endian way. For little endian you need to iterate converted string backwards and instead of prepending append exteacted characters.
0

RSA all depends on the large prime numbers and how they are very hard to factor. For further knowledge on the subject I'm gonna give you two resources that will explain the algorithm in further depth. I would recommend writing down which variables/methods you will want to create in java to stay organized.

Here are resources:

YouTube Clip which Explains the premise of the algorithm: RSA Cipher Explained

More Interactive Slide Explanation: RSA Algorithm Slide Show

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.