Create a gist now

Instantly share code, notes, and snippets.

#######para el compresor variables######
letras = []
nletras = []
cantidad = 0
codigo = []
cer = ""
arb = []
cond = 0
inte = 0
######para el compresor variables######
#########descompresor##################
dletras = []
dcodigo = []
dcandidad = 0
###############descompresor############
#cont = 0
def receptor(cadena):
#for i in range (len(cadena)):
i = 0
text = ""
ash = 1
dec = ""
#print "valor de la cadena: ",cadena
while i < len(cadena):
print "valor de la cadena actual: : ",cadena[i]
if cadena[i] == '%':
#print "entro aqui acaso ?"
p = 0
while p < len(dletras):
if dletras[p] == cadena[i+1]:
cambi1,cambi2 = dletras[p],dletras[0]
dletras[p],dletras[0] = cambi2,cambi1
cambi1,cambi2 = dcodigo[p],dcodigo[0]
dcodigo[p],dcodigo[0] = cambi2,cambi1
print "letra: ",dletras[0],"codigo anterior",dcodigo[p],"codigo nuevo: ",dcodigo[0]
#cambi1
#cambi2
break
i = i + 3
if cadena[i] == '$':
dletras.append(cadena[i+1])
i = i + 2
while True:
if cadena[i] == '$':
print "letra : ",dletras[len(dletras)-1]
print "codigo grabar : ",text
dec += "".join(dletras[len(dletras)-1])
dcodigo.append(str(text))
#print "descomprimi ",,""
i = i + 1
text = ""
break
else:
text += "".join(cadena[i])
i = i + 1
else:
#i = i + 1
text = ""
text += "".join(cadena[i])
while True:
letter = cadena[i]
if letter == "1":
for j in range(len(dcodigo)):
if text == dcodigo[j]:
dec += "".join(dletras[j])
print "descomprimi",dletras[j],"con el codigo: ",dcodigo[j]
text = ""
i = i + 1
ash = 0
break
if ash == 0:
ash = 1
break
else:
i = i + 1
text += "".join(cadena[i])
#text += "0"
#for j in range (len(dcodigo)):
# print "codigo : ",dcodigo[j],"vs text: ",text,""
# if text == dcodigo[j]:
# print dletras[j]
# text = ""
# ash = 0
# i = i + 1
# break
#if ash == 0:
# ash = 1
# break
#i = i + 1
#text += "".join(cadena[i])
#print "texto actual: ",text
#i = i + 1
#i = i + 1
return dec
def proceso(cadena):
##########enviar datos ################
cont = 0
texto = ""
final = ""
for i in range(len(cadena)):
cont = cont + 1
texto += "".join(cadena[i])
if cont == 8:
cont = 0
print "bloque a comprimir : ",texto
recivir = comp(texto)
print "lo que me envio: ",recivir
final += "".join(receptor(recivir))
#print "si iso algo"
print "cadena actual: ",final
texto = ""
# while
# resivir = maquina(cadena[i])
###########enviar datos################
print "cadena original: ",final
def comp(letra):
global letras
global cantidad
global nletras
global cer
global arb
global cond
global inte
cont = 0
enviar = ""
si = 1
ver = 1
inte += 1
pos = 0
for i in range (len(letra)):
for le in range (len(letras)):
if letras[le] == letra[i]:
nletras[le] += 1
print codigo[le]
si = 0
enviar +="".join(codigo[le])
###modifique desde aqui
if inte == 2:
inte = 0
mayor = nletras[0]
for l in range (len(nletras)):
if mayor < nletras[l]:
mayor = nletras[l]
pos = 0
if mayor != nletras[0]:
cont1 = letras[pos]
cont2 = letras[0]
letras[0],letras[pos] = cont1,cont2
cont1 = codigo[pos]
cont2 = codigo[0]
codigo[0],codigo[pos] = cont1,cont2
cont1 = nletras[pos]
cont2 = nletras[0]
nletras[pos],nletras[0] = cont1,cont2
enviar += "".join('%')
enviar += "".join(""+str(letras[0])+"")
# enviar += "".join('')
enviar += "".join('%')
#enviar += "".join('$')
#enviar +="".join(""+str(letras[0])+""+str(codigo[0])+"")
# enviar += "".join('')
# enviar += "".join('$')
##modifique desde aqui
if si == 1:
cod = ""
letras.append(letra[i])
nletras.append(int(1))
cantidad = cantidad + 1
for k in range(cantidad):
cod += "0"
cod += "1"
codigo.append(cod)
enviar += "".join('$')
enviar +="".join(""+str(letra[i])+""+str(codigo[len(codigo)-1])+"")
enviar += "".join('$')
#cont = 1
si = 1
return enviar
def main():
archivo = open("texto.txt","r")
cadena = ""
for i in archivo.readlines():
cadena += "".join(i)
cadena = cadena.replace(" ","-").replace("\n","-")
proceso(cadena)
#print cadena
#print letras
#print nletras
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment