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

Function decrypt

ciphers/brute_force_caesar_cipher.py:4–45  ·  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: str)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 1

findMethod · 0.45

Tested by

no test coverage detected