Created
May 7, 2013 05:34
-
-
Save Zolmeister/5530473 to your computer and use it in GitHub Desktop.
picoCTF - Evergreen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product | |
from copy import copy | |
board = [[None for x in xrange(13)] for y in xrange(13)] | |
for i,x in enumerate(board): | |
for j,y in enumerate(board[0]): | |
if i>=6 or j>=13: | |
break | |
#board[i][j]=1 | |
first = "01211212021202212011102122002201" | |
second= "12012220122202121022021221022220" | |
third = "12021022020222210212022121022020" | |
fourth= "12222012221121220122202012120212" | |
col=0 | |
row=0 | |
for i in first: | |
board[row][col]=int(i) | |
col+=1 | |
if col>=13: | |
col=0 | |
row+=1 | |
for i in second: | |
board[row][col]=int(i) | |
col+=1 | |
if col>=13: | |
col=0 | |
row+=1 | |
for i in third: | |
board[row][col]=int(i) | |
col+=1 | |
if col>=13: | |
col=0 | |
row+=1 | |
for i in fourth: | |
board[row][col]=int(i) | |
col+=1 | |
if col>=13: | |
col=0 | |
row+=1 | |
""" | |
(s[0] == 6962645667329216838L) | |
(s[1] == -9213219107527098271L) | |
(s[2] == -8636705539236951775L) | |
(s[3] == 1301971326710323201L)) | |
""" | |
def serializedState(board): | |
s=[0,0,0,0] | |
bit=0 | |
for row in board: | |
for hex in row: | |
if hex is not None: | |
if hex==0: | |
s[((bit + 1) / 64)] |= 1L << (bit + 1) % 64 | |
elif hex==1: | |
s[(bit / 64)] |= 1L << bit % 64 | |
bit+=2 | |
return s | |
print serializedState(board) | |
print serializedState(board)[3] | |
print 1301971326710323201L | |
print str(board).replace("[","{").replace("]","}").replace("None","-1") | |
""" | |
def getter(target): | |
gen = product(['2','1','0'],repeat=32) | |
for g in gen: | |
k=calc(''.join(g)) | |
print k | |
if k==target: | |
return g | |
""" | |
def calc(tar): | |
k=0 | |
bit=0 | |
for let in tar: | |
if let=="0": | |
k |= 1L << (bit + 1) % 64 | |
elif let=="1": | |
k |= 1L << bit % 64 | |
bit+=2 | |
return k | |
def increase(num, index): | |
cop = copy(num) | |
if cop[index]=="0": | |
index-=1 | |
if cop[index]=="2": | |
cop[index]="1" | |
elif cop[index]=="1": | |
cop[index]="0" | |
else: | |
return increase(cop,index-1) | |
return cop | |
current = list("22222222222222222222222222222222") | |
target = 1301971326710323201L | |
index = len(current)-1 | |
while index>=0: | |
test = increase(current, index) | |
if calc(''.join(test))>target: | |
index-=1 | |
else: | |
current=test | |
print ''.join(current) | |
print calc(''.join(current)) | |
print target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment