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

Function prepare_input

ciphers/playfair_cipher.py:36–59  ·  view source on GitHub ↗

Prepare the plaintext by up-casing it and separating repeated letters with X's

(dirty: str)

Source from the content-addressed store, hash-verified

34
35
36def prepare_input(dirty: str) -> str:
37 """
38 Prepare the plaintext by up-casing it
39 and separating repeated letters with X's
40 """
41
42 dirty = "".join([c.upper() for c in dirty if c in string.ascii_letters])
43 clean = ""
44
45 if len(dirty) < 2:
46 return dirty
47
48 for i in range(len(dirty) - 1):
49 clean += dirty[i]
50
51 if dirty[i] == dirty[i + 1]:
52 clean += "X"
53
54 clean += dirty[-1]
55
56 if len(clean) & 1:
57 clean += "X"
58
59 return clean
60
61
62def generate_table(key: str) -> list[str]:

Callers 1

encodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected