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

Function generate_table

ciphers/playfair_cipher.py:39–58  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

37 return clean
38
39def generate_table(key):
40
41 # I and J are used interchangeably to allow
42 # us to use a 5x5 table (25 letters)
43 alphabet = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
44 # we're using a list instead of a '2d' array because it makes the math
45 # for setting up the table and doing the actual encoding/decoding simpler
46 table = []
47
48 # copy key chars into the table if they are in `alphabet` ignoring duplicates
49 for char in key.upper():
50 if char not in table and char in alphabet:
51 table.append(char)
52
53 # fill the rest of the table in with the remaining alphabet chars
54 for char in alphabet:
55 if char not in table:
56 table.append(char)
57
58 return table
59
60def encode(plaintext, key):
61 table = generate_table(key)

Callers 2

encodeFunction · 0.85
decodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected