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

Function generate_table

ciphers/playfair_cipher.py:62–80  ·  view source on GitHub ↗
(key: str)

Source from the content-addressed store, hash-verified

60
61
62def generate_table(key: str) -> list[str]:
63 # I and J are used interchangeably to allow
64 # us to use a 5x5 table (25 letters)
65 alphabet = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
66 # we're using a list instead of a '2d' array because it makes the math
67 # for setting up the table and doing the actual encoding/decoding simpler
68 table = []
69
70 # copy key chars into the table if they are in `alphabet` ignoring duplicates
71 for char in key.upper():
72 if char not in table and char in alphabet:
73 table.append(char)
74
75 # fill the rest of the table in with the remaining alphabet chars
76 for char in alphabet:
77 if char not in table:
78 table.append(char)
79
80 return table
81
82
83def encode(plaintext: str, key: str) -> str:

Callers 2

encodeFunction · 0.70
decodeFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected