Skip to content

Instantly share code, notes, and snippets.

@jef-nunes
Created May 27, 2025 17:21
Show Gist options
  • Save jef-nunes/14357004a39c6e72616c62a341dc5327 to your computer and use it in GitHub Desktop.
Save jef-nunes/14357004a39c6e72616c62a341dc5327 to your computer and use it in GitHub Desktop.
Decifrar o hash SHA256 de uma string contendo apenas números.
import hashlib
# Gerar a string hexadecimal do hash SHA256
# a partir de um texto de entrada
def gerar_hex(texto:str):
hash_obj = hashlib.sha256(texto.encode('utf-8'))
hex = hash_obj.hexdigest()
return hex
# Função que tenta decifrar o hash
def numeros_apenas(hex_alvo:str, algarismos: int):
# O loop termina ao atingir esse numero
numero_maximo = (10**algarismos)-1
for i in range (0, numero_maximo):
texto = f"{i}"
hash_obj = hashlib.sha256(texto.encode('utf-8'))
hex = hash_obj.hexdigest()
print(f"{i} : {hex}")
if hex==hex_alvo:
print(f"Valor encontrado: {i}")
break
# Teste
def teste1():
numero_alvo = 54321
hex_alvo = gerar_hex(f"{numero_alvo}")
algarismos = len(f"{numero_alvo}")
numeros_apenas(hex_alvo,algarismos)
if __name__ == "__main__":
teste1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment