0

I want to make a Caesar cipher algorithm in Python and I have a list of 116 characters. If in a string I have z I want the z to be replaced by the character that is 7 char later on the right, in this case equals L:

x = [a,b,c,F,g,L,2,u'}',u'?',n,2,5,8...........,3,r,u'!',y,z,Z]
rook
  • 5,880
  • 4
  • 39
  • 51
mathieu
  • 55
  • 1
  • 8
  • 1
    Have you written any code? Note: making a variable named `list` is not a good idea – OneCricketeer Apr 14 '16 at 15:12
  • What have you tried so far? please post your code and a description of whats going wrong. – Will Apr 14 '16 at 15:13
  • 2
    The problem with not posting code is that we can't judge where you are at (other than the fact that you are still learning the language) so it is hard to make an answer which is appropriate for where you are on the learning curve. Any experienced Python programmer would solve this in about 3 lines of code -- but the resulting code is likely to prove cryptic to a beginner. – John Coleman Apr 14 '16 at 15:16
  • @John Coleman i was thinking to get the current position of the character and calcul the difference between the character position and the lenght of the list, and get the new character from the beginning of the list with the difference – mathieu Apr 14 '16 at 15:22
  • Sounds like a promising idea (although it can be streamlined with the `%` operator). Give it a try and edit your question when you have some code to ask about (or, better yet, delete this question and ask another only if needed). – John Coleman Apr 14 '16 at 15:25
  • Yep, the question is unclear, explain us what are you doing - deciphering a text message with a given cipher. Where is the cipher then? Where is the text message? – rook Apr 14 '16 at 15:30
  • http://stackoverflow.com/questions/8886947/caesar-cipher-function-in-python http://stackoverflow.com/questions/15327423/python-caesar-cypher http://stackoverflow.com/questions/18031520/caesar-cipher-python-additional-features – Bahrom Apr 14 '16 at 15:32
  • I think it is an educational task so during algorithm implementation he should learn how to deal with Python data types and etc. Caesar ciphering isn't the point.. – rook Apr 14 '16 at 15:34

1 Answers1

1

Take a look at this link here, there are plenty of examples. The Caesar cipher is one of the most common exercises in programming. So I guess you haven't researched a lot before you asked. In addition a data structure that might be of interest in python are dictionaries.

Bouramas
  • 1,077
  • 1
  • 17
  • 36