Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'arguments': 0.07; 'key.': 0.07; 'meantime,': 0.07; 'suppose': 0.07; 'accepts': 0.09; 'cipher': 0.09; 'corresponds': 0.09; 'explanation': 0.09; 'help"': 0.09; 'key)': 0.09; 'okay': 0.09; 'url:faqs': 0.09; 'def': 0.10; 'volunteer': 0.11; 'assume': 0.11; 'dec': 0.15; '"key"': 0.16; '*why*': 0.16; 'alphabet': 0.16; 'comma,': 0.16; 'encryption': 0.16; 'exclamation': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'harsh,': 0.16; 'jobs.': 0.16; "john's": 0.16; 'merit,': 0.16; 'so!': 0.16; 'subject:String': 0.16; 'this).': 0.16; 'url:catb': 0.16; 'world;': 0.16; 'string': 0.17; 'wrote:': 0.17; 'working.': 0.17; 'input': 0.18; 'putting': 0.20; 'help.': 0.22; "i'd": 0.22; 'this:': 0.23; "haven't": 0.23; 'seems': 0.23; 'header:In-Reply- To:1': 0.25; 'creating': 0.26; 'skip:" 20': 0.26; 'am,': 0.27; '(we': 0.27; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.27; 'actual': 0.28; 'run': 0.28; 'post': 0.28; 'key,': 0.29; 'letter.': 0.29; "i'm": 0.29; "we're": 0.30; 'becomes': 0.30; 'basic': 0.30; 'function': 0.30; 'code': 0.31; 'asking': 0.32; 'problem.': 0.32; 'help,': 0.32; 'received:209.85.160.46': 0.32; 'space,': 0.32; 'material': 0.33; '11,': 0.33; 'to:addr:python- list': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'clear': 0.35; 'certificate': 0.35; 'fail': 0.35; 'so,': 0.35; 'too.': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'next': 0.35; 'but': 0.36; 'url:org': 0.36; 'programmers': 0.36; "didn't": 0.36; 'enough': 0.36; 'two': 0.37; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'you.': 0.61; '(that': 0.62; 'details': 0.63; 'skip:n 10': 0.63; 'more': 0.63; 'great': 0.64; 'here': 0.65; 'our': 0.65; 'importantly,': 0.65; 'kids,': 0.65; 'sound': 0.65; 'subject': 0.66; 'fact,': 0.69; 'sounds': 0.71; 'honest': 0.75; 'yourself': 0.77; 'prompt': 0.78; 'truck': 0.84; 'working,': 0.84; 'world!"': 0.84; 'you/your': 0.84; 'cryptography': 0.91; 'roads': 0.91; 'this;': 0.91; 'have.': 0.95; 'incredibly': 0.96; 'subject:..': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=X9EaZr5L7eFJC7ZuT1vYJZDPJtt2Gk/ODtYZhiyfy78=; b=i00PqyV91hqkJw0/w2oVWL02W8d3yUNLipxZ9f0pMYjqOIHg3uQtEwb6M467B02DJt 38S0ttarIlmx+0rMzar2omvo+t4YDH5SKVE5wiBWViWEMFKPEhnhHf0BsEgh+fPaKkjI Sz3JS6xvY78aBvd2EA1Nbew8oepMxloITnkGrw+kbATq1tOeM/uNn610lecyrkCm8okj 3k6BKl+HlOJzSc73YhaybMp023L5TDWxUYPK32H45oxZCIAws6OlMqWhifOa58nRNBZh FVirOVjvqAR9GB/bg9bTOXyN63jJ+yXm8CVGVScvXZymWhrsFsZDDZ9gBWtKAqP16jVS jj0w== MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 11 Dec 2012 10:36:12 +1100 Subject: Re: String manipulation in python..NEED HELP!!!! From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355182575 news.xs4all.nl 6880 [2001:888:2000:d::a6]:34816 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34581 On Tue, Dec 11, 2012 at 9:38 AM, wrote: > I need help with a program i am doing. it is a cryptography program. i am= given a regular alphabet and a key. i need to use the user input and use t= he regular alphabet and use the corresponding letter in the key and that be= comes the new letter. i have the basic code but need help with how to mainp= ulate the string to do the encryption/decryption. please help A few starting tips. Firstly, I'm going to assume here that this is a homework question; you haven't said so, but it seems rather more likely than the alternative (that you're actually going to use such an incredibly low-grade cipher and an interactive prompt like this). Please be honest about this; it's okay to ask for help, but we're not here to do your homework for you. (We do NOT want to help you to get a certificate you don't merit, then get a job using that certificate, and then write code that we'll be staring at in our next jobs. There are already more than enough incompetent programmers in the world; I'd rather that you either learn the material for real, or if you can't, fail the course honestly. Sorry if that sounds harsh, but I'm sure you'd rather that I didn't have a certificate entitling me to drive a truck on roads near you/your kids, because I do not know how to drive one safely.) Secondly, putting "NEED HELP" in your subject line doesn't, in fact, help. :) It just makes you sound demanding. So! On to the actual problem. What you need to do is find the letter that corresponds to the one you have. Decryption is the same as encryption but with the "alpha" and "key" switched, so I recommend creating a function that accepts those two as arguments - something like this: clear =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key =3D "XPMGTDHLYONZBWEARKJUFSCIQV" def crypt(msg,from,to): # and put your code in here # To encrypt: encrypted =3D crypt(original, clear, key) # To decrypt: message =3D crypt(encrypted, key, clear) The details of the encryption you can put together from John's and/or vbr's responses, but make sure you understand the code yourself. For example: What will each of them do with any non-alphabetic characters? Suppose your original message is "HELLO, WORLD!" - what will happen to the comma, space, and exclamation mark? Be sure you know *why* this is how it is, too. If you run into trouble, post your non-working code and exactly how it's not working, and we'll try to help you understand why it's not working. :) In the meantime, here's a document that you may want to familiarize yourself with: http://www.catb.org/esr/faqs/smart-questions.html It's a great explanation of the how and, more importantly, the why of asking questions of volunteer geeks. All the best! ChrisA