Underc0de

Programación Scripting => Python => Mensaje iniciado por: darkucla en Enero 15, 2020, 10:59:28 PM

Título: Cifrado Cesar ... 3 Funciones
Publicado por: darkucla en Enero 15, 2020, 10:59:28 PM
CHQF ÑUQZ, NTBEN XQF YHQFGEB YU OBPUSB PQX OURENPB OQFNE FBZ 3 RHZOUBZQF, HZN OUREN QX GQKGB, BGEN XB PQFOUREN L BGEN YHQFGEN XNF OBYÑUZNOUBZQF PQ CBFUÑXQF PQFOURENPBF QFCQEB XQF CHQPN FQEIUE L FU NXSHUQZ XB CHQPQ YQVBENE, CBE RNIBE, OBYCNEGUEXB

Código (python) [Seleccionar]

def CifradoCesar(strTexto, intROT, intMod = 27):
lstABC = list(chr(x) for x in range(65,91))
if intMod == 27:
lstABC.insert(14,"Ñ")
strCifrado = ""
for strLetra in strTexto:
strLetra = strLetra.upper()
if strLetra in lstABC:
intIndex = lstABC.index(strLetra)
intIndexCodificado = (intIndex + intROT) % len(lstABC)
strLetra = lstABC[intIndexCodificado]
strCifrado += strLetra
return strCifrado

def DescifradoCesar(strCifrado, intROT, intMod = 27):
lstABC = list(chr(x) for x in range(65,91))
if intMod == 27:
lstABC.insert(14,"Ñ")
strDescifrado = ""
for strLetra in strCifrado:
if strLetra in lstABC:
intIndex = lstABC.index(strLetra)
intIndexDecodificado = (intIndex - intROT) % len(lstABC)
strLetra = lstABC[intIndexDecodificado]
strDescifrado += strLetra
return strDescifrado

def EncuentraCifradoCesar(strCifrado):
lstABC = list(chr(x) for x in range(65,91))
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))
print("")
lstABC.insert(14,"Ñ")
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))


Código (python) [Seleccionar]

strTexto = input("Introduzca el texto a Descifrar: ")
intROT = int(input("Desplazamiento? (0 Muestra Todos): "))
if intROT == 0:
EncuentraCifradoCesar(strTexto)
else:
print("Descifrado:", DescifradoCesar(strTexto, intROT))
Título: Re:Cifrado Cesar ... 3 Funciones
Publicado por: DtxdF en Enero 15, 2020, 11:30:30 PM
Excelente para la fuerza bruta en los retos de Underc0de  :-X  ;D

~ DtxdF
Título: Re:Cifrado Cesar ... 3 Funciones
Publicado por: darkucla en Enero 15, 2020, 11:46:18 PM
Plebes, ya se los cambié...
Código (python) [Seleccionar]


def CifradoCesar(strTexto, intROT, intMod = 27):
return CodigoCesar(strTexto, intROT, intMod, True)

def DescifradoCesar(strCifrado, intROT, intMod = 27):
return CodigoCesar(strCifrado, intROT, intMod, False)

def CodigoCesar(strTexto, intROT, intMod = 27, bolCifrar=True):
lstABC = list(chr(x) for x in range(65,91))
if intMod == 27:
lstABC.insert(14,"Ñ")
strCifrado = ""
for strLetra in strTexto:
strLetra = strLetra.upper()
if strLetra in lstABC:
intIndex = lstABC.index(strLetra)
if bolCifrar:
intIndexCodificado = (intIndex + intROT) % len(lstABC)
else:
intIndexCodificado = (intIndex - intROT) % len(lstABC)
strLetra = lstABC[intIndexCodificado]
strCifrado += strLetra
return strCifrado

def EncuentraCifradoCesar(strCifrado):
lstABC = list(chr(x) for x in range(65,91))
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))
print("")
lstABC.insert(14,"Ñ")
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))

Título: Re:Cifrado Cesar ... 3 Funciones
Publicado por: darkucla en Enero 16, 2020, 12:42:18 AM
Nuevamente hay cambios.... ahora una función VoyATenerSuerte()
la cual muestra las 2 posibles soluciones basado en el numero máximo de leras repetidas, podrían ser la A o la E

Código (python) [Seleccionar]

def CifradoCesar(strTexto, intROT, intMod = 27):
return CodigoCesar(strTexto, intROT, intMod, True)

def DescifradoCesar(strCifrado, intROT, intMod = 27):
return CodigoCesar(strCifrado, intROT, intMod, False)

def CodigoCesar(strTexto, intROT, intMod = 27, bolCifrar=True):
lstABC = list(chr(x) for x in range(65,91))
if intMod == 27:
lstABC.insert(14,"Ñ")
strCifrado = ""
for strLetra in strTexto:
strLetra = strLetra.upper()
if strLetra in lstABC:
intIndex = lstABC.index(strLetra)
if bolCifrar:
intIndexCodificado = (intIndex + intROT) % len(lstABC)
else:
intIndexCodificado = (intIndex - intROT) % len(lstABC)
strLetra = lstABC[intIndexCodificado]
strCifrado += strLetra
return strCifrado

def EncuentraCifradoCesar(strCifrado):
lstABC = list(chr(x) for x in range(65,91))
VoyATenerSuerteCesar(strCifrado, lstABC)
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))
print("")
lstABC.insert(14,"Ñ")
VoyATenerSuerteCesar(strCifrado, lstABC)
for intROT in range(len(lstABC)+1):
print(intROT, DescifradoCesar(strCifrado, intROT, len(lstABC)), len(lstABC))


def VoyATenerSuerteCesar(strTexto, lstABC):
lstRepetidas = []
for strLetra in lstABC:
strLetra = strLetra.upper()
lstRepetidas.append(strTexto.count(strLetra))

intNumMax = max(lstRepetidas)
print("Voy a tener suerte....")
# Posible A
intIndex = lstRepetidas.index(intNumMax)
print(intIndex, DescifradoCesar(strTexto, intIndex))
# Posible E
intIndex = lstRepetidas.index(intNumMax)-4
print(intIndex, DescifradoCesar(strTexto, intIndex))
input("presiona enter....")