RSA Encryption
Sam Kennedy


#1 May 19, 2012
I've been looking into RSA encryption today, and I'm *just* managing to grasp the concept of it (I have a feeling if I sneeze I will forget it all again!)

I've written a program to simulate RSA encryption (according to the steps on the wikipedia page: )

An example output:

p = 628232
q = 1166625
Public Key:(n = 732911157000, e = 13912169)
Private Key:(n = 732911157000, d = 480742768793)
Enter Message to Encrypt: test
Encrypted Message:

As you can see, the string 'test' being encrypted to '…mk…' could easily be cracked, since it's basically a substitution cipher, how could I make the encryption more secure?

At the minute I take the ascii values of the characters, raise them to the power of e, then modulus by n.

If an outsider wanted to crack the key by brute force, would the number of iterations required be the value of d? Since they will already know 'n' since it's part of the public key.

If anyone can tell, is my program calculating everything correctly?

Thank You :)
-Sam Kennedy

Reading, UK

#2 Jun 23, 2013

First for e (except if you're forced to take 13912169), take 3 or 7 instead (or another small prime number). e is public, so don't care about its value. That's better to take a little one. It makes the encryption faster.

Secondly, yes your encryption method is bad. If I've well understood what you did, you took the ascii value of ®t®, so 116. Then you did 116^e mod N. After that you took the ascii value of e, 101, and you did 101^e mod N. And so on.

That's not like that you should have prosseed. Because as you wrote, it makes RSA be a substitution algorithm. Which is very bad.

You should have done:

Letters ASCII decimal ASCII hex
t 116 0x74
e 101 0x65
s 115 0x73
t 116 0x74

You need to transform ®test® into a number, not 4 numbers.
Hence, using the ascii representation of each letters, you build a big number.

So you build, M = 116 + 101*256 + 115*256^2 + 116*256^3.
Each letters are coded on 1 byte, that's why I multiplied them by a power of 256.
And you do C = M^e mod N. And now your encrytion is no longer a substitution.

C is a number. So, decompose it ®in 256 basis® as M to get each bytes. Those bytes are the ascii values of the ciphertext as 116, 101... were for ®test®.

Tell me when this thread is updated:

Subscribe Now Add to my Tracker

Add your comments below

Characters left: 4000

Please note by submitting this form you acknowledge that you have read the Terms of Service and the comment you are posting is in compliance with such terms. Be polite. Inappropriate posts may be removed by the moderator. Send us your feedback.

Cryptography Discussions

Title Updated Last By Comments
What is this and can I decode it? Mar 20 MRE1 1
Galaxy Cipher Instrument open sourced. Mar 18 Russell Lee 1
AEAD encryption Schemes Mar 12 mogambo 1
Help - Crazy Cipher Feb '17 InBetweenHonor 1
Is this a real secuirty concern? Feb '17 nawas 1
LYRA 2 or sponge constructor Feb '17 golda 1
Vigenere Cipher Expansion Feb '17 cusar2 1
More from around the web