Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # unshuffle_plus.py
- # had thought there might be a way to further compress data through this method
- # ... which is not the case, so it's been retracted. It was a fun attempt though.
- from cStringIO import StringIO
- from PIL import ImageTk, Image
- import base64, zlib
- import random
- key_cycles = 10
- msg = '''
- Hello World!
- THE ZEN OF PYTHON
- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
- Sparse is better than dense.
- Readability counts.
- Special cases aren't special enough to break the rules.
- Although practicality beats purity.
- Errors should never pass silently.
- Unless explicitly silenced.
- In the face of ambiguity, refuse the temptation to guess.
- There should be one-- and preferably only one --obvious way to do it.
- Although that way may not be obvious at first unless you're Dutch.
- Now is better than never.
- Although never is often better than *right* now.
- If the implementation is hard to explain, it's a bad idea.
- If the implementation is easy to explain, it may be a good idea.
- Namespaces are one honking great idea -- let's do more of those!
- The quick brown fox jumps over the lazy dog
- abcdefghijklmnopqrstuvwxyz
- ABCDEFGHIJKLMNOPQRSTUVWXYZ
- 0123456789,:,;(*!?'")
- '''
- def b64_zlib(data):
- compressed = zlib.compress(data)
- b64 = base64.encodestring(compressed)
- return b64
- def b64_zlib_decompress(b64):
- b64 = base64.decodestring(b64)
- data = StringIO(zlib.decompress(b64))
- return data
- def decrypt(message, key):
- random.seed(key)
- L = list(range(len(message)))
- random.shuffle(L)
- return "".join(message[i] for i, x in sorted(enumerate(L), key=lambda x: x[1]))
- def encrypt(message, key):
- random.seed(key)
- L = range(len(message))
- random.shuffle(L)
- sss = "".join([message[x] for x in L])
- return sss
- def pyzip(code,func,depth=''):
- L = len(code)
- t = code
- if depth:
- t = func(t,depth)
- print [the_key],
- print L,
- else:
- t = func(t)
- if len(t) <= L:
- code = t
- return code
- code = msg
- for the_key in range(1, key_cycles):
- ### code = pyzip(code,b64_zlib)
- code = pyzip(code,encrypt,1)
- print len(code)
- print [code]
- print
- for the_key in range(key_cycles-2,-1,-1):
- ### code = pyzip(code,b64_zlib_decompress)
- code = pyzip(code,decrypt,1)
- print len(code)
- print [code]
- print
- print
- print code
Add Comment
Please, Sign In to add comment