![]() With that change, the code above decodes the message quickly.įurther improvements are possible, but more complicated, and won't be drop-in replacements. So decrypt can be written as: def decrypt(kenc, d, n): You could implement it yourself, but Python handily provides a built-in function for this: pow(x, e, n) There is a simple remedy: use modular exponentiation, which keeps the size of the numbers that it is working with low throughout the whole calculation by reducing modulo n as it goes along. This does not finish in a reasonable time. Key = RSA.generate(1024, random_generator) For example, trying it out with 1024bit RSA (the lowest setting!): import Crypto Kenc**d is in general a very big number that takes a long time to compute, and then it takes a long time again to reduce it modulo n. ![]() There is a serious problem with this implementation: it computes kenc**d. In this case though, there is a much more efficient solution that is about equally simple, and is probably sufficient. python rsa Share Improve this question Follow asked at 17:08 CoderMan 35 8 try utf-8 encode/decode kj-crypto at 17:13 unfortunately, this still returns unable to decrypt CoderMan at 17:17 (publicKey, privateKey) rsa. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do it. You should generate one keypair and use the private and public halves of that pair. Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks. These keys dont match and thus dont work.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |