This kata aims to show the vulnerabilities of hashing functions for short messages.

When provided with a SHA-256 hash, return the value that was hashed. You are also given the characters that make the expected value, but in alphabetical order.

The returned value is less than 10 characters long. Return `nil` for Ruby and Crystal, `None` for Python, `null` for Java when the hash cannot be cracked with the given characters.

---

Example:
--------
```
Example arguments: '5694d08a2e53ffcae0c3103e5ad6f6076abd960eb1f8a56577040bc1028f702b', 'cdeo'
Correct output: 'code'
```

Source: codewars | Difficulty: EASY
Tags: Ad-hoc

Starter code: def sha256_cracker(hash, chars):
	

Solutions:
from hashlib import sha256
from itertools import permutations

def sha256_cracker(hash, chars):
	for p in permutations(chars, len(chars)):
		current = ''.join(p)
		if sha256(current.encode('utf-8')).hexdigest() == hash:
			return current


import hashlib
import itertools

def sha256_cracker(hash, chars):
	for p in itertools.permutations(chars):
		if toSHA256(''.join(p)) == hash:
			return ''.join(p)
	return None

def toSHA256(s):
	m = hashlib.sha256()
	m.update(s.encode())
	return m.hexdigest()


from itertools import permutations
from hashlib import sha256

def sha256_cracker(hash, chars):
	return next(iter((''.join(p) for p in permutations(chars) if sha256(str.encode(''.join(p))).hexdigest() == hash)), None)


from hashlib import sha256
from itertools import permutations as p
sha256_cracker = lambda h, c: next((''.join(i) for i in p(c) if sha256(''.join(i).encode()).hexdigest() == h), None)


import hashlib
import itertools

def hashit(str):
	result = hashlib.sha256(str.encode())
	return result.hexdigest()

def guess(chars):
	yield from list(itertools.permutations(chars, len(chars)))

def sha256_cracker(hash, chars):
	for x in guess(chars):
		str = ''.join(x)
		if hashit(str) == hash:
			return str
	return None


import hashlib
from itertools import permutations

def sha256_cracker(code, chars):
	x = [''.join(i) for i in permutations(chars)]
	for i in x:
		if hashlib.sha256(str.encode(i)).hexdigest() == code:
			return i


from itertools import permutations
from hashlib import sha256

def sha256_cracker(hash, chars):
	return next((''.join(p) for p in permutations(chars) if sha256(''.join(p).encode('utf-8')).hexdigest() == hash), None)


from hashlib import sha256
from itertools import permutations

def sha256_cracker(hash, chars):
	for x in map(''.join, permutations(chars)):
		if sha256(x.encode()).hexdigest() == hash:
			return x


import hashlib
from itertools import permutations

def sha256_cracker(hash, chars):
	bs = chars.encode()
	h = bytes.fromhex(hash)
	return next((bytes(xs).decode() for i in range(1, min(10, len(bs)) + 1) for xs in permutations(bs, i) if hashlib.sha256(bytes(xs)).digest() == h), None)