I need help with this program I am doing. I need to be able to select encrypt or decrypt(ive only done encrypt at the momment) and need to be able to select an offset here what ive got so far and I have a number of problems. http://imgur.com/a/N3Tul 1 is that it only cycles back around with lower case and does work with upper case, second is that I dont know if I should be using a while loop there and dont know why it isnt working and finally I can't set a key for some reason, because it thinks "1" is STR but if I put 1 with out "" it works but that mean I can't change it. I am new to python sorry if some of this is obvious.

Recommended Answers

All 2 Replies

First you have to define the limits of the character set. Are you using English/ASCII as other character sets have an extended range?

Do you want to encode special characters as well, @. ?. $ etc.

For your purposes, ASCII goes from decmal 32, space, through decimal 126, ~.

You can ask for an input from the user to get the offset. After the offset is applied, you then have to test if the resulting decimal value is < 32 or > 126 (for ASCII) depending on if it is encrypting or decrypting, and asjust accordingly. If it is < 32 then you possibly want to increase it by 95, which is the range of decimals used in the above example, 32...126.

Use the code tag in the header to paste your code here. It is not a good idea for us to go to some other site provided by a new poster as it can contain spam or worse.

Also, see "String to Integer" for typecasting the input string into an integer http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_2.6/Revenge_of_the_Strings

second is that I dont know if I should be using a while loop there

Don't know what "there" means, but generally a for loop is used if you mean traverse the string
for character in input_string:

One of the simpler Caesar ciphers can be done using Python's double-ended queue rotation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.