[Tutor] Simple ROT-13 Script
Javier JJ
python.tutorial at jarava.org
Tue Feb 3 11:09:22 EST 2004
And the reason that it wont' work on other than ASCII.- strings ??
I mean:
>>> s = "asasas"
>>> s.encode("rot13")
'nfnfnf'
>>> type(s)
<type 'str'>
>>> s = "aaañññaaaaaaaa"
>>> s
'aaa\xf1\xf1\xf1aaaaaaaa'
>>> type(s)
<type 'str'>
>>> s.encode("rot13")
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\encodings\rot_13.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 3:
ordinal not in range(128)
>>>
¿¿¿?????
Thanks a lot...
Javier Jarava
On this day, 03/02/2004 15:13, Karl Pflästerer wrote:
>On 3 Feb 2004, don arnold <- darnold02 at sprynet.com wrote:
>
>
>
>>And in case you didn't know, the reason you want it to wrap around is so
>>that you only need a single rot13() function, not individual encrypt() and
>>decrypt() functions:
>>
>>
>
>
>
>>>>>print rot13('abc')
>>>>>
>>>>>
>>nop
>>
>>
>>>>>print rot13('nop')
>>>>>
>>>>>
>>abc
>>
>>
>
>Right. And you should take care, that only characters are moved.
>Numbers or punctuation signs e.g. are not touched.
>
>
>
>>>>s = "Guido 123; Tim 456"
>>>>s.encode('rot13')
>>>>
>>>>
>'Thvqb 123; Gvz 456'
>
>
>>>>_.encode('rot13')
>>>>
>>>>
>'Guido 123; Tim 456'
>
>
>
>
>
> Karl
>
>
More information about the Tutor
mailing list