
-----------------------------------
1ahmadale
Wed Nov 13, 2019 10:27 am

I Need to Write a Program that Can Encrypt a Message Using the Enigma Word Method
-----------------------------------
/* 
Here is the information I have:

Enigma Word Method Uses a word for the shift Each letter of the word is used to shift the letters in the sentence
(a=1, b=2,… z=26) When the end of the word is reached, start back at the beginning

*/

* Here is my program so far. What should I fix it make it work?:


put ""

put " Input a sentence: " ..
var sentence : string
get sentence : *

put ""
put " The sentence is: ", sentence

var shift : int     % the number of positions to shift
var encryptedletter : string     % the encrypted letter
var encryptednumber : int     % the encrypted letter stored as an integer

put ""

put " Enter the encrypt key (a single word): " ..
var key : string     % the shift key (a word)
get key     % the letter a is a shift of 1 position, b is 2, c is 3,...

var len : int := length (sentence)
var len2 : int := length (key)
var a : int := 0

put ""
put " The encrypted sentence is: " ..

for positiona : 1 .. len2
    var charactera : string := key (positiona)

    shift := ord (charactera) - ord ("a") + 1

    var newshift := shift
    for position : 1 .. len
        var character : string := sentence (position)

        if (character >= "a" and character  len2) then
                newshift := shift
            end if
            encryptednumber := ord (character)     % If a character is a valid encrypt character (lowercase letter) the program will convert the letter into a number.
            encryptednumber := encryptednumber + newshift     % The program will shift the letter based on the encrypt key.
            if ((encryptednumber = 128) or (chr (encryptednumber) > "z")) then      % This if statement is used if the encrypted letter goes past "z".
                encryptednumber := encryptednumber - 26     % If the encrypted letter goes past "z", the program will wrap it back around to "a".
            end if     % This command instructs the program to end the if statement.
            encryptedletter := chr (encryptednumber)     % This command converts the encrypted number back into an encrypted letter.
            newshift := newshift + 1

            if (a < len) then
                put encryptedletter .. % This command is used to display the encrypted letter.
            end if
        end if         % This command instructs the program to end the if statement.

    end for     % This command instructs the program to end the for loop.
end for
