# Primer programa

## <mark style="color:blue;">Hasher</mark>

Es un programa en Python que permite cifrar una cadena de texto utilizando diferentes tipos de algoritmos de cifrado, como NTLM, MD5 y SHA-256. El usuario introduce la cadena de texto y el programa realiza el proceso de cifrado correspondiente, devolviendo como resultado el valor cifrado en formato hexadecimal.

El programa presenta un menú para que el usuario pueda seleccionar el tipo de cifrado que desea utilizar. Además, permite al usuario repetir el proceso de cifrado con otra cadena de texto o salir del programa.

En resumen, "hasher" es una herramienta sencilla y útil para cifrar información de manera segura utilizando diferentes algoritmos de cifrado.

{% embed url="<https://github.com/afsh4ck/hasher>" %}

```python
import hashlib

verde = "\033[1;32m"
amarillo = "\033[1;33m"
magenta = "\033[95m"
cyan = "\033[96m"
default = "\033[0m"


def cabecera():
    print(title)
    print(divider)


title = """
$$\                           $$\                           
$$ |                          $$ |                          
$$$$$$$\   $$$$$$\   $$$$$$$\ $$$$$$$\   $$$$$$\   $$$$$$\  
$$  __$$\  \____$$\ $$  _____|$$  __$$\ $$  __$$\ $$  __$$\ 
$$ |  $$ | $$$$$$$ |\$$$$$$\  $$ |  $$ |$$$$$$$$ |$$ |  \__|
$$ |  $$ |$$  __$$ | \____$$\ $$ |  $$ |$$   ____|$$ |      
$$ |  $$ |\$$$$$$$ |$$$$$$$  |$$ |  $$ |\$$$$$$$\ $$ |      
\__|  \__| \_______|\_______/ \__|  \__| \_______|\__|      

A really simple multiple encripting              < afsh4ck >
"""

divider = """------------------------------------------------------------
"""


def menu():
    print(verde + "[*] Selecciona el tipo de cifrado:" + default)
    print("1. NTLM")
    print("2. MD5")
    print("3. SHA256")
    print("4. Salir")
    opcion = input(amarillo + "[*] Escribe el número de la opción: " + default)
    return opcion


def hasher(tipo_cifrado):
    texto = input(
        magenta + "[*] Introduce el texto a cifrar en " + tipo_cifrado + ": " + default)
    if tipo_cifrado == "NTLM":
        valor_hash = hashlib.new('md4', texto.encode('utf-16le')).hexdigest()
    elif tipo_cifrado == "MD5":
        valor_hash = hashlib.md5(texto.encode()).hexdigest()
    else:
        valor_hash = hashlib.sha256(texto.encode()).hexdigest()
    print(cyan + "[*] " + tipo_cifrado + " hash:" + default, valor_hash)
    print(divider)


cabecera()
while True:
    opcion = menu()
    if opcion == "1":
        hasher("NTLM")
    elif opcion == "2":
        hasher("MD5")
    elif opcion == "3":
        hasher("SHA256")
    elif opcion == "4":
        break
    else:
        print("Opción no válida")
    respuesta = input(amarillo + "[*] ¿Deseas hacer otra operación? (S/N): ")
    if respuesta.upper() == "N":
        break
    elif respuesta.upper() == "S":
        continue

print(verde + "[*] ¡Hasta luego!")
```

<figure><img src="/files/842FmAZ2bhQo0R9l4tvE" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://afsh4ck.gitbook.io/desarrollo-con-python/conceptos-basicos/primer-programa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
