The program adds the rest of the alphabet to the key.

After inputting the keyword we need to add on the rest of the alphabet to form the full key (as described in the Enciphering chapter). The algorithm for this task is:

    take each letter of the alphabet from the string called alphabet:
    convert it to upper case
    find out whether this letter is present in ‘key’
        if it is not present then add it to ‘key’

Here is the program code that you might like to try:

alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 'HYPNOTIZABLE'
length_key=len(key)
for j in range(26):
    present=0
    for k in range(length_key):
        if(alphabet[j].upper()==key[k]):
            present=1
    if(present==0):
        key=key+alphabet[j].upper()
print (key)

What is going on here? First of all, each letter of the alphabet is chosen and made into upper case and the variable 'present' is set to zero. Then the alphabet letter is compared with each letter in the keyword. If there is a match the variable 'present' is set to 1. After all keyword letters have been scanned, if 'present' is still zero then the alphabet letter is added to the key.

PREVIOUS          NEXT