Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import random
def verificacion(text,h):
array = []
for i in range(len(h)):
resut = 5
#array.append([])
for j in range(len(h[i])):
if h[i][j] == 1 and text[j] == 1:
algo = 1
else:
algo = 0
if resut == 5:
resut = 0
antes = algo
else:
ahora = algo
if ahora == antes:
antes = 0
else:
antes = 1
array.append(antes)
print array
error = 0
for i in range(len(array)):
a = array[i]
if a != 0:
error = 1
#print "hay un error :P"
control = 0
cont = 0
if error == 1:
cosa = []
#print "error chekando :"
for i in range(len(array)):
cosa.append(str(array[i]))
cosa = "".join(cosa)
tam = len(h[0])
cosab = []
for i in range(tam):
for j in range(len(h)):
a = h[j][i]
cosab.append(str(a))
cosab = "".join(cosab)
if cosa == cosab and control == 0:
control = 1
cont = i
print cosab
cosab = []
if control== 1:
print "error en el lugar: ",cont,"del texto"
if text[cont] == 0:
text[cont] = 1
else:
text[cont] = 0
print "corregido : ",text
verificacion(text,h)
return
def creath(table,vec,pares):
ftable = []
v = []
par = []
tam = len(pares[0])
#print "pares: ",pares
for j in range(tam):
par.append([])
for i in range(len(pares)):
par[j].append(pares[i][j])
#print "par: ",par
tam = len(vec)
#print "vec: ",vec
for i in range(len(vec) - 1):
v.append([])
for j in range(len(vec)-1):
v[i].append(vec[i][j])
#print pares[i][j]
#print "v: ",v
for i in range(len(v)):
ftable.append([])
for j in range(len(v[i])):
ftable[i].append(v[i][j])
for j in range(len(par[i])):
ftable[i].append(par[i][j])
return ftable
def processc(cadena,table,cant):
final = []
for i in range (cant):
#print "colum = ",i
resultado = 3
for j in range(len(table)):
########################################
if cadena[j] == 1 and table[j][i] == 1:
algo = 0
else:
algo = 1
##########################################
#########################################
if resultado == 3:
antes = algo
resultado = 0
else:
ahora = algo
if antes == ahora:
antes = 0
else:
antes = 1
final.append(antes)
###########################################
#print "cadena final: ",final
return final
def creatt(bits):
table = []
paried = []
for k in range(bits):
table.append([])
paried.append([])
for j in range(bits):
if k == j:
table[k].append(1)
else:
table[k].append(0)
#print "sin pariedad: ",table
pariedad = 3
for k in range(bits):
datos = []
for j in range(bits):
datos.append(table[k][j])
#print datos
for l in range(pariedad):
resultado = 3
for i in range(len(datos)):
if l != i:
if resultado == 3:
antes = datos[i]
resultado = 5
else:
ahora = datos[i]
#print "antes: ",antes,"ahora: ",ahora
if antes == ahora:
antes = 0
else:
antes = 1
#table[k].append(antes)
paried[k].append(antes)
#print "tabla: ",table
#print "pariedad: ",paried
ftable = []
for i in range (len(table)):
ftable.append([])
for k in range(len(paried[i])):
ftable[i].append(paried[i][k])
for j in range(len(table[i])):
ftable[i].append(table[i][j])
#print "ftable: ",ftable
return ftable,table,paried
def ruido(text):
for i in range(len(text)):
a = text[i]
b = random.randint(0,4)
if b == 4:
if a == 0:
text[i] = 1
else:
text[i] = 0
return text
def main():
tbits = int(raw_input("Dame el tam de los bits: "))
#tpari = raw_input("Dime la pariedad que deseas: ")
#print "escogiste tbits = ",tbits,"y pariedad de : ",tpari
table,vect,paried = creatt(tbits)
bits = raw_input("dame la cadena de cuatro porfa: ")
ebits = []
print "final g: "
for i in range(len(table)):
print table[i]
print "final g: ",table
print "codigo: ",vect
print "pyre code: ",paried
for i in range(len(bits)):
ebits.append(int(bits[i]))
#print ebits
cant = tbits + 3
cenviar = processc(ebits,table,cant)
print "cadena normal: ",cenviar
h = creath(table,vect,paried)
for i in range(len(h)):
print h[i]
#print "con ruido: ",cenviar
cenviar = ruido(cenviar)
print "cadena a enviar: ",cenviar
#print h
error = 1
#while error == 1:
verificacion(cenviar,h)
#print cenviar
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment