![]() This means that someone who doesn't know D can't easily find it, and the encryption is secure. However, someone who knows just the public key only knows N=PQ to get P and Q from there, he'd need to factor N, which is hard. ![]() We could find D from E easily because we know M, which depends on knowing P and Q. Therefore the decryption actually does reverse the encryption. This means that (A E) D = A DE ≡A M+1≡A mod N. It's a basic result in number theory that if N and M are defined as above, then A M≡ 1 mod N. To decrypt text, encrypt it using D instead of E. Compute A^E mod N for each block, giving the encrypted version of that block.Divide it into blocks which are encoded as integers A, 1The pair (E,N) is the public key, and (D,N) is the private key.Find E's inverse mod M: an integer D such that DE ≡ 1 mod M.Take a random integer E, 1We find two large primes P and Q, and find N=PQ which will be used as a modulus.The other two functions could easily be part of rsakey() they're isolated here for clarity, and because they're somewhat useful on their own rprime() generates a random prime, and extgcd() is the extended Euclidean Algorithm.įirst, here is a description of how RSA works. Two of them are necessarily independent: rsakey() is used to generate a public and private key, and rsa() is used to encrypt or decrypt. The code for this program is divided into four parts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |