Skip to content

Commit

Permalink
chal done(?) just need to deploy + sol script
Browse files Browse the repository at this point in the history
  • Loading branch information
Spamakin committed Mar 14, 2024
1 parent a38f9f0 commit bbf15b9
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 18 deletions.
14 changes: 14 additions & 0 deletions chals/crypto/diagonal/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions chals/crypto/diagonal/challenge.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 20 additions & 18 deletions chals/crypto/diagonal/chal.py → chals/crypto/diagonal/public.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
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],
[0, 0, 0],
]
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()
55 changes: 55 additions & 0 deletions chals/crypto/diagonal/server.py
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions chals/crypto/diagonal/sol.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit bbf15b9

Please sign in to comment.