Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from multiprocessing import Process
- def encrypt(key, msg):
- key = list(key)
- msg = list(msg)
- for char_key in key:
- for i in range(len(msg)):
- if i == 0:
- tmp = ord(msg[i]) + ord(char_key) + ord(msg[-1])
- else:
- tmp = ord(msg[i]) + ord(char_key) + ord(msg[i-1])
- while tmp > 255:
- tmp -= 256
- msg[i] = chr(tmp)
- return ''.join(msg)
- def decrypt(key, msg):
- key = list(key)
- msg = list(msg)
- for char_key in reversed(key):
- for i in reversed(range(len(msg))):
- if i == 0:
- tmp = ord(msg[i]) - (ord(char_key) + ord(msg[-1]))
- else:
- tmp = ord(msg[i]) - (ord(char_key) + ord(msg[i-1]))
- while tmp < 0:
- tmp += 256
- msg[i] = chr(tmp)
- return ''.join(msg)
- def is_ascii(txt, prc = 0.6):
- tot = len(txt)
- num_ascii = 0
- for c in txt:
- if ord(c) < 128:
- num_ascii += 1
- return (num_ascii / tot) >= prc
- def are_there_some_spaces(txt, some = 5):
- tot = len(txt)
- num_spaces = 0
- for c in txt:
- if ord(c) == 0x20: # space hex code
- num_spaces += 1
- return num_spaces >= some
- def brute_force_job(words, start, end, job):
- print('I am job #{0}, trying from {1} to {2}...'.format(job, start, end))
- enc_file = open('ciphertext', 'rb')
- enc_text = enc_file.read()
- for index in range(start, end):
- key = words[index].strip()
- dec = decrypt(key, enc_text)
- try:
- # dec_text = dec.decode()
- if are_there_some_spaces(dec, 5):
- print('Found Key: {0}'.format(key))
- print('Found Txt: {0}'.format(dec))
- except:
- continue
- def brute_force(wordlist_path, cpu = 8):
- wordlist = open(wordlist_path, 'r')
- words = wordlist.readlines()
- chunk_size = len(words) / cpu
- curr_start = 0
- curr_end = curr_start + chunk_size
- for c in range(cpu):
- if c == cpu - 1:
- curr_end = len(words)
- p = Process(target=brute_force_job, args=(words, curr_start, curr_end, c))
- p.start()
- curr_start = curr_end
- curr_end = curr_end + chunk_size
- if __name__ == '__main__':
- brute_force('/usr/share/wordlists/rockyou.txt', 8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement