|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# added by : H4Z3 |
| 4 | +# edit of Mart | marvhus MD5 module |
| 5 | + |
| 6 | +import hashlib |
| 7 | + |
| 8 | +# help menu for cipheringing process |
| 9 | +help_menu = """ |
| 10 | +USAGE: |
| 11 | + key blake2b [FLAGS] [OPTIONS] |
| 12 | +
|
| 13 | +FLAGS: |
| 14 | + -b, --brute Brute force hash |
| 15 | + -e, --encrypt Encrypt input text or file |
| 16 | + -h, --help Prints help information |
| 17 | + -V, --version Prints version information |
| 18 | +
|
| 19 | +OPTIONS: |
| 20 | + -i, --inputFile <input file> Input file to encrypt or decrypt |
| 21 | + -o, --output <output file> Output file for encrypted or decrypted text |
| 22 | + -r, --range <number> Max guess length (required if brute forcing dynamically) |
| 23 | + -t, --text <text> Input text to encrypt or decrypt |
| 24 | + -w, --wordlist <input file> Wordlist (required if brute forcing with wordlist) |
| 25 | +
|
| 26 | +EXAMPLES: |
| 27 | + key blake2b -e -t "hello" |
| 28 | +""" |
| 29 | + |
| 30 | +# decode function [!] Each Cipher Must Have This <---------- [!] |
| 31 | +def encode(args): |
| 32 | + # Getting text from all passed in args |
| 33 | + # All other args can be grabbed the same way |
| 34 | + # Example key = input.key | range = input.range |
| 35 | + text = args.text |
| 36 | + salt = args.salt |
| 37 | + |
| 38 | + if text: |
| 39 | + # Run Decode |
| 40 | + output = f'Encoding | {text}' |
| 41 | + |
| 42 | + # Detect Salt |
| 43 | + if salt: |
| 44 | + rawresult = hashlib.blake2b( salt.encode('ascii') + |
| 45 | + text.encode('ascii') ).digest() |
| 46 | + output += f'Salt | {salt}' |
| 47 | + else: |
| 48 | + rawresult = hashlib.blake2b( text.encode('ascii') ).digest() |
| 49 | + |
| 50 | + result = rawresult.hex() |
| 51 | + |
| 52 | + output += f"\nBlake2b Raw Sum | {rawresult}\nBlake2b Sum | {result}" |
| 53 | + |
| 54 | + # Output content as string for main.py to print |
| 55 | + # Pass True if Success Message |
| 56 | + return [output,True] |
| 57 | + else: |
| 58 | + # Pass False if Fail Message |
| 59 | + # Return Nothing to have no output |
| 60 | + return [f'"{text}" is not a valid input for -t', False] |
| 61 | + |
| 62 | +# brute function [!] Optional Per Cipher <----------------- [!] |
| 63 | +def brute(args): |
| 64 | + # Getting text from all passed in args |
| 65 | + # All other args can be grabbed the same way |
| 66 | + # Example key = input.key | range = input.range |
| 67 | + text = args.text |
| 68 | + |
| 69 | + if args.wordlist and args.range: |
| 70 | + return ["Please only pick one '-r' or '-w\'", False] |
| 71 | + |
| 72 | + if text and args.wordlist: |
| 73 | + wordlist = args.wordlist |
| 74 | + |
| 75 | + # Run Decode |
| 76 | + output = f'Bruteforcing | {text}' |
| 77 | + |
| 78 | + length = len(wordlist) |
| 79 | + |
| 80 | + print() |
| 81 | + for i, word in enumerate(wordlist): |
| 82 | + print(f'Checking {i + 1}/{length}', end='\r') |
| 83 | + guess = hashlib.blake2b( word.encode('ascii') ).hexdigest() |
| 84 | + if guess.lower() == text.lower(): |
| 85 | + output += f'\nDecoded Blake2b | {word}' |
| 86 | + return [output, True] |
| 87 | + continuear |
| 88 | + print() |
| 89 | + |
| 90 | + output = "Not found in wordlist" |
| 91 | + # Output content as string for main.py to print |
| 92 | + # Pass True if Success Message |
| 93 | + return [output, False] |
| 94 | + |
| 95 | + if text and args.range: |
| 96 | + import string |
| 97 | + import itertools |
| 98 | + |
| 99 | + alphabet = string.ascii_letters + string.punctuation + string.digits |
| 100 | + range_ = int(args.range) |
| 101 | + |
| 102 | + if range_ <= 0: |
| 103 | + return ["Can't use a range that is 0 or lower", False] |
| 104 | + |
| 105 | + i = 0 |
| 106 | + print() |
| 107 | + for item in itertools.product(alphabet, repeat=range_): |
| 108 | + i += 1 |
| 109 | + guess = "".join(item) |
| 110 | + print(f'Attempt {i} -- {guess}', end='\r') |
| 111 | + result = hashlib.blake2b( guess.encode('ascii') ).hexdigest() |
| 112 | + |
| 113 | + if result.lower() == text.lower(): |
| 114 | + return [f'Decoded Blake2b | {guess}', True] |
| 115 | + print() |
| 116 | + |
| 117 | + return [f'Did not decode Blake2b with max range of {range_}', False] |
| 118 | + |
| 119 | + |
| 120 | + # Pass False if Fail Message |
| 121 | + # Return Nothing to have no output |
| 122 | + |
| 123 | + if not text: |
| 124 | + return [f'"{text}" is not a valid input for -t', False] |
| 125 | + |
| 126 | + return ['Unknown error', False] |
| 127 | + |
| 128 | + |
| 129 | + |
0 commit comments