Skip to content

Instantly share code, notes, and snippets.

@simonwuelker
Last active August 20, 2025 14:33
Show Gist options
  • Select an option

  • Save simonwuelker/01eba191efed0faa352b338bdbaa0d1a to your computer and use it in GitHub Desktop.

Select an option

Save simonwuelker/01eba191efed0faa352b338bdbaa0d1a to your computer and use it in GitHub Desktop.

Revisions

  1. simonwuelker revised this gist Sep 7, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    This is a crypto challenge i created for [the hackthissite discord](https://discord.gg/hts).
    I have a working exploit, so I'm somewhat confident that everything works fine - still,
    if you run into any issues, feel free ping `Alaska#4736`.
    if you run into any issues, feel free ping `Alaska#4736`.
    (Yes, the flag is already viewable. I'm not hosting an instance of this. If you create your own flag, make it about equal in length)
  2. simonwuelker created this gist Sep 7, 2022.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    This is a crypto challenge i created for [the hackthissite discord](https://discord.gg/hts).
    I have a working exploit, so I'm somewhat confident that everything works fine - still,
    if you run into any issues, feel free ping `Alaska#4736`.
    1 change: 1 addition & 0 deletions flag.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    69 changes: 69 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    #!/usr/bin/env python3
    from Crypto.Cipher import AES
    from Crypto.Random import get_random_bytes, random
    from Crypto.Util import Counter
    import binascii

    used_nonces = set()
    MAX_NONCE = 100000

    def get_random_nonce():
    global used_nonces
    if len(used_nonces) == MAX_NONCE:
    print("""Error: Nonce space is exhausted, continuing would compromise security.
    Installing a new key will allow nonces to be reused safely, go do that :^)""")
    exit(0)

    while True:
    nonce = random.randint(0, MAX_NONCE)
    if nonce not in used_nonces:
    used_nonces.add(nonce)
    return nonce

    def encrypt(data):
    nonce = get_random_nonce()
    counter = Counter.new(nbits=128, initial_value=nonce)
    cipher = AES.new(key, AES.MODE_CTR, counter=counter)
    ciphertext = cipher.encrypt(data)
    return nonce, binascii.hexlify(ciphertext).decode("ascii")


    key = get_random_bytes(16)

    print("""Welcome to Alaska's super duper mega encryption system.
    We encrypt our data with state of the art AES-CTR mode - which is
    mathematically unbreakable since it involves a one time pad.
    You'll never be able to get the flag!""")

    while True:
    print("""Enter a number between [1-3]:
    1. Get encrypted flag.txt
    2. Encrypt your own data
    3. Quit""")
    choice = input(">")

    if choice == "1":
    with open("flag.txt", "rb") as infile:
    data = infile.read()
    nonce, ciphertext = encrypt(data)

    print("nonce:", nonce)
    print("ct:", ciphertext)
    elif choice == "2":
    print("Please give me the data to encrypt (as hex):")
    data = binascii.unhexlify(input(">"))

    if len(data) > 256:
    print("data must not be larger than 256 bytes")
    continue

    nonce, ciphertext = encrypt(data)
    print("nonce:", nonce)
    print("ct:", ciphertext)
    elif choice == "3":
    break
    else:
    print(f"Invalid input '{choice}', try again:")
    print()
    print("Bye!")

    1 change: 1 addition & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    pycryptodome==3.15.0