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!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; '"""': 0.05; 'skip:" 60': 0.05; 'implements': 0.07; 'key.': 0.07; 'python': 0.09; '"thanks': 0.09; 'substitution': 0.09; 'def': 0.10; '2.7': 0.13; 'alpha': 0.15; '"2":': 0.16; 'alphabet': 0.16; 'correctly,': 0.16; 'main():': 0.16; 'skip:" 70': 0.16; 'subject:String': 0.16; 'string': 0.17; '>>>': 0.18; 'code,': 0.18; 'input': 0.18; 'translate': 0.20; 'skip:" 30': 0.20; 'import': 0.21; '3.2': 0.22; 'help.': 0.22; 'header:In-Reply- To:1': 0.25; 'skip:" 20': 0.26; 'plain': 0.27; 'received:209.85.210.46': 0.27; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.27; 'coded': 0.29; 'letter.': 0.29; 'url:mailman': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'becomes': 0.30; 'basic': 0.30; 'stuff': 0.30; 'code': 0.31; '(and': 0.32; 'url:python': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'here': 0.65; 'secret': 0.71; 'spy': 0.84; 'cryptography': 0.91; '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=Y6Vn3g3ug/XS43xhwForVUI6aQQ7L0i7INz5spb/Y9I=; b=H2Sv0x27nEweltGxOo15Nu1gDLZBsrZERJJs8Ta860cLY88AsREmja2XwB6YuiWKvr zv+U3lwwrxoaRJ2vnLrimdAR50WHrhCHgEpzUYbxQvVHPc7+Ol7H5EU3MRhSOfF5Kc2V Jmrm1Kzgu6sr5TZWmFTUsoHF0TZOZ3K5zqKDprNB7fYGv5+f0I+BYN1/mUkKruIXxASU gp7xI6BNm9l+QQNiCdJB/M19fsH5VDAaN+t3uLjYxQfSAGYJSg3I/6i9b1ZcyhqHIzYH l2Ckf+EWELcyhFKBa5VWiWk66WMZ8hSRfiqOVHKmxIRhBDqwUu8q6mpbD5WDqZZMHY/v vYiw== MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 11 Dec 2012 00:25:58 +0100 Subject: Re: String manipulation in python..NEED HELP!!!! From: Vlastimil Brom 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355181961 news.xs4all.nl 6985 [2001:888:2000:d::a6]:60253 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34580 2012/12/10 : > 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 > > here is my code so far: > > > """ crypto.py > Implements a simple substitution cypher > """ > > alpha =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > key =3D "XPMGTDHLYONZBWEARKJUFSCIQV" > > def main(): > keepGoing =3D True > while keepGoing: > response =3D menu() > if response =3D=3D "1": > plain =3D raw_input("text to be encoded: ") > print encode(plain) > elif response =3D=3D "2": > coded =3D raw_input("code to be decyphered: ") > print decode(coded) > elif response =3D=3D "0": > print "Thanks for doing secret spy stuff with me." > keepGoing =3D False > else: > print "I don't know what you want to do..." > > > > > i really need help on how to encrypt it im not sure how to go about doing= that please help. > -- > http://mail.python.org/mailman/listinfo/python-list Hi, if I understand correctly, for the data shown in the code, you may probably use the translate method of the string (and the corresponding maketrans method); cf.: python 2.7 >>> import string >>> "ABCDEF...VWXYZ".translate(string.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ= ", "XPMGTDHLYONZBWEARKJUFSCIQV")) 'XPMGTD...SCIQV' >>> python 3.2 >>> "ABCDEF...VWXYZ".translate("".maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "= XPMGTDHLYONZBWEARKJUFSCIQV")) 'XPMGTD...SCIQV' >>> hth, vbr