Last active
December 16, 2015 11:28
-
-
Save TheEmpty/5427120 to your computer and use it in GitHub Desktop.
PGP Example (using static values)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def crypt(mod, key, data, hashes = 50): | |
| encrypted = [] | |
| for v in data: | |
| for i in range(0, hashes + 1): | |
| v = (v ** key) % mod | |
| encrypted.append(v) | |
| return list(map(int, encrypted)) | |
| # My keys (p and q are intermediates) | |
| p = 11 | |
| q = 43 | |
| my_mod = p*q | |
| my_public = 23 | |
| my_private = 1187 | |
| p, q = None, None | |
| # Your keys | |
| p2 = 97 | |
| q2 = 89 | |
| you_mod = p2*q2 | |
| you_public = 17 | |
| you_private = 497 | |
| p2, q2 = None, None | |
| # (you)'s super secret message | |
| message = input("Your secret message: ") | |
| # Now represented as their indexies on the ASCII table | |
| data = list(map(ord, str(message))) | |
| # Now (you) is going to send the message | |
| # first they encrypt the message with my public key | |
| encrypted = crypt(my_mod, my_public, data) | |
| # then (you) sign it, so I know it came from (you) | |
| # and not someone else that has my public key | |
| signed = crypt(you_mod, you_private, encrypted) | |
| print("\n") | |
| print("=== YOU (SENDER) ===") | |
| print("message =", message) | |
| print("data =", data) | |
| print("encrypted =", encrypted) | |
| print("signed =", signed) | |
| print("") | |
| # Then you send me signed. | |
| # Now I unsign it, by crypting it with your pub | |
| unsign = crypt(you_mod, you_public, signed) | |
| # Now I decrypt it by using my private key | |
| msg2 = crypt(my_mod, my_private, unsign) | |
| print("====== RECIVER =====") | |
| print("signed =", signed) | |
| print("unsigned =", unsign) | |
| print("unencrypted =", msg2) | |
| print("message =", ''.join(list(map(chr, msg2)))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refrence: http://www.dongrays.com/btd/crypt-how.html