|
1 |
| -message = input("Encrypted message: ") |
2 |
| -LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 1 | +def decrypt(message): |
| 2 | + """ |
| 3 | + >>> decrypt('TMDETUX PMDVU') |
| 4 | + Decryption using Key #0: TMDETUX PMDVU |
| 5 | + Decryption using Key #1: SLCDSTW OLCUT |
| 6 | + Decryption using Key #2: RKBCRSV NKBTS |
| 7 | + Decryption using Key #3: QJABQRU MJASR |
| 8 | + Decryption using Key #4: PIZAPQT LIZRQ |
| 9 | + Decryption using Key #5: OHYZOPS KHYQP |
| 10 | + Decryption using Key #6: NGXYNOR JGXPO |
| 11 | + Decryption using Key #7: MFWXMNQ IFWON |
| 12 | + Decryption using Key #8: LEVWLMP HEVNM |
| 13 | + Decryption using Key #9: KDUVKLO GDUML |
| 14 | + Decryption using Key #10: JCTUJKN FCTLK |
| 15 | + Decryption using Key #11: IBSTIJM EBSKJ |
| 16 | + Decryption using Key #12: HARSHIL DARJI |
| 17 | + Decryption using Key #13: GZQRGHK CZQIH |
| 18 | + Decryption using Key #14: FYPQFGJ BYPHG |
| 19 | + Decryption using Key #15: EXOPEFI AXOGF |
| 20 | + Decryption using Key #16: DWNODEH ZWNFE |
| 21 | + Decryption using Key #17: CVMNCDG YVMED |
| 22 | + Decryption using Key #18: BULMBCF XULDC |
| 23 | + Decryption using Key #19: ATKLABE WTKCB |
| 24 | + Decryption using Key #20: ZSJKZAD VSJBA |
| 25 | + Decryption using Key #21: YRIJYZC URIAZ |
| 26 | + Decryption using Key #22: XQHIXYB TQHZY |
| 27 | + Decryption using Key #23: WPGHWXA SPGYX |
| 28 | + Decryption using Key #24: VOFGVWZ ROFXW |
| 29 | + Decryption using Key #25: UNEFUVY QNEWV |
| 30 | + """ |
| 31 | + LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 32 | + for key in range(len(LETTERS)): |
| 33 | + translated = "" |
| 34 | + for symbol in message: |
| 35 | + if symbol in LETTERS: |
| 36 | + num = LETTERS.find(symbol) |
| 37 | + num = num - key |
| 38 | + if num < 0: |
| 39 | + num = num + len(LETTERS) |
| 40 | + translated = translated + LETTERS[num] |
| 41 | + else: |
| 42 | + translated = translated + symbol |
| 43 | + print("Decryption using Key #%s: %s" % (key, translated)) |
3 | 44 |
|
4 |
| -message = message.upper() |
| 45 | +def main(): |
| 46 | + message = input("Encrypted message: ") |
| 47 | + message = message.upper() |
| 48 | + decrypt(message) |
5 | 49 |
|
6 |
| -for key in range(len(LETTERS)): |
7 |
| - translated = "" |
8 |
| - for symbol in message: |
9 |
| - if symbol in LETTERS: |
10 |
| - num = LETTERS.find(symbol) |
11 |
| - num = num - key |
12 |
| - if num < 0: |
13 |
| - num = num + len(LETTERS) |
14 |
| - translated = translated + LETTERS[num] |
15 |
| - else: |
16 |
| - translated = translated + symbol |
17 |
| - |
18 |
| - print("Decryption using Key #%s: %s" % (key, translated)) |
| 50 | +if __name__ == '__main__': |
| 51 | + import doctest |
| 52 | + doctest.testmod() |
| 53 | + main() |
0 commit comments