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

Function encryptMessage

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

Source from the content-addressed store, hash-verified

92
93
94def encryptMessage(message, key):
95 rails = getBlankRails(message, key)
96 railCoordinates = getRailCoordinates(message, key)
97
98 # Lay out the letters in rails:
99 messageIndex = 0
100 for x, y in railCoordinates:
101 rails[x][y] = message[messageIndex]
102 messageIndex += 1
103
104 # Read the letters going across the rails:
105 encryptedText = ''
106 for railNumber in range(key):
107 for x, y in railCoordinates:
108 if y == railNumber:
109 encryptedText += rails[x][y]
110
111 # Show the encrypted message to the user:
112 displayRails(rails)
113 print('The encrypted message (not including the right-side bar) is:')
114 print(encryptedText + '|')
115 copyIfPossible(encryptedText)
116
117
118def decryptMessage(message, key):

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