diff --git a/chals/crypto/diagonal/Dockerfile b/chals/crypto/diagonal/Dockerfile new file mode 100644 index 0000000..4e00805 --- /dev/null +++ b/chals/crypto/diagonal/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install -y socat python3 + +RUN adduser chal + +RUN mkdir -p /chal +WORKDIR /chal + +COPY chal.py flag.txt ./ +RUN chmod 555 chal.py +USER chal + +CMD socat -T60 TCP-LISTEN:1337,fork,reuseaddr EXEC:"python3 -u chal.py",stderr diff --git a/chals/crypto/diagonal/challenge.yml b/chals/crypto/diagonal/challenge.yml new file mode 100644 index 0000000..6b65c76 --- /dev/null +++ b/chals/crypto/diagonal/challenge.yml @@ -0,0 +1,25 @@ +name: "Diagonal" +author: Anakin +category: Crypto +description: |- + We've tried and failed with horizontal and vertical integration. + Hopefully something more angular will catch on. + + `nc chal.fallctf.sigpwny.com 6001` + + **author**: Pete +value: 500 +type: dynamic +tags: + - medium +extra: + initial: 500 + decay: 150 + minimum: 100 +flags: + - sigpwny{mult1d1m3n510n4l} +files: + - public.py +hints: + - Play with some matrices, see how the exponent affects the entries, get some equations going +state: hidden diff --git a/chals/crypto/diagonal/chal.py b/chals/crypto/diagonal/public.py similarity index 53% rename from chals/crypto/diagonal/chal.py rename to chals/crypto/diagonal/public.py index 3ef05fd..da82c4a 100644 --- a/chals/crypto/diagonal/chal.py +++ b/chals/crypto/diagonal/public.py @@ -1,12 +1,10 @@ import numpy as np import random -import sympy as sp - -FLAG = "sigpwny{testing_yay!}" +FLAG = "sigpwny{????????????????}" def inputs(): - print("Define a 3 x 3 Integer Matrix M") + print("[D] Define a 3 x 3 Integer Matrix M") M = [ [0, 0, 0], [0, 0, 0], @@ -14,40 +12,44 @@ def inputs(): ] for i in range(3): for j in range(3): - M[i][j] = int(input(f"[D] M[{i}][{j}] = ")) + try: + M[i][j] = int(input(f"[D] M[{i}][{j}] = ")) + except: + return None return M def fun(M_, d): - M = np.matrix(M_) + M = np.matrix(M_, dtype='object') M = M**d + # [\\\] + # [ \\] + # [ \] return M[0, 0] + M[1, 1] + M[2, 2] + M[0, 1] + M[1, 2] + M[0, 2] def main(): secret = random.randint(1_000_000_000, 10_000_000_000) + print("[D] Welcome") M = inputs() + if M == None: + print("[D] You tried something weird...") + return + res = fun(M, secret) print() print(f"[D] Have fun: {res}") print() - guess = int(input(f"[D] Make a guess: ")) + try: + guess = int(input(f"[D] Make a guess: ")) + except: + print("[D] You tried something weird...") + return if guess == secret: print(f"[D] {FLAG}") else: print(f"[D] Better luck next time!") - - # # Some test solutions - # disc = (25 - 4 * (6 - 2*int(res)))**(0.5) - # sec_ = (-5 + disc) // 2 - # print(sec_) - - # n = sp.Symbol('n') - # print(sp.solve(3 + 2*n + (n**2 + n) / 2 - res, n)) - - - if __name__ == "__main__": main() diff --git a/chals/crypto/diagonal/server.py b/chals/crypto/diagonal/server.py new file mode 100644 index 0000000..7956eb9 --- /dev/null +++ b/chals/crypto/diagonal/server.py @@ -0,0 +1,55 @@ +import numpy as np +import random + +FLAG = "sigpwny{mult1d1m3n510n4l}" + +def inputs(): + print("[D] Define a 3 x 3 Integer Matrix M") + M = [ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0], + ] + for i in range(3): + for j in range(3): + try: + M[i][j] = int(input(f"[D] M[{i}][{j}] = ")) + except: + return None + return M + +def fun(M_, d): + M = np.matrix(M_, dtype='object') + M = M**d + + # [\\\] + # [ \\] + # [ \] + return M[0, 0] + M[1, 1] + M[2, 2] + M[0, 1] + M[1, 2] + M[0, 2] + +def main(): + secret = random.randint(1_000_000_000, 10_000_000_000) + + print("[D] Welcome") + M = inputs() + if M == None: + print("[D] You tried something weird...") + return + + res = fun(M, secret) + print() + print(f"[D] Have fun: {res}") + print() + try: + guess = int(input(f"[D] Make a guess: ")) + except: + print("[D] You tried something weird...") + return + + if guess == secret: + print(f"[D] {FLAG}") + else: + print(f"[D] Better luck next time!") + +if __name__ == "__main__": + main() diff --git a/chals/crypto/diagonal/sol.py b/chals/crypto/diagonal/sol.py new file mode 100644 index 0000000..9060e31 --- /dev/null +++ b/chals/crypto/diagonal/sol.py @@ -0,0 +1,18 @@ +import sympy as sp + +def main(): + + res = 18669237451167230340 + + # Some solutions + disc = (25 - 4 * (6 - 2*int(res)))**(0.5) + sec_ = (-5 + disc) // 2 + print(int(sec_)) + + n = sp.Symbol('n') + print(sp.solve(3 + 2*n + (n**2 + n) / 2 - res, n)[1]) + + + +if __name__ == "__main__": + main()