From 34efdede445e29702edf33b4f5cd660e32a0c7be Mon Sep 17 00:00:00 2001 From: jan6 Date: Fri, 19 Feb 2021 09:21:15 +0200 Subject: [PATCH] edited term colors to also include black and white --- README.md | 2 +- wordlists/term16color.txt | 2 ++ wordmap.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e29509..fbd87c5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Usage: wordmap.py [string to append] where `string to append` is optional, and itself has \x1b[0m appended to it (the "reset formatting" code to stop color bleeding) for example `python3 wordmap.py wordlists/corncob_lowercase.txt "example words"` would result in `serenading` -and to use the terminal colors: `python3 wordmap.py wordlists/term16color.txt "example" "example"` +and to use the terminal colors: `python3 wordmap.py wordlists/term16color.txt "colored" "colored"` it can also be imported, something like `python3 -c 'a="example";from wordmap import wordmap;wordmap("wordlists/term16color.txt",a);print(a+"\x1b[0m")'` diff --git a/wordlists/term16color.txt b/wordlists/term16color.txt index 1b9d4a0..27c21ab 100644 --- a/wordlists/term16color.txt +++ b/wordlists/term16color.txt @@ -1,3 +1,4 @@ +    @@ -5,6 +6,7 @@    +    diff --git a/wordmap.py b/wordmap.py index c3d9456..76cf6b7 100755 --- a/wordmap.py +++ b/wordmap.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from sys import argv +from math import floor from hashlib import blake2b @@ -26,7 +27,8 @@ def wordmap(wordlist_file: str, input: str, digest_size: int = 4): words_max = len(words) digest_max = int.from_bytes(b'\xff' * digest_size, "big") input_hash = hashfun(input, digest_size=digest_size) - input_hash_mapped = scale(input_hash, (0, digest_max), (0, words_max)) + input_hash_mapped = scale(input_hash, (0, digest_max), (0, words_max-1)) + #floor, to make sure it doesn't round over the max input_hash_mapped = round(input_hash_mapped) print(words[input_hash_mapped], end="")