Need to add to ord and convert to chr
Terry Reedy
tjreedy at udel.edu
Sun Nov 5 18:22:51 EST 2000
<mchitti at my-deja.com> wrote in message news:8u4gn9$pe5$1 at nnrp1.deja.com...
> Trying to teach myself python, would appreciate any help.
>
> I have a long string of letters (a caesar cipher) which I chop up,
> convert to ord values and stick into a list. I need to be able to add
> an arbitrary interger to the ord values and then convert back to char.
> This should allow me to brute force the cipher if my logic is good.
> position = 0
> message =
> 'qfoukwucpujlukfdsjfdoujoswubepswsbipnqnjqfouksdlnepsaipuoujosdqfzwuobsq
> ubqsjfdnbbukobsqfkfhjubskhflskcfjwnkofkwuyshsbnudbsbpomswshsksblfkyshfds
> wfkwuwubtndhsdfofdksdejuuducneskpofjhslsosjcukngujfujsdopsljfgpdsbukxlpq
> fipukpopchnjopsdwfbskukljubbskobsqsdjuyfduksbsepsejnkopsdwfbfkujsbukkpud
> sdqujfdnoskwusbmubnqfoukwucpujlukfdsjfdoujoswubepswsbipnqnj'
>
> loop = len(message)
>
> while loop:
> decode = map(ord,message[position]), #, wrong; use of map wrong
> print decode
> position = position + 1
> loop = loop - 1
map applies a function to all items of a list, not to one item extracted
therefrom. IE, it has implicit loop builtin. Start with
ords = map(ord, message)
Then
import string
def trydelta(i): return string.join(map( lambda x: chr(x+i), ords))
#untested
will something like what you want for one possible shift
Terry J. Reedy
More information about the Python-list
mailing list