RSA Algorithm

RSA Algorithm

RSA is a cryptosystem for public-key encryption, and is widely used for securing sensitive data. It uses two different keys, one public and one private key. The Private key is kept in secret whereas Public key is shared with everyone. It provides a method of assuring the confidentiality of data. RSA is rather slow so it’s hardly used to encrypt data, more frequently it is used to encrypt and pass around symmetric keys which can actually deal with encryption at a faster speed.

Below is the sample on how the data is encrypted and decrypted with RSA.

Four Steps are required:

  1. Generate Public Key
  2. Generate Private Key
  3. Encrypt Data with Public Key
  4. Decrypt Data with Private Key

Generate Public Key:

  1. Select 2 prime numbers P & Q. Let’s say P = 53, Q = 59.
  2. Public Key(p)
PQ i.e 53 * 59 = 3127
  1. We also need a small exponent n’, this n must be

a). Be an integer

b). Not be a factor of p

c). 1<n<??(p), in this example n = 3 Our public key is made up of p & n, i.e 3127 & 3

Generate Private Key:

  1. We need to calculate ??(p)
??(p) = (P-1) (Q-1)
??(p) = (53-1) (59-1)
??(p) = 3016                     
  1. Now for calculating private key say d
d = (2(??(p))+1)/n

d = 2011 

(After putting all the value from above)Private key d  = 2011

Encrypt Data with Public Key:

Till now we have Public Key and Private Key, in this scenario Public Key is made up of p & n, i.e 3127 & 3. Our Private Key is d, i.e 2011.

Let’s encrypt ‘EG’. Convert the letters to number E= 5 and G = 7.Encrypt = 57?? mod 3127, here n = 3, so the result will be 700

Decrypt Data with Private Key:

Till now we have c = Encrypted Data n = Private key p = Public Key

Decrypt = c? mod p, 

Decrypt = 700? mod 3127, 

here n = 2011

After calculation decrypt = 57.

Now convert the number to their respective letters, i.e 5 = E, and 7 = G, So we have our result i.e EG.





要查看或添加评论,请登录

Aman Shekhar的更多文章

  • Key Points to Remember before developing an Android App.

    Key Points to Remember before developing an Android App.

    We have seen once the app is completed, then most of us indulge ourselves in code improvement, or fixing lints etc…

  • GARBAGE COLLECTOR

    GARBAGE COLLECTOR

    Before I dig deep into the topic, below are the few points to remember: Java provides automatic memory management…

  • Average of two Integer.MAX_VALUE (Integer Overflow )

    Average of two Integer.MAX_VALUE (Integer Overflow )

    Before we dive into the basic of computing average and give the answer as ((a+b)/2)), then I hate to say that, this…

    1 条评论
  • Out Of Memory Exception.

    Out Of Memory Exception.

    In Java, all objects are stored in the heap. Every Android developer must have encountered the OutOfMemoryError, also…

    2 条评论
  • Mastering the Coding Skills.

    Mastering the Coding Skills.

    In this blog I’m not going to explain, rather I’ll share the tips and sources which I’m using to improve my coding…

    1 条评论
  • ANDROID P: SNEEK PEEK

    ANDROID P: SNEEK PEEK

    Yesterday, Google announces the changes which is going to come in Android P. Below are few of the listed changes which…

  • Android Studio 3.0

    Android Studio 3.0

    At its I/O 2017 developer conference, Google today unveiled Android Studio 3.0, the latest version of its integrated…

  • OutOfMemory Error

    OutOfMemory Error

    OutOfMemoryError is the error which we get all the time. Whenever we get this error we generally think that our bitmap…

    1 条评论
  • Google announces Android O: Focus on power management, notifications, and more...

    Google announces Android O: Focus on power management, notifications, and more...

    As some had expected based on the timing of last year's Android N announcement, Android O was due sooner or later, and…

社区洞察

其他会员也浏览了