4

I need an encript arithmetic, which encript text to text.

the input text could be unicode, and the output should be a-z A-Z 0-9 - . (64 char max)

and it could be decrypt to unicode again.

it should implement in javascript and python.

If there is already some library could do this, great, if there is not, could you tell me.

Let me talk about why

To cheat China Greate Fire Wall , and GAE https has been blocked at china. Angry for this damn goverment.

5
  • Please add some clarification about the process. Can you show an example of input and expected output? Why does it need to be implemented in JS and Python? That sounds like a pretty exotic requirement. What exactly do you need this for? Commented Oct 13, 2010 at 9:37
  • This is not encryption, this is encoding. fixing tags. Commented Oct 13, 2010 at 9:45
  • It sounds like you're implementing something catastrophically insecure, and chances are the correct answer is "stop" and "use HTTPS". Commented Oct 13, 2010 at 9:50
  • Re why: Now that's a noble cause and gets my thumbs up any day, but is the Great Firewall really this simple? Hard to believe Commented Oct 13, 2010 at 12:58
  • I am not sure. Base on some experience, there are url filter and content filter, and ip filter, e.g. if url contains groups.google.com wheather it is the domain position, it will blocked, if content contains some sensitive words it will blocked, and https port for specific ip is blocked manually. Commented Oct 13, 2010 at 14:45

2 Answers 2

10

You might want to look at the base64 module. In Python 2.x (starting with 2.4):

>>> import base64
>>> s=u"Rückwärts"
>>> s
u'R\xfcckw\xe4rts'
>>> b=base64.b64encode(s.encode("utf-8"))
>>> b
'UsO8Y2t3w6RydHM='
>>> d=base64.b64decode(b)
>>> d
'R\xc3\xbcckw\xc3\xa4rts'
>>> d.decode("utf-8")
u'R\xfcckw\xe4rts'
>>> print d.decode("utf-8")
Rückwärts
Sign up to request clarification or add additional context in comments.

Comments

4

You are looking for a base64 encoding. In JavaScript and Python 2 this is a bit complicated as the latter doesn't support unicode natively and for the former you would need to implement an Unicode encoding yourself.

Python 3 solution

>>> from base64 import b64encode, b64decode
>>> b64encode( 'Some random text with unicode symbols: äöü今日は'.encode() )
b'U29tZSByYW5kb20gdGV4dCB3aXRoIHVuaWNvZGUgc3ltYm9sczogw6TDtsO85LuK5pel44Gv'
>>> b64decode( b'U29tZSByYW5kb20gdGV4dCB3aXRoIHVuaWNvZGUgc3ltYm9sczogw6TDtsO85LuK5pel44Gv' )
b'Some random text with unicode symbols: \xc3\xa4\xc3\xb6\xc3\xbc\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf'
>>> _.decode()
'Some random text with unicode symbols: äöü今日は'

3 Comments

Does Python 3 default to UTF-8 when calling .encode() without arguments?
Ok, got it. The default encoding was changed from ASCII to UTF-8. I think encode() somewhat violates the rule of "explicit over implicit".
Python 3 strings are unicode, calling .encode() creates a bytes object that holds no information about the encoding. .decode() on bytes object does the reverse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.