Skip to content

Instantly share code, notes, and snippets.

@Sam-Lane
Created July 11, 2019 11:28
Show Gist options
  • Save Sam-Lane/ae4b700bb85af7006744c4bac89111d3 to your computer and use it in GitHub Desktop.
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
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