MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / decrypt

Function decrypt

ciphers/brute_force_caesar_cipher.py:2–44  ·  view source on GitHub ↗

>>> decrypt('TMDETUX PMDVU') Decryption using Key #0: TMDETUX PMDVU Decryption using Key #1: SLCDSTW OLCUT Decryption using Key #2: RKBCRSV NKBTS Decryption using Key #3: QJABQRU MJASR Decryption using Key #4: PIZAPQT LIZRQ Decryption using Key #5: OHYZOPS KHYQP Decr

(message)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 1

findMethod · 0.80

Tested by

no test coverage detected