MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / decryptMessage

Function decryptMessage

src/gamesbyexample/railfencecipher.py:118–139  ·  view source on GitHub ↗
(message, key)

Source from the content-addressed store, hash-verified

116
117
118def decryptMessage(message, key):
119 rails = getBlankRails(message, key)
120 railCoordinates = getRailCoordinates(message, key)
121
122 # Lay out the letters on the rails:
123 messageIndex = 0
124 for railNumber in range(key):
125 for x, y in railCoordinates:
126 if y == railNumber:
127 rails[x][y] = message[messageIndex]
128 messageIndex += 1
129
130 # Read the letters in rail order:
131 decryptedText = ''
132 for x, y in railCoordinates:
133 decryptedText += rails[x][y]
134
135 # Show the decrypted message to the user:
136 displayRails(rails)
137 print('The decrypted message is:')
138 print(decryptedText)
139 copyIfPossible(decryptedText)
140
141
142# If this program was run (instead of imported), run the game:

Callers 1

mainFunction · 0.70

Calls 4

getBlankRailsFunction · 0.85
getRailCoordinatesFunction · 0.85
displayRailsFunction · 0.85
copyIfPossibleFunction · 0.85

Tested by

no test coverage detected