: : Can the following snippets be reduced? The total lines of each snippet is 136!
: :
: :
: :
: : while n <= x:
: : if char == 'A':
: : newstr = newstr + 'D'
: : elif char == 'B':
: : newstr = newstr + 'E'
: : elif char == 'C':
: : newstr = newstr + 'F'
: : ...
: : elif char == '!':
: : newstr = newstr + 'A'
: : elif char == '-':
: : newstr = newstr + 'B'
: : elif char == ' ':
: : newstr = newstr + 'C'
: : str = newstr
: :
: :
: : while n <= x:
: : if char == 'A':
: : newstr = newstr + '!'
: : elif char == 'B':
: : newstr = newstr + '-'
: : elif char == 'C':
: : newstr = ' '
: : ...
: : elif char == '!':
: : newstr = newstr + ','
: : elif char == '-':
: : newstr = newstr + '.'
: : elif char == ' ':
: : newstr = newstr + '?'
: : str = newstr
: :
: :
: : Any ideas?
: :
: : Thanks in advance,
: : Nathan
: : Swat spam before it fills your inbox!
: :
:
: What are you trying to do? May be its possible to generalize things... post the whole code, if you can...or you yourself look for patterns you can exploit
:
: like for the first part
:
: if char == 'A':
: newstr = newstr + 'D'
: elif char == 'B':
: newstr = newstr + 'E'
: elif char == 'C':
: newstr = newstr + 'F'
:
: you can go (pseduocode)
:
:
: if char is in range 'A' to 'D'
: newstr = newstr + str(int(char)+3)
:
: ...thats how I would do it in C, or something like that, it runs atop the fact that characters are numbers, but I'm not sure you can do such stuff in python efficiently...
:
: if that didn't explain much (I doubt it did), just post mroe of your code, and we can help :)
:
: {2}rIng
:
I'm trying to encrypt/decrypt messages. I switched to PyCrypto and ezPyCrypto and got the following error:
>>> from ezPyCrypto import key
>>> str = '4 big dogs.'
>>> key.encString(str)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in ?
key.encString(str)
TypeError: unbound method encString() must be called with key instance as first argument (got str instance instead)
>>>
How can I fix the error
Swat spam before it fills your inbox!