![]() With that change, the code above decodes the message quickly.įurther improvements are possible, but more complicated, and won't be drop-in replacements. For instance, let’s say we have two peers communicating with each other in a channel secured by the RSA algorithm. One key is used for encrypting the message which can only be decrypted by the other key. So decrypt can be written as: def decrypt(kenc, d, n): Each pair of the RSA algorithm has two keys, i.e. ![]() 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. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do it. Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |