import binascii
def get(str):
lst = []
for i in range(0,len(str),2):
lst.append('0x' + str[i:i+2])
return lst
def xor_hexlist(list1,list2):
return [ hex(int(x,16) ^ int(y,16)) for (x,y) in zip(list1,list2)]
def show(listNN):
for i in listNN:
for j in i:
print j,
print '\n'
def show_hexlist(hexlist):
t = []
for i in hexlist:
t.append(i[2:])
t = ''.join(t)
print t
#---------------------
f = open('in.txt','r')
clst = []
minlen = 100000
con = True
while con:
line = f.readline()
line = line.strip()
if line != '':
if minlen > len(line):
minlen = len(line)
clst.append(get(line))
else:
con = False
print minlen
for i in range(len(clst)):
clst[i] = clst[i][:minlen/2]
#show(clst)
print '*******************************************************'
#=====
xored = []
for line in range(0,len(clst) - 1):
xored.append(xor_hexlist(clst[line],clst[-1]))
#show(xored)
a_xor_space = [hex((ord('a')+i) ^ ord(' ')) for i in range(26)]
for i in range(26):
a_xor_space.append(hex((ord('A')+i) ^ ord(' ')))
#a_xor_space.append(hex((ord(' ')) ^ ord(' ')))
alpha_ascii = [hex(ord('a')+i) for i in range(26)]
for i in range(26):
alpha_ascii.append(hex(ord('A')+i))
#alpha_ascii.append(hex(ord(' ')))
print alpha_ascii
secret = []
for i in xored:
temp = []
for j in i:
temp.append('*')
secret.append(temp)
show(xored)
target = ['@' for i in range(minlen / 2)]
key = ['*' for i in range(minlen / 2)]
sum = 0
for i in range(len(xored)):
for j in range(0,len(xored[i])):
if xored[i][j] in a_xor_space:
int1 = ord(' ')
int2 = int(xored[i][j],16) ^ int1
flag1= 0
flag2= 0
k_1 = hex(int(clst[-1][j],16) ^ int1)
k_2 = hex(int(clst[-1][j],16) ^ int2)
for k in range(len(xored)):
#temp = hex(k_j ^int(clst[k][j],16))
#if temp not in alpha_ascii:
# flag += 1
if hex(int(clst[k][j],16) ^ int(k_1,16)) in alpha_ascii:
flag1 += 1
if hex(int(clst[k][j],16) ^ int(k_2,16)) in alpha_ascii:
flag2 += 1
if flag1 > flag2:
key[j] = k_1
target[j] += ' '
secret[i][j] = chr(int2)
else:
key[j] = k_2
target[j] += chr(int2)
secret[i][j] = ' '
show(secret)
for i in xored:
for j in i:
if j in a_xor_space:
print j,
else:
print '*',
print '\n'
for i in target:
print i,
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。