MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / main

Class main

Caesar_Cipher/Caesar_cipher.py:1–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class main:
2 def __init__(self,key:dict) -> None:
3 self.key = key
4
5 def get_input(self) -> None:
6 while True:
7 blank_string = str(input("Enter string to decrypt: "))
8 if blank_string.isalpha():
9 blank_string = blank_string.lower()
10 self.blank_string = blank_string
11 break
12 else:
13 print("Input is not valid")
14 continue
15
16 def encrypt_string(self) -> str:
17 output = ""
18 for c in self.blank_string:
19 for k,v in self.key.items():
20 if k == c:
21 output += v
22 else:
23 continue
24 self.decrypted_string = output
25 return(output)
26
27 def decrypt_string(self, string: str) -> str:
28 output = ""
29 string = string.lower()
30 string = string.strip()
31 if string == "":
32 return(self.blank_string)
33 else:
34 for c in string:
35 for k,v in self.key.items():
36 if v == c:
37 output += k
38
39 return(output)
40
41if __name__ == "__main__":
42 key ={"a": "d", "b": "e", "c": "f", "d": "g", "e": "h", "f": "i", "g": "j", "h": "k", "i": "l", "j": "m", "k": "n", "l": "o", "m": "p", "n": "q", "o": "r", "p": "s", "q": "t", "r": "u", "s": "v", "t": "w", "u": "x", "v": "y", "w": "z", "x": "a", "y": "b", "z": "c"}

Callers 1

Caesar_cipher.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected