# -*- coding: utf-8 -*-
#Yazar : aintnobody
#Kullanım : hash("test")
#İşlev : Şifreleme (Karıştırma yöntemi ile)
import binascii
import hashlib
import base64
def hash(toHash):
# Değişkenler
CRYPT_VALUES = [-9, 25, -92, -37, -117, 18, 112, -95, -5, -108, 40, -83, -107, 73, -92, -102, 46, -52, 49, -118, -79, -56, -72, 63, -69, -98, -118, -22, 46, -16, -22, -111]
HEX_CHARS = "0123456789abcdef"
# SHA256 ile karıştır
toHash_sha256 = hashlib.sha256(toHash).hexdigest()
HashBytes = []
# Step 1 : toHash_sha256 içindeki tüm karakterleri HashBytes içerisine yerleştir, belli baytlara dönüştür
for char in toHash_sha256:
HashBytes.append(ord(char))
# Step 2 : HashBytes içine dizininin eklendiği tüm cryptValues değerlerini yerleştir
for indice in range(0, len(CRYPT_VALUES)):
HashBytes.append(int(CRYPT_VALUES[indice] + indice))
# Step 3 : HashBytes dizisini Hexdecimal (onaltılık) bir dizeye dönüştür, hexChars için kullanılacak dizinleri al
HashHex = ""
for byte in HashBytes:
# İlk dizin: Bayt, hex (0-15) bir değer elde etmek için (4 bit çünkü 2^4 = 16)
firstId = (byte >> 4) & 15
# İkinci dizin : Kalan bayt
secondId = byte & 15
# Hex karakterleri ekle
HashHex = HashHex + HEX_CHARS[firstId] + HEX_CHARS[secondId]
# Step 4 : Çeşitli dönüşümler
HashHex_bin = binascii.unhexlify(HashHex) # Hex => Binary
HashHex_sha256_bin = hashlib.sha256(HashHex_bin).digest() # Binary => SHA256 Binary
HashHex_sha256_b64 = base64.b64encode(HashHex_sha256_bin) # SHA256 Binary => SHA256 Base64
return HashHex_sha256_b64