Encrypting a Message
FUNCTION – def encrypt(plaintext):
It is likely that a message of more than 1 character will be used. Thus, a way to repeatedly encode a single character and move the wheel is needed. That sounds like a loop to me, a for loop to be exact.
Pertinent bits of code
#Encrypt each letter in the plaintext string.
for o_char in plaintext:
#Substitute '.' with 'X'.
if o_char == '.':
o_char = 'X'
#Encrypt this character.
e_char = transformChar(o_char, selectedWheel, pointer)
#Do something if the character was encrypted ok.
if len(e_char) > 0:
block += 1
if block > blocksize:
cipher += ' ' #Add a space after a block of blocksize characters.
block = 1 #Remembering the character that was blocksize+1.
cipher += e_char #Add the character to the result.
pointer = (pointer + increment)%26 #Turn the wheel, using mod 26 to stay within circle.
Notice the extra code to replace full stops with “X” characters before encoding.
Also notice how the output is formed into fixed size blocks of blocksize. This is another technique used to further hide the words.