
-----------------------------------
uknowhoiam
Thu Dec 18, 2008 8:27 pm

encrypting codes
-----------------------------------
my question that i have to answer is this

.  Write a program to read in a phrase and encrypt this phrase using a basic ?Caesar? cipher. Caesar realized that messages could be hidden in encrypted text. He sent messages by shifting characters to encrypt the messages contents. Your program will read in a phrase and encrypt the phrase. The user will choose the character shift or a random number can be chosen for the character shift (between 1 and 25) .The original and encrypted phrases must be printed out.

This is what i got so far..

var phrase : string := ""
var number, char_shift, word, encrypt : int := 0


put "Enter a phrase"
get phrase : *
put "Enter a character shift"
get char_shift

% This loop will repeat untill the end of the phrase
for count : 1 .. length (phrase)

    encrypt := encrypt - 1
    % Encrypt will equal to the phrase in an integer value

    encrypt := ord (phrase (count))
    % if encrypt is 'space' then ..

    if encrypt = 32 then
        % encrypt will be subtracted by char_shift

        encrypt := encrypt - char_shift
        % If encrypt is capital z then..
    elsif encrypt = 90 then
        % encrypt will go back and will be before A

        encrypt := 64
        % If encrtpy is z then..
    elsif encrypt = 122 then
        %encrypt will go back and will be before a
        encrypt := 96
    end if
    %word will equal encrypt and will add the char_shift
    word := encrypt + char_shift
    put chr (word) ..
end for


my problem is that, when encrypt is over lowercase z then it goes further in the ascii code (w/e is after z)
what i want is that i want it to go to capital A instead of going further

im stuck :(  anyone want to help me :)

Mod Edit: Remember to use syntax tags! Thanks :) [syntax="Turing"]Code Here[/syntax]

-----------------------------------
Insectoid
Thu Dec 18, 2008 8:57 pm

RE:encrypting codes
-----------------------------------
perhaps 'if ord (letter) > ord(z) then however many characters it is past z + A'?. That made sense to me, but I doubt I explained it well. 

You need to find out how far a letter is past ascii z and then add that much -1 to ascii A. So say it is at ascii 124, it is 2 more than z, so add 2-1 to A, to get a capital B. Remember that there is a few ascii characters between Z and a. 

Oh, and Turing uses ansii (not that it makes too much difference).

-----------------------------------
uknowhoiam
Fri Dec 19, 2008 3:53 pm

RE:encrypting codes
-----------------------------------
ugh i handed my program in so now it doesnt matter if i edit it, but my teacher said it doesnt really matter if i get this question wrong cuz it is really hard, she wont cut marks off

-----------------------------------
syntax_error
Fri Dec 19, 2008 8:34 pm

RE:encrypting codes
-----------------------------------
Now you have 2 weeks(ish) to fix it, and learn if you wish to.

-----------------------------------
Tyr_God_Of_War
Fri Dec 19, 2008 9:10 pm

Re: encrypting codes
-----------------------------------



    elsif encrypt >= 90 then
        % encrypt will go back and will be before A

        encrypt :=encrypt-26


Would that work?

-----------------------------------
SNIPERDUDE
Sat Dec 20, 2008 10:46 am

Re: encrypting codes
-----------------------------------



    elsif encrypt >= 90 then
        % encrypt will go back and will be before A

        encrypt :=encrypt-26


Would that work?

You could of just as easily made this line
encrypt := encrypt - 26
this
encrypt -= 26

for future reference.  You just put the character before the equal so you don't have to repeat the variable name.  So for example multiplying the variable Test by 3 would look like this:
Test *= 3
