Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 24fc561df0
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (32 sloc) 1.363 kb
# Transposition Cipher Encryption
# (BSD Licensed)
import pyperclip
def main():
myMessage = 'Common sense is not so common.'
myKey = 8
translated = encryptMessage(myKey, myMessage)
# Print the (encrypted) string in translated to the screen, with
# a | (called "pipe" character) after it in case there are spaces at
# the end of the encrypted message.
print(translated + '|')
# Copy the (encrypted) string in translated to the clipboard.
def encryptMessage(key, message):
# Each string in ciphertext represents a column in the grid.
ciphertext = [''] * key
# Loop through each column in ciphertext.
for col in range(key):
pointer = col
# Keep looping until pointer goes past the length of the message.
while pointer < len(message):
# Place the character at pointer in message at the end of the
# current column in the ciphertext list.
ciphertext[col] += message[pointer]
# move pointer over
pointer += key
# Convert the ciphertext list into a single string value and return it.
return ''.join(ciphertext)
# If is run (instead of imported as a module) call
# the main() function.
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.