import string

from hacksport.problem import ProtectedFile, Remote


class Problem(Remote):
    program_name = "ecb.py"
    files = [ProtectedFile("flag"), ProtectedFile("key")]

    def initialize(self):
        # generate random 32 hexadecimal characters
        self.enc_key = "".join(
            self.random.choice(string.digits + "abcdef") for _ in range(32)
        )

        self.welcome_message = "Welcome to Secure Encryption Service version 1.{}".format(
            self.random.randint(0, 10)
        )

@@ -1,12 +1,27 @@
+import secrets%0A
 import strin
@@ -75,16 +75,54 @@
  Remote%0A
+from hacksport.deploy import flag_fmt%0A
 %0A%0Aclass 
@@ -550,20 +550,272 @@
 nt(0, 10)%0A        )%0A
+%0A    # flag length must be a multiple of 16%0A    def generate_flag(self, random):%0A        flag = (flag_fmt() %25 secrets.token_hex(32))%5B:32%5D%0A        if %22%7B%22 in flag:%0A            flag = flag%5B:31%5D + %22%7D%22%0A        assert len(flag) %25 16 == 0%0A        return flag%0A

Fix ecb-1 to assert flag length