
-----------------------------------
Prince Pwn
Sun Jan 17, 2010 1:11 pm

Creating a New Seed for Random
-----------------------------------
What is it you are trying to achieve?
Changing my random seed inside the program.

What is the problem you are having?
I can manually change it in the code, encryptionKey = 15, but cannot change it when I execute the program, 4 - Change the Key.

Describe what you have tried to solve this problem
I've organized all my variables at the top and in my code, examined the code, and I'm stumped.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



/*
 Author:
 Program: Encryption v1.0
 Date:    1/17/2010
 */

View.Set ("graphics;nocursor")

var debug : boolean := false                            % Show debugging output
const ubound : int := 26                                % Size of alphabet
var encryptionKey : int := 15                           % Encryption key
var randNum : int                                       % Used to hold a random number
var encryptionLetter : array 1 .. ubound of char        % Stores each letter in order
var encryptionStorage : array 1 .. ubound of char       % Stores each letter perminantely
var alphabet : string := ""                             % Stores the alphabet perminantely
var encryptedAlphabet : string := ""                    % Stores the encrypted alphabet
var ch : char                                           % Used for character input in menu
var convertMessage : string                             % Message to convert
var message : string := ""                              % Message after conversion
var encryptedMessage : string                           % Encrypted message
var decryptedMessage : string                           % Decrypted message

for i : 1 .. ubound                                     % Counts the alphabet
    encryptionLetter (i) := chr (64 + i)                % Fills each letter uniquely and in order as capitals
    alphabet += encryptionLetter (i)                    % Fills the alphabet
end for

loop

    /* Main Menu */
    put "My Encryption Program"
    put "---------------------"
    put "1 - Encrypt a Message"
    put "2 - Decrypt a Message"
    put "3 - View the Key"
    put "4 - Change the Key"

    /* Makes user select an option */
    loop
        Input.Flush
        delay (0)
        Input.Flush
        ch := getchar
        exit when ch = '1' or ch = '2' or ch = '3' or ch = '4'
    end loop

    /* Encrypt a message */
    if ch = '1' then

        Rand.Set (encryptionKey)                % Starts a sequence of pseudo-random numbers
        message := ""                           % Blanks message
        encryptedMessage := ""                  % Blanks encrypted message

        for decreasing i : ubound .. 1                          % Counting alphabet backwards
            randNum := Rand.Int (1, i)                          % Sets random letter from 'a' to 'z,y,x...'
            encryptionStorage (i) := encryptionLetter (randNum) % Store random letter into storage
            encryptedAlphabet += encryptionStorage (i)          % Stores the alphabet randomly
            encryptionLetter (randNum) := encryptionLetter (i)  % Sets that random letter back where it cannot be reached on next loop
        end for

        if (debug) then
            put "\nAlphabet:\t\t\t\t", alphabet
            put "Encrypted Alphabet:\t\t\t", encryptedAlphabet, '\n' ..
            put "Generated an encryption key:\t\t", encryptionKey, '\n'
        end if

        put "\n>> Please enter a message to encrypt:\t" ..      % Prompts user input
        get convertMessage : *                                  % User input

        for i : 1 .. length (convertMessage)                                                % Scans through message to convert
            if ord (convertMessage (i)) >= 97 and ord (convertMessage (i)) = 65 and ord (message (i)) = 97 and ord (convertMessage (i))  90 then    % If character is anything but 'A' - 'Z'
                decryptedMessage += message (i)                         % Add to message
            end if
        end for

        /* Output for user */
        put ">> Decrypted Message:\t\t\t", decryptedMessage
        put "\nPress any key to continue..."
        Input.Pause
        cls

    elsif ch = '3' then

        /* View the key */
        put "\n>> Current encryption key: ", encryptionKey
        put "\nPress any key to continue..."
        Input.Pause
        cls


    elsif ch = '4' then

        /* Change the key */
        put "\n>> Current encryption key: ", encryptionKey
        put ">> Enter a new key: " ..
        get encryptionKey
        cls

    end if
end loop



Please specify what version of Turing you are using
4.1.1


Sorry if it's hard to read. I'm running on two 1680x1050 so I can read it all fine.
