Created
July 11, 2019 11:28
-
-
Save Sam-Lane/ae4b700bb85af7006744c4bac89111d3 to your computer and use it in GitHub Desktop.
Censor a CTF flag by changing chars * except first and last n chars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def print_usage(): | |
print("censor_flag.py <hash> [i]\nhash = hash you wish to censor\ni = optional amount you wish to keep plain text in censored string.") | |
def censor(hash, uncensor_amount=3): | |
uncensor_amount = int(uncensor_amount) | |
hash_length = len(hash) | |
censored_hash = hash[:uncensor_amount] | |
censored_hash += "*" * (hash_length - uncensor_amount * 2) | |
censored_hash += hash[-uncensor_amount:] | |
print(censored_hash) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print_usage() | |
exit(1) | |
if len(sys.argv) == 3: | |
censor(sys.argv[1], sys.argv[2]) | |
else: | |
censor(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment