Skip to content

Instantly share code, notes, and snippets.

@whs
Created July 23, 2011 16:21
Show Gist options
  • Select an option

  • Save whs/1101601 to your computer and use it in GitHub Desktop.

Select an option

Save whs/1101601 to your computer and use it in GitHub Desktop.
Hackathon r2-7
input = "\x4c\x9a\x59\x3a\x35\x89\x91\x24\x5a\x9a\x5d\x3a\x35\x29\x95\x2b\x53\x8c\x35\xba\x94\xca\xd5\x2d\x4d\xae\x59\x92\x45\x6a\xd1\x21\x4c\x9a\x59"
#input="\x53\xac\x3d\x7a\xc4"
pos = 0
out=""
for i in input:
# do a circular right shift
b = list(bin(ord(i)).split("0b")[1])
# pad to 8 bits
while len(b) < 8:
b.insert(0, "0")
print pos, b
i=0
# right shift
while i < pos:
b.insert(0, b.pop())
i += 1
print b
pos += 1
decoded = chr(int("".join(b), 2))
# reverse it!
i=0
start = 65
end = 90
while i <= 26:
if decoded == chr(start+i):
decoded = chr(end-i)
break
i += 1
out += decoded
print out
@raktai

raktai commented Jul 23, 2011

Copy link
Copy Markdown

great

I use collections:deque to rotate (right shift)

from collections import deque
d=deque("11110000")
d.rotate(4)
d
deque(['0', '0', '0', '0', '1', '1', '1', '1'])
list(d)
['0', '0', '0', '0', '1', '1', '1', '1']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment