Cifrado rot13 y atbash

Iniciado por Once, Abril 12, 2013, 02:05:07 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Les dejo un par de algoritmos que me pusieron e trabajo en la U por si a alguien le es de utilidad, la idea es codificar con rot13 y atbash sin importar librerias.

Código: python

#!/usr/bin/python2

#65 90
#97 122

def rot13(palabra):
    Cifrado = ''
    for i in palabra:
        buff = ord(i)
        if (buff >= 65 and buff <= 90) or (buff >= 97 and buff <= 122):
            if ((buff + 13 > 90 and buff + 13 <= 103) or (buff + 13 > 122 and buff + 13 <= 135)):
                Cifrado += chr(buff -13)
            else:
                Cifrado += chr(buff + 13)
    print Cifrado
   
def atbash(palabra):
    V1 = "abcdefghijklm"
    V2 = "zyxwvutsrqpon"
   
    Buff = ""
   
    for i in range(len(palabra)):
        for a in range(len(V1)):
            if V1[a] == palabra[i]:
                Buff += V2[a]
            elif V2[a] == palabra[i]:
                Buff += V1[a]
    print Buff

atbash("criptografia")
rot13("Criptografia")


Saludos!







You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Abril 23, 2013, 06:11:34 PM #1 Ultima modificación: Mayo 03, 2014, 11:18:21 AM por Flemon
Colega ! , muy buen código !
Espero no te moleste que lo haya pasado a Python CGI para poder correrlo desde la Web :D

El código para los interesado:
Código: python

#!/usr/bin/python
#Original: 11Sep
#To CGI: JaAViEr::0x5d - @0x5d
import cgi, os

def  formulario_inicial():
form_html = '''
<form action="" method="POST">
Data: <br/>
<textarea name="contenido"></textarea><br />
<select name="opcion">
<option value="rot13">ROT13</option>
<option value="atbash">Atbash</option>
</select><br />
<input type="Submit"><br/>
Programado por <b>11Sep</b><br />
Programado en CGI por <b>JaAViEr::0x5d</b>
</form>
'''
return base("Cifrar Rot13/Atbash", form_html)

def base(title, content):
code = '''
<div class="ui-widget-content">
<div class="ui-widget-header">%s</div>
%s
</div>
'''%(title, content)
return code

def rot13(palabra):
    Cifrado = ''
    for i in palabra:
        buff = ord(i)
        if (buff >= 65 and buff <= 90) or (buff >= 97 and buff <= 122):
            if ((buff + 13 > 90 and buff + 13 <= 103) or (buff + 13 > 122 and buff + 13 <= 135)):
                Cifrado += chr(buff -13)
            else:
                Cifrado += chr(buff + 13)
    return Cifrado
   
def atbash(palabra):
    V1 = "abcdefghijklm"
    V2 = "zyxwvutsrqpon"
   
    Buff = ""
   
    for i in range(len(palabra)):
        for a in range(len(V1)):
            if V1[a] == palabra[i]:
                Buff += V2[a]
            elif V2[a] == palabra[i]:
                Buff += V1[a]
    return Buff

print "content-type:text/html\r\n\r\n"
print '''
<title>Cifrar Rot13/Atbash 11Sep::JaAViEr</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/cupertino/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<style>
div {
text-align:center;
font-size:0.5cm;
}
input, select {
height:0.7cm;
font-size:0.4cm;
}
</style>
'''
form = cgi.FieldStorage()
method = os.environ['REQUEST_METHOD']
contenido = form.getvalue("contenido")
opcion = form.getvalue("opcion")
if method == "POST":
if opcion:
if opcion == "rot13":
print formulario_inicial()
print base("Salida", "<textarea>"+rot13(contenido)+"</textarea>")
elif opcion == "atbash":
print formulario_inicial()
print base("Salida", "<textarea>"+atbash(contenido)+"</textarea>")
else:
print formulario_inicial()
print base("ERROR","Opción inválida")
else:
print formulario_inicial()
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Para nada brother, le hecharé un vistazo al code, hace tiempo que tengo ganas de pasar un viejo wargame que tengo a python

Saludos!







You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Se ve excelente el code, buen aporte!

-Saludos-