Last active
April 14, 2018 18:35
-
-
Save intrd/4139d8bc1f8f149f9230d7923a6dc87b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import re, sys, string, math, time, os, random | |
sys.path.append("../../LIBS") | |
from int_netcat import Netcat | |
def get_bitn(xx): | |
y=8 | |
for x in range (1,50): | |
y=2*y | |
if y > xx: | |
return y/2 | |
def xorsum(xorval, somaval): | |
num = 0 | |
for x in range(0,int(math.trunc(int(somaval)/2)+1)): | |
for y in range(x+1, int(somaval)-x+1): | |
if ( str(x^y) == str(xorval) and str(x+y) == str(somaval) ): | |
#print str(x)+"^"+str(y)+"="+str(xorval)+" e "+str(x)+"+"+str(y)+"="+str(somaval) | |
num += 2 | |
return num | |
def combinations(iterable, r): | |
pool = tuple(iterable) | |
n = len(pool) | |
if r > n: | |
return | |
indices = range(r) | |
yield tuple(pool[i] for i in indices) | |
while True: | |
for i in reversed(range(r)): | |
if indices[i] != i + n - r: | |
break | |
else: | |
return | |
indices[i] += 1 | |
for j in range(i+1, r): | |
indices[j] = indices[j-1] + 1 | |
yield tuple(pool[i] for i in indices) | |
def xorsum1(N, M): | |
N=int(N) | |
M=int(M) | |
Ns = [] | |
for x in range(M+1): | |
Ns.append(x) | |
X = [] | |
for i in combinations(Ns, 2): | |
xor = i[0]^i[1] | |
#print str(i[0])+"^"+str(i[1])+"="+str(xor) | |
if xor==N: | |
X.append(i) | |
S = [] | |
for i in X: | |
summ = i[0]+i[1] | |
if summ==M: | |
S.append(i) | |
result = len(S)*2 | |
return result | |
def xorraf(x): | |
x=int(x) | |
a = bin(x)[2:] | |
a = str(a).count("1") | |
a = math.pow(2,a) | |
return int(a) | |
def xorraf0(x): | |
x=int(x) | |
a = bin(x)[2:] | |
print a | |
a = str(a).count("0") | |
a = math.pow(2,a) | |
return int(a) | |
def xorfor(N): | |
count = 0 | |
for i in range(0, N + 1): | |
for j in range(0, N + 1): | |
if (i ^ j) == N: | |
print str(i) + ', ' + str(j) | |
count = count + 1 | |
return count | |
def is_prime(a): | |
return all(a % i for i in xrange(2, a)) | |
M=211 | |
with open("out2.txt","w") as f: | |
f.write("") | |
c=0 | |
for i in range (1,M): | |
out = str(c)+","+str(M)+" = "+str(xorsum1(c, M)) | |
print out | |
with open("out2.txt","a") as f: | |
f.write(out +"\n") | |
c+=1 | |
exit() | |
#N = "1235" | |
# 211 = 3 1 9 5 7 | |
while 1: | |
nc = Netcat('45.55.184.240', 8866) | |
data=nc.read() | |
print(data) | |
nc.write("start") | |
data=nc.read() | |
print(data) | |
while 1: | |
data=nc.read_until_prompt(2048,1,10) | |
print(data) | |
if "Eroooou" in data: | |
with open("errors.txt","a") as f: | |
f.write(str(M)+","+str(N)+ "=" +str(RM)+":"+str(RN) +"\n") | |
break | |
if "Correto" in data: | |
if N!=M: | |
with open("corrects.txt","a") as f: | |
f.write(str(M)+","+str(N)+ "=" +str(RM)+":"+str(RN) +"\n") | |
if re.search(r'(flag)', data): | |
data=nc.read_until("}") | |
print(data) | |
print(data) | |
print(data) | |
exit() | |
D = int(re.search(r'o (\d+) - ', data).group(1)) | |
N = re.search(r'M\): (\d+)', data).group(1) | |
M = re.search(r'M\): (\d+), (\d+)', data).group(2) | |
l=len(str(M)) | |
RM = xorraf(M) | |
RN = xorraf(N) | |
#value = xorraf(M-N) | |
# if D==51: | |
# value = 128 | |
# else: | |
# if True and D<51: | |
# value = xorsum1(N,M) | |
# else: | |
# result = xorraf(M) | |
# if int(N)==int(M): value = result | |
# #if int(M)!=int(N) and N[-1:] == "0": value = xorraf(M) | |
# if int(N)!=int(M) and N[-1:] == "2": value = result | |
# if int(N)!=int(M) and N[-1:] == "4": value = result | |
# if int(N)!=int(M) and N[-1:] == "6": value = result | |
# if int(N)!=int(M) and N[-1:] == "8": value = result | |
# if int(M)!=int(N) and int(M)%2!=0: value = 0 | |
if D==51: value=128 | |
if D<1: | |
value = xorsum1(N,M) | |
else: | |
if int(N)==int(M): value = xorraf(N) | |
#if int(N)!=int(M): value = xorraf(int(M)-int(N)) | |
#if int(M)!=int(N) and N[-1:] == "0": value = xorraf(M) | |
if int(M)!=int(N) and int(N)%2==0 and int(M)%2==0: value = xorraf(N) | |
if int(M)!=int(N) and int(N)%2!=0 and int(M)%2!=0: value = xorraf(N) | |
if int(M)!=int(N) and int(N)%2!=0 and int(M)%2==0: value = 0 | |
if int(M)!=int(N) and int(N)%2==0 and int(M)%2!=0: value = 0 | |
#if int(M)==int(N): value = xorraf(M) | |
#if int(M)!=int(N): value=random.choice([0,xorraf(int(M))]) | |
# if int(M)!=int(N) and int(RN)%8==0: | |
# value = 0 | |
# if int(M)!=int(N) and int(RN)%8!=0: | |
# value = xorraf(M) | |
# value = xorraf(M) | |
# if D<51: value = xorsum(M,N) | |
# if D==51: value=128 | |
# if D>51 and int(M)==int(N): value = xorraf(M) | |
# if D>51 and int(M)!=int(N): | |
# value=random.choice([0,xorraf(int(M))]) | |
print(value) | |
nc.write(str(value)+'\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment