예제 #1
0
파일: main.py 프로젝트: esterp/xkcd-hashing
def run_worker(do_submit=True, time_limit=None):
	best = float('inf')
	guess = random.getrandbits(RANDOM_BIT_LEN)
	t = time.time()
	i = 0
	while True:
		if gmpy is not None:
			encoded = gmpy.digits(guess, 62).encode('ascii')
			digest = gmpy.mpz(skein.skein1024(encoded).digest()[::-1] + b'\0', 256)
			diff = gmpy.hamdist(digest, TARGET)
		else: # fallback implementation
			encoded = hex(guess)[2:].encode('ascii')
			digest = int(skein.skein1024(encoded).hexdigest(), 16)
			diff = bin(digest ^ TARGET).count('1')
		if diff < best:
			best = diff
			if do_submit:
				submit(guess)
			print('Found new best input with diff [%.3d]: \"%s\"' %
				(diff, guess))
		i += 1
		if time_limit and time.time() - t > time_limit:
			break
		guess += 1
	return i
예제 #2
0
def tryval(n):
    h = skein.skein1024(bytes(n, "utf8"), digest_bits=1024).hexdigest()
    d = bitdiff(h, TARGET)
    #if n % 100000 == 0:
    #    print(n)
    if d < 425:
        print(n, d)
예제 #3
0
def run_worker(do_submit=True, time_limit=None):
	best = float('inf')
	r = random.SystemRandom()
	t = time.time()
	i = 0
	while True:
		# guess = random.getrandbits(RANDOM_BIT_LEN)

		# encoded = gmpy.digits(guess, 62).encode('ascii')
		# digest = gmpy.mpz(skein.skein1024(encoded).digest()[::-1] + b'\0', 256)
		# diff = gmpy.hamdist(digest, TARGET)

		guess = hex(r.getrandbits(RANDOM_BIT_LEN))[2:]
		encoded = guess.encode('utf-8')
		digest = int(skein.skein1024(encoded).hexdigest(), 16)
		diff = bin(digest ^ TARGET).count('1')
		if diff < best:
			best = diff
			if do_submit:
				submit(guess)
			print('Found new best input with diff [%.3d]: \"%s\"' %
				(diff, guess))
		i += 1
		if time_limit and time.time() - t > time_limit:
			break
	return i
예제 #4
0
def main(args):
	hash_key = skein.skein1024(init=args.key.encode(), digest_bits=512+args.size, pers=b'emaddygen').digest()
	hash_name = skein.skein1024(init=args.name.encode(), digest_bits=512+args.size, pers=b'emaddygen').digest()

	total_hash = tuple(map(lambda x: x[0]^x[1], zip(hash_key, hash_name)))

	hash_int = int.from_bytes(total_hash, 'big')

	hash_str = letterify(hash_int)[:args.size]

	if args.position is Position.FIRST_POSITION:
		print('.'.join((args.name, hash_str)))
	elif args.position is Position.LAST_POSITION:
		print('.'.join((hash_str, args.name)))
	else:
		insert_position = hash_int % (args.size - 2) + 1
		print('.'.join((hash_str[:insert_position], args.name, hash_str[insert_position:])))
예제 #5
0
파일: xkcd.py 프로젝트: Carrigan/PyXKCDHash
def processBytes(bytesIn):
    """
    Return the difference (based on an xor) between the hashed value and the
    target value.
    """
    hashedValue = skein.skein1024(bytesIn)
    n = int(hashedValue.hexdigest(),16)
    diff = bin(n ^ xkcd).count('1')
    return diff
예제 #6
0
def gethash(smstr, mode='twofish'):
	#generating salt
	salt=b'gierghyuihflfugirugh89GYOB  IIUH ^%^&& YHGVF!@#$**R F MV GV^I"OLp;of\e\3 t49hrhf h hrushg vb'
	nhash=skein1024(salt+smstr.encode('ascii')).digest()
	tweak=salt+smstr.encode('ascii')

	# generating key 2^18 times
	if mode=='twofish':
		for x in range(2**18):
			nhash=sha512(salt+nhash).digest()
		return sha256(salt+nhash).digest()

	elif mode=='threefish':
		for x in range(2**18):
			nhash=skein1024(nhash).digest()
			if not x%256:
				tweak=md5(tweak+salt).digest()
		return skein1024(salt+nhash).digest(), tweak
예제 #7
0
def run_worker():
	best = float('inf')
	r = random.SystemRandom()
	while True:
		guess = hex(r.getrandbits(RANDOM_BIT_LEN))[2:]
		encoded = guess.encode('utf-8')
		digest = int(skein.skein1024(encoded).hexdigest(), 16)
		diff = bin(digest ^ TARGET).count('1')
		if diff < best:
			best = diff
			submit(guess)
			print('Found new best input with diff [%.3d]: \"%s\"' %
				(diff, guess))
예제 #8
0
def run_worker():
	best = 1024
	r = random.SystemRandom()
	while True:
		guess = hex(r.getrandbits(RANDOM_BIT_LEN))[2:]
		encoded = guess.encode('utf-8')
		digest = skein.skein1024(encoded).digest()
		diff = 0
		for i in range(128):
			diff += NUMBITS[TARGET[i] ^ digest[i]]
			
		if diff < best:
			best = diff
			submit(guess)
			print('Found new best input with diff [%.3d]: \"%s\"' %
				(diff, guess))
예제 #9
0
파일: hash.py 프로젝트: perryh/xkcd-hash
    def test(self, b):
        x = skein.skein1024(b)
        hex_x = x.hexdigest()
        int_x = int(hex_x, 16)
        dist = hamdist(int_x, int_goal)

        if dist < self.best:
            self.best = dist

            if dist < best_global.value:  # XXX: Race
                best_global.value = dist
                print("{} bits - {} - hashes to {}".format(dist, b, hex_x))

        if hex_x == goal:
            print("omg")
            print(b)
            print(repr(b))
            quit()
예제 #10
0
def run_worker(do_submit=True, time_limit=None):
	best = float('inf')
	guess = random.getrandbits(RANDOM_BIT_LEN)
	t = time.time()
	i = 0
	while True:
		encoded = gmpy.digits(guess, 62).encode('ascii')
		digest = gmpy.mpz(skein.skein1024(encoded).digest()[::-1] + b'\0', 256)
		diff = gmpy.hamdist(digest, TARGET)
		if diff < best:
			best = diff
			if do_submit:
				submit(guess)
			print('Found new best input with diff [%.3d]: \"%s\"' %
				(diff, guess))
		i += 1
		if time_limit and time.time() - t > time_limit:
			break
		guess += 1
	return i
예제 #11
0
def run_worker():
    #method of naming each thread individually
    time.sleep(random.random()*cpu_count()) #reduces chance of two processes claiming the same id
    count =0
    for item in process_array:
        if item==0:
            #local_id is this threads process id
            local_id = count
        count +=1
    process_array[local_id] = 1
    
    best = high_value.value
    
    guess = random.getrandbits(128)
    start_time = time.time()
    
    i = 1
    
    while True:
	
	#the meat of the loop
        encoded = hex(guess)[2:].encode('ascii')
        digest = int(skein.skein1024(encoded).hexdigest(), 16)
        diff = bin(digest ^ TARGET).count('1')
	
        if diff < best:
            if diff < high_value.value:
                best = diff
                high_value.value = best
                print("pid:", local_id, "::", 'Found new best [%.3d]: \"%s\"' %(diff, encoded))
                
            if diff > high_value.value:
                best = high_value.value
                
        if i%500000==0:
            current_speed = i/(time.time()-start_time)
            process_array[local_id] = current_speed

        i += 1
        guess += 1
	if len(x)<len(y):
		x = '0'*(len(y)-len(x))+x
	diffCnt = 0
	for i in range(len(x)):
		if x[i] != y[i]:
			diffCnt += 1
	return diffCnt

correct = b"5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6"
bestCnt = int(re.search(r'olin\.edu","(\d+)"', requests.get("http://almamater.xkcd.com/").text).group(1))
log = open("log.txt", "w+")

print('Best count:', bestCnt)

letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

while True:
	a = ""
	for i in range(random.randint(2,1000)):
		curr = letters[random.randint(0,len(letters)-1)]
		a = a + curr
		theHash = str(skein.skein1024(a.encode(), digest_bits=1024).hexdigest())
		newCnt = diffHex(correct,theHash.encode())
		if newCnt < bestCnt:
			bestCnt = newCnt
			requests.post("http://almamater.xkcd.com/?edu=olin.edu", {'hashable': a})
			log.write("NEW:\n|%s|\n%d\n\n" %(a, bestCnt))
			print("NEW:\n"+"|"+a+"|")
			print(bestCnt)
			print("\n")
예제 #13
0
def hashWord(word):
    """ Returns a hash for a given word """
    h = skein1024(word.encode('UTF-8'), digest_bits=1024)
    return h.hexdigest()
예제 #14
0
def find_hash(nonce, core_id):
    h = skein1024()
    h.update(nonce.to_bytes(16, "little"))
    h.update(core_id.to_bytes(3, "little"))

    return h.digest()
예제 #15
0
def get_skein_hash(input_string):
  h = skein1024(digest_bits=1024)
  h.update(input_string.encode('utf-8'))
  return h.hexdigest()
예제 #16
0
import skein
from numpy import bitwise_xor, binary_repr
from binascii import unhexlify
import random

#h = skein.skein1024(b'test', digest_bits=1024)
#my_hash = h.digest()

real_hash='5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6'
real_hash_hex=unhexlify(real_hash)

while True:
  input = str(random.random()).encode()
  sk = skein.skein1024(input, digest_bits=1024)
  my_hash=sk.digest()
  g = 0
  for x in ''.join([binary_repr(j) for j in [bitwise_xor(real_hash_hex[i],my_hash[i]) for i in range(0,len(real_hash_hex))]]):
    g+=int(x)
  if g < best:
    print(g)
    print(input)
    best = g

예제 #17
0
파일: 1193.py 프로젝트: bitcars/xkcd-1193
    theString = ''.join(random.choice(candidate_chars) for x in range(strlen))
    return theString


print()

best_hash = 1024
min_hash = ''
nattempts = 0
n = 0
candidate_chars = string.printable[:-6]
strlen = 2
attempt = newstring(strlen,candidate_chars)

while True:
    attempt_hash = skein1024(bytes(attempt, 'ascii'), digest_bits=1024).hexdigest()
    attempt_bytes = hash2bytes(attempt_hash)
    d = hashdiff(attempt_bytes,target_bytes)
    if d < best_hash:
        best_hash = d
        min_hash = attempt
        if d < THRESHOLD:
            sendit(attempt,d)
            THRESHOLD = d
    nattempts += 1
    n += 1
    if (n >> 10):
        sys.stdout.write('\r%d hashes compared. Best so far is %d' % (nattempts, best_hash))
        attempt = newstring(strlen-1,candidate_chars)
        n = 0
    attempt = attempt + random.choice(candidate_chars)
예제 #18
0
	"""

    r = requests.post("http://almamater.xkcd.com/?edu=" + institution,
                      {"hashable": bytes})
    print(r.text)
    # The hash supplied by xkcd


xkcdhash = "5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6"

best = 418
pre = ""
try:
    while True:
        x = random_bytes()
        h = skein1024()
        val = pre + str(x)
        #x = random_bytes()
        h.update(val.encode())
        diff = int(h.hexdigest(), 16) ^ int(xkcdhash, 16)
        diffbits = bin(diff).count("1")
        if (diffbits < best):
            print()
            print("New best: {} ({})".format(h.hexdigest(), diffbits))
            best = diffbits
            print(val + "->" + str(diffbits))
            submit_to_xkcd(val)
            print("\n")

except KeyboardInterrupt:
    print("Finished.")
예제 #19
0

def get_random_string():
    slen = random.randint(2, 200)
    return "".join(random.choice(alphabet) for _ in range(slen)).encode("ascii")


def hamming_dist(hex_str1, hex_str2):
    def hex_to_bytes(hex_str):
        size = len(hex_str) * 4
        return (bin(int(hex_str, 16))[2:]).zfill(size)

    bytes1 = hex_to_bytes(hex_str1)
    bytes2 = hex_to_bytes(hex_str2)
    return sum(map(str.__ne__, bytes1, bytes2))


best_dist = 1024
while True:
    string = get_random_string()

    h = skein1024(string)
    dist = hamming_dist(h.hexdigest(), target)
    if dist < best_dist:
        best_dist = dist
        print(string, dist)

        # send to xkcd and print response (for sanity check)
        r = requests.post("http://almamater.xkcd.com/?edu=berkeley.edu", data={"hashable": string})
        print(r.content)
예제 #20
0
 def test(self):
     self.assertEqual(type(skein.__version__), str)
     self.assert_(
         type(skein.skein256()) is type(skein.skein512()) is type(
             skein.skein1024()))
예제 #21
0
def find_hash(nonce, core_id):
    h = skein1024()
    h.update(nonce.to_bytes(16, "little"))
    h.update(core_id.to_bytes(3, "little"))

    return h.digest()
예제 #22
0
파일: common.py 프로젝트: cg123/xkcdbrute
def plaintext_score(pt):
	hash_ = skein.skein1024(pt.encode(), digest_bits=1024).hexdigest()
	return hamming_distance(hash_, target)
예제 #23
0
# Required:
# # Python 3.2 (32 bit)
# # Skein module (Currently only works with 32 bit version of Python 3.2)

import skein
import random

bestguess = ""
bestscore = 1024 # Replace with current best score before running so that only better scores are printed
target = "5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6"

# Function inputs two hex values as strings, and returns the bit differential
def hexdiff(hex1, hex2):
  try:
    return bin(int(hex1, 16)^int(hex2, 16)).count('1') # This is the number of different bits in the hash
  except:
    print("hexdiff inputs must be valid hex strings")
  
seednum = 123467891544 + random.random()
  
while True:
  testvalue = str(seednum).encode('utf-8')
  test = skein.skein1024(init=testvalue, digest_bits=1024)
  score = hexdiff(test.hexdigest(), target)
  if score < bestscore:
    bestguess = testvalue
    bestscore = score
    print(bestguess, score)
  seednum += 1