In any case, you might want to swap the keys and values in your dictionary: right now your find_key might as well be using a list, as you're simply searching over all the k,v pairs until you find a match. As well, if you want to turn a letter into a number, and you don't really care what number, you could use the "ord"/"chr" functions, and not even need a dictionary. The following aren't bugs, but suggestions: you should probably use pow(c,d,n) rather than (c**d)%n for large numbers the former will be much faster. You want modInverse(e, phi(n)), not modInverse(e, n) see this worked example.Īfter fixing those, it seems to work for me. (4) You're taking the wrong multiplicative modular inverse. (3) Your alpha should be alpha (otherwise you'll get "96llo, worl5"). (2) You also don't check to see that p != q. Getting a composite will lead to problems. Q = random.choice(primes_range(Low, High))Ĭhar_array.append(encrypt_byte(alpha], e, n)) P = random.choice(primes_range(Low, High)) The code: import fractions, sys, random, math I decided to write a simple RSA encryption implementation in Python, but every time I run it it prints the error Inde圎rror: list out of range when it's decrypting and in find_key.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |