Posted: Thu Dec 18, 2008 8:27 pm Post subject: 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..
Turing:
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 =32then % encrypt will be subtracted by char_shift
encrypt := encrypt - char_shift
% If encrypt is capital z then.. elsif encrypt =90then % encrypt will go back and will be before A
encrypt :=64 % If encrtpy is z then.. elsif encrypt =122then %encrypt will go back and will be before a
encrypt :=96 endif %word will equal encrypt and will add the char_shift
word := encrypt + char_shift
putchr(word)..
endfor
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
code:
[syntax="Turing"]Code Here[/syntax]
Sponsor Sponsor
Insectoid
Posted: Thu Dec 18, 2008 8:57 pm Post subject: 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
Posted: Fri Dec 19, 2008 3:53 pm Post subject: 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
Posted: Fri Dec 19, 2008 8:34 pm Post subject: RE:encrypting codes
Now you have 2 weeks(ish) to fix it, and learn if you wish to.
Tyr_God_Of_War
Posted: Fri Dec 19, 2008 9:10 pm Post subject: Re: encrypting codes
Turing:
elsif encrypt >= 90then % encrypt will go back and will be before A
encrypt :=encrypt-26
Would that work?
SNIPERDUDE
Posted: Sat Dec 20, 2008 10:46 am Post subject: Re: encrypting codes
Tyr_God_Of_War @ December 19th 2008 wrote:
Turing:
elsif encrypt >= 90then % encrypt will go back and will be before A
encrypt :=encrypt-26
Would that work?
You could of just as easily made this line
Turing:
encrypt := encrypt - 26
this
Turing:
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: