Created
December 21, 2014 07:29
-
-
Save arvinddoraiswamy/846de119b09dcbb8ea92 to your computer and use it in GitHub Desktop.
Flare on challenge 6
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
import collections | |
import string | |
import sys | |
def hextobin(string): | |
bin_str='' | |
split_str=list(string) | |
for i in split_str: | |
temp1=str(bin(int(i,16))[2:].zfill(4)) | |
bin_str+=temp1 | |
return bin_str | |
flag='' | |
#Character 1 - Handling rotation rightwards for the first time | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('f2', 16)) | |
for x in c1: | |
l.append(x) | |
if hex(int(''.join(l), 2))[2:] == '1b': | |
flag+=i | |
break | |
#Character 2 - Handling XOR for the first time | |
for i in string.printable: | |
t1='' | |
t1= ord(i)^0x40 | |
t1= t1^0xf2 | |
t1= t1^0xb3 | |
if t1 == 0x30: | |
flag+=i | |
break | |
#Character 3 | |
for i in string.printable: | |
t1='' | |
t1= ord(i)^0x71 | |
if t1 == 0x1f: | |
flag+=i | |
break | |
#Character 4 - Handling hex addition and ignoring the carry for the first time | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0xa3 | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('bc', 16)) | |
for x in c1: | |
l.append(x) | |
if hex(int(''.join(l), 2))[2:] == 'b0': | |
flag+=i | |
break | |
#Character 5 - Handling hex subtraction with negative numbers for the first time | |
for i in string.printable: | |
t2=ord(i)-0x79 | |
""" | |
https://stackoverflow.com/questions/7822956/how-to-convert-negative-integer-value-to-hex-in-python | |
""" | |
t2= hex(t2 & (2**8-1))[-2:] | |
if t2 == 'e8': | |
flag+=i | |
break | |
#Character 6 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('82', 16)) | |
for x in c1: | |
l.append(x) | |
t1= ''.join(l) | |
t2= int(t1, 2)-0x28 | |
t2= hex(t2 & (2**8-1))[-2:] | |
if t2 == 'f6': | |
flag+=i | |
break | |
#Character 7 | |
for i in string.printable: | |
l=[] | |
t2=ord(i)-0xb0 | |
""" | |
https://stackoverflow.com/questions/7822956/how-to-convert-negative-integer-value-to-hex-in-python | |
""" | |
t2= hex(t2 & (2**8-1))[-2:] | |
x = list(hextobin(t2)) | |
c1= collections.deque(x) | |
c1.rotate(int('4d', 16)) | |
for x in c1: | |
l.append(x) | |
t1= ''.join(l) | |
t2= int(t1, 2)+0x2c | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
if hex(t1)[2:].zfill(2) == '1f': | |
flag+=i | |
break | |
#Character 8 - Rotate left for the first time. This I think is the last new operation (Phew #-o) and it's just code reuse from now on :). | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0x54 | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('-0x99', 16)) | |
for x in c1: | |
l.append(x) | |
t2= int(''.join(l), 2)^0xb8 | |
l=[] | |
x = list(hextobin(hex(t2)[2:])) | |
c1= collections.deque(x) | |
c1.rotate(int('2a', 16)) | |
for x in c1: | |
l.append(x) | |
t2= int(''.join(l), 2) + 0x3f | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
if hex(t1)[2:].zfill(2) == 'af': | |
flag+=i | |
break | |
#Character 9 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('ba', 16)) | |
for x in c1: | |
l.append(x) | |
if hex(int(''.join(l), 2))[2:] == '5d': | |
flag+=i | |
break | |
#Character 10 | |
for i in string.printable: | |
l=[] | |
t1='' | |
t1= ord(i)^0xed | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('6c', 16)) | |
for x in c1: | |
l.append(x) | |
t1= int(''.join(l), 2) | |
t2=t1+0x30 | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
if t1 == 0x29: | |
flag+=i | |
break | |
#Character 11 | |
for i in string.printable: | |
t2=ord(i)-0xbf | |
t2= hex(t2 & (2**8-1))[-2:] | |
if t2 == 'b5': | |
flag+=i | |
break | |
#Character 12 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('-bc', 16)) | |
for x in c1: | |
l.append(x) | |
t1= int(''.join(l), 2) | |
t2=t1+0x8c | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('-0x7b', 16)) | |
for x in c1: | |
l.append(x) | |
t1= int(''.join(l), 2) | |
t2= t1-0x31 | |
t2= hex(t2 & (2**8-1))[-2:] | |
t2= int(t2, 16) | |
t2+= 0x63 | |
if hex(t2)[2:] == 'a5': | |
flag+=i | |
break | |
#Character 13 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('-0x20', 16)) | |
c1.rotate(int('-0x16', 16)) | |
for x in c1: | |
l.append(x) | |
t1= int(''.join(l), 2) | |
t1= t1^0xae | |
l=[] | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('-0x98', 16)) | |
for x in c1: | |
l.append(x) | |
t1= int(''.join(l), 2) | |
if hex(t1)[2:] == 'f3': | |
flag+=i | |
break | |
#Character 14 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('6e', 16)) | |
for x in c1: | |
l.append(x) | |
t2= int(''.join(l), 2) | |
t2= t2+0xd2 | |
t2= hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
if hex(t1)[2:] == 'a6': | |
flag+=i | |
break | |
#Character 14 | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0x34 | |
t2=hex(t2) | |
if len(str(t2)) == 4: | |
t1= int(str(t2)[2:], 16) | |
elif len(str(t2)) == 5: | |
t1= int(str(t2)[3:], 16) | |
if hex(t1)[2:] == '62': | |
flag+=i | |
break | |
#Character 15 | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0xcd | |
t2= t2-0x10 | |
t2= hex(t2 & (2**8-1)) | |
t2= int(t2, 16) | |
t2+= 0x62 | |
t2^= 0xb2 | |
if hex(t2)[2:] == '32': | |
flag+=i | |
break | |
#Character 16 | |
for i in string.printable: | |
l=[] | |
t1='' | |
t1= ord(i)^0xb7 | |
t1= t1^0x73 | |
x= list(bin(t1)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('0x7', 16)) | |
for x in c1: | |
l.append(x) | |
t2= int(''.join(l), 2) | |
if hex(t2)[2:] == 'eb': | |
flag+=i | |
break | |
#Character 17 | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0x34 | |
t2=t2-0x61 | |
t2= hex(t2 & (2**8-1)) | |
t2= int(t2,16) | |
x= list(bin(t2)[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('0x36', 16)) | |
for x in c1: | |
l.append(x) | |
t2= int(''.join(l), 2) | |
t2= t2+0x5b | |
t2= t2-0x4c | |
t2= hex(t2 & (2**8-1))[2:].zfill(2) | |
if t2 == '0b': | |
flag+=i | |
break | |
#Character 18 | |
for i in string.printable: | |
l=[] | |
t2=ord(i)+0x5a | |
if hex(t2)[2:] == '9a': | |
flag+=i | |
break | |
#Character 19 | |
for i in string.printable: | |
l=[] | |
x= list(bin(ord(i))[2:].zfill(8)) | |
c1= collections.deque(x) | |
c1.rotate(int('a2', 16)) | |
for x in c1: | |
l.append(x) | |
if hex(int(''.join(l), 2))[2:] == '99': | |
flag+=i | |
break | |
#Character 20 | |
""" | |
At this point I just guessed the rest as it was similar to the previous challenges. Wasted another half hour due to an oversight and ended up looking at previous solutions. I'd accidentally resolved a character twice and added an extra 'l' #-o | |
""" | |
print flag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment