From 4982ca7dbe93548d3a7d64b27aaaea4cdc38aa49 Mon Sep 17 00:00:00 2001 From: zeski99 Date: Wed, 13 Apr 2022 10:04:11 +0200 Subject: [PATCH] put_me_in_coach --- challs/put_me_in_coach/challenge.yml | 22 +++++++++++ challs/put_me_in_coach/freq.py | 39 +++++++++++++++++++ challs/put_me_in_coach/gen.py | 39 +++++++++++++++++++ challs/put_me_in_coach/secret.py | 13 +++++++ challs/put_me_in_coach/serve/ct.txt | 1 + .../put_me_in_coach/serve/put_me_in_coach.py | 32 +++++++++++++++ challs/put_me_in_coach/solv.py | 21 ++++++++++ challs/put_me_in_coach/text.txt | 11 ++++++ 8 files changed, 178 insertions(+) create mode 100644 challs/put_me_in_coach/challenge.yml create mode 100644 challs/put_me_in_coach/freq.py create mode 100644 challs/put_me_in_coach/gen.py create mode 100644 challs/put_me_in_coach/secret.py create mode 100644 challs/put_me_in_coach/serve/ct.txt create mode 100644 challs/put_me_in_coach/serve/put_me_in_coach.py create mode 100644 challs/put_me_in_coach/solv.py create mode 100644 challs/put_me_in_coach/text.txt diff --git a/challs/put_me_in_coach/challenge.yml b/challs/put_me_in_coach/challenge.yml new file mode 100644 index 00000000..629a3a56 --- /dev/null +++ b/challs/put_me_in_coach/challenge.yml @@ -0,0 +1,22 @@ +name: "Put me in coach" +author: "zeski" +category: Crypto + +description: | + I've seen this kind of encryption before, but the script isn't working. What's wrong with it? This isn't standard. +value: 500 +type: standard + +files: + - serve/put_me_in_coach.py + - serve/ct.txt + +flags: + - dctf{ctfs_would_be_boring_without_some_classical_ciphers} + +tags: + - crypto + +state: visible + +version: "0.1" \ No newline at end of file diff --git a/challs/put_me_in_coach/freq.py b/challs/put_me_in_coach/freq.py new file mode 100644 index 00000000..b4533730 --- /dev/null +++ b/challs/put_me_in_coach/freq.py @@ -0,0 +1,39 @@ +from string import printable + +f = open("ct.txt").readline() + +alphabet = printable[:-6] + +d = {c:0 for c in alphabet} + +for c in f: + if c in alphabet: + d[c] += 1 + +a = sum(d.values()) + +# print({k:100*v/a for k,v in d.items()}) + +for k,v in d.items(): + if v > 0: + print(f"{k}: {100*v/a}") + + +# key = dict() + +# for k,v in zip( "^!J;>o&b}ysPUcxv8z:t?pf%0Q+guHNEe4", +# "dctf{}\n._ o?ananrdistatiere"): +# key[k] = v + +# out="" + +# for c in f: +# if c in key: +# out += key[c] +# else: +# # out += c +# out += "_" + +# print(out) + +# je solvable na roke, not doing it again tho \ No newline at end of file diff --git a/challs/put_me_in_coach/gen.py b/challs/put_me_in_coach/gen.py new file mode 100644 index 00000000..3aaddaec --- /dev/null +++ b/challs/put_me_in_coach/gen.py @@ -0,0 +1,39 @@ +from math import ceil + +freq = { + "a": 8.167, + "b": 1.492, + "c": 2.782, + "d": 4.253, + "e": 12.702, + "f": 2.228, + "g": 2.015, + "h": 6.094, + "i": 6.966, + "j": 0.153, + "k": 0.772, + "l": 4.025, + "m": 2.406, + "n": 6.749, + "o": 7.507, + "p": 1.929, + "q": 0.095, + "r": 5.987, + "s": 6.327, + "t": 9.056, + "u": 2.758, + "v": 0.978, + "w": 2.360, + "x": 0.150, + "y": 1.974, + "z": 0.074, + " ": 15, +} + +extra = "\n.,{}?_-'" + +coef = 1.7 + +arr = [ceil(f/coef) for f in freq.values()] + [1]*len(extra) + +print(arr) \ No newline at end of file diff --git a/challs/put_me_in_coach/secret.py b/challs/put_me_in_coach/secret.py new file mode 100644 index 00000000..7862ca75 --- /dev/null +++ b/challs/put_me_in_coach/secret.py @@ -0,0 +1,13 @@ +text = """Following norms and regulations is essential for electricians. These norms and regulations exist to ensure that proper safety measures are taken while working, and to guarantee safe, high quality installations. In this text, I will discuss what kind of consequences breaching norms and regulations can bring in the field of an electrician. Can a breach of norms and regulations potentially reach the newspaper headlines? + +In vocational professions, a norm is an official standard that an organization is expected to reach. These are not to be confused with social norms. In almost every field in engineering, you have norms that you need to follow, and these are often set according to market standards. Norms are guidelines to maintain official standards. Rules and regulations on the other hand, are set by committees or tribunals, and are mandatory for every electrician. In Norway, the Norwegian law is a foundation for rules and regulations. + +Engineers and electricians alike take pride in making their work look organized and neat. Making the installations functional is only half of the job. There are a lot of unwritten rules for making an organized installation. At what length to strip the cables, where to clamp cables to a wall, or placement of switches and cable boxes are all examples of this. These seemingly trivial skills are vital to an engineer's skillset and are arguably equally important as following the official rules and regulations. Breaking these norms does not pose a threat to personal or structural damage, but it can lead to the customer being dissatisfied. + +A vital aspect of an electrical installation is to choose the correct diameter of the cables. In Norway, the NEK-400 norms (Norwegian Electronic Committee) are used as guidelines for picking the right cable diameter. Varying thickness of cables can conduct different amounts of current without overheating, and it is therefore important to calculate exactly how much current your components will draw. Installing a cable with the wrong dimension can have critical consequences. To have a wider cable than necessary causes no technical problem. However, if the cable is not rated for the appropriate currents, the cable will overheat and potentially catch fire. + +To know the norms and regulations is crucial to an electrician's field. As I have discussed, not following them can have unfortunate consequences. An installation could be certified by official rules while being unorganized. Likewise, you could have an installation that looks expertly executed, but is indeed a fire hazard. Breaching official regulations have the greatest potential to have a critical outcome. Simply choosing too narrow of a cable could have the potential to for example spark a large-scale factory fire. I would argue that this is a headline-worthy event. In conclusion, rules, norms and regulations should always be followed to ensure a safe and expertly done installation. + +dctf{ctfs_would_be_boring_without_some_classical_ciphers}""" + +mapping = [5, 1, 2, 3, 8, 2, 2, 4, 5, 1, 1, 3, 2, 4, 5, 2, 1, 4, 4, 6, 2, 1, 2, 1, 2, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1] diff --git a/challs/put_me_in_coach/serve/ct.txt b/challs/put_me_in_coach/serve/ct.txt new file mode 100644 index 00000000..683c1343 --- /dev/null +++ b/challs/put_me_in_coach/serve/ct.txt @@ -0,0 +1 @@ +ruDYu3GjR;jfa\%hN4[PZLRcYOsGuF?}g?)6??L4'dwDhTJv;_A6S>ZiS|w4%(;sI21=qFuZ\*;Nj[Ex6/cYOH|uF1E2pd1'}{uP6]?"Z2PHyN{)+xJ+Ka;*wr_Hehb2m1cZ61;wvL}^w:L]E`IGDLn`f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QzvyLOs704[E$t'=FsgOYYoq@w>@y}rgZL(WW^8;:4J3;sy_}]txb*7mFX)Z6RcYO'gtj1)G17Sa"S|0Yn>fq0]7KYK@^vdSgmj#?PrdKA[(Pw1EGh5mQ_nXG%@"??=Xkq4t{nruAYf`i]R)^y_bESNFP5wQ_n"jTuvHcjm>zPSu]%=Mcz4SK*(nw4ndj?H0YYm>gtjq@f"D-nB6qS=a>drg=-7BenuTriSi0YhvcYU1735GA_)BKg]/;c]tZ/NFg!2-(nYG:63d%Lknofc)St"Y-}INQUEOjP|F*'NAAOsif4n>I0^PAff:*)Up$=x>Ae)=pzScs6XkqB">Pd*Pi]-L6-hmqrgZzEl0!OZX(EBazw@l|4R)uTrg@|0APZzR"A0^|8j1)ImQ=h>l2qRx2m'=?^;+J>24>GND)HuPlwQUqw}Sags|@mY}tc'@u\L(E*|\$YenSlJt?g4RqHftn]NZvu`Efr)w;SOBY_PS8"A-PI0QKPslzn+f^L4{|wD7{u7rfxqUpN\$A_)%+Oa:hNhAOa/KC%@0D2qrNS>JZoETiZ6(q|q`ucY-PNa/"zPsI0^E{5|*)g1}m)l=N-Yg]LC`fas5eqzQL4s(}|]}@tF@A"1dJFk7v"Y6*kqjJa\%PO4XqZK/"Ym{GtF?;*lJcD[)OD3Oe%EB2hruAA8`U[hHJ7K]*"v=qwh1OrKh0][7_p$6Z>Do7[t]K)ij1{OYAmsGt](WWXS>T~S{r%&3fcAX&BU&Bfv|4/&3gsl8cs&*ubU&@DO?1d@mD&SG$y_a%9 diff --git a/challs/put_me_in_coach/serve/put_me_in_coach.py b/challs/put_me_in_coach/serve/put_me_in_coach.py new file mode 100644 index 00000000..4eea63fb --- /dev/null +++ b/challs/put_me_in_coach/serve/put_me_in_coach.py @@ -0,0 +1,32 @@ +import random +from secret import text, mapping +from string import printable + +alphabet = "abcdefghijklmnopqrstuvwxyz \n.,{}?_-'" + +def gen_key(alphabet, mapping): + pool = list(printable[:-6]) + random.shuffle(pool) + + key = dict() + + for c, n in zip(alphabet, mapping): + tmp = [] + for i in range(n): + tmp.append(pool.pop()) + key[c] = tmp + return key + + +def encrypt(pt, key): + ct = "" + for c in pt: + if c in key: + ct += random.choice(key[c]) + return ct + + +key = gen_key(alphabet, mapping) + +ct = encrypt(text.lower(), key) +print(ct) diff --git a/challs/put_me_in_coach/solv.py b/challs/put_me_in_coach/solv.py new file mode 100644 index 00000000..f69e314f --- /dev/null +++ b/challs/put_me_in_coach/solv.py @@ -0,0 +1,21 @@ +key={'N': 'a', 'w': 'a', 'm': 'a', 'O': 'a', '0': 'a', 'B': 'b', '@': 'c', 'S': 'c', '[': 'd', 'X': 'd', '-': 'd', 'z': 'e', 'K': 'e', '2': 'e', 'L': 'e', 'U': 'e', '=': 'e', '_': 'e', '6': 'e', 'r': 'f', 'T': 'f', 'R': 'g', '/': 'g', 'y': 'h', 'l': 'h', '5': 'h', 'I': 'h', 'i': 'i', 'd': 'i', '|': 'i', 'G': 'i', 'g': 'i', ',': 'j', ':': 'k', 'D': 'l', 'A': 'l', 'Y': 'l', '\\': 'm', 'b': 'm', '4': 'n', ']': 'n', 'F': 'n', 'j': 'n', 'u': 'o', 'J': 'o', 't': 'o', 'f': 'o', '8': 'o', '$': 'p', '+': 'p', 'M': 'q', 'a': 'r', 'Z': 'r', 'x': 'r', 'v': 'r', '1': 's', '%': 's', '?': 's', '*': 's', "'": 't', '>': 't', 's': 't', '^': 't', 'H': 't', '{': 't', '"': 'u', 'c': 'u', 'Q': 'v', '`': 'w', '3': 'w', 'p': 'x', 'e': 'y', 'o': 'y', '!': 'z', ')': ' ', '7': ' ', 'q': ' ', 'E': ' ', 'h': ' ', ';': ' ', 'P': ' ', 'n': ' ', '}': ' ', 'W': '\n', '(': '.', 'k': ',', '~': '{', '9': '}', '.': '?', '&': '_', 'C': '-', '#': "'"} + +# def gen_dec_key(key): +# dec_key = dict() +# for k,v in key.items(): +# for i in v: +# dec_key[i] = k +# return dec_key + +def decrypt(ct, key): + pt = "" + for c in ct: + pt += key[c] + return pt + +# dec_key = gen_dec_key(key) +# print(dec_key) + +ct = open("ct.txt").read().strip() + +print(decrypt(ct,key)) \ No newline at end of file diff --git a/challs/put_me_in_coach/text.txt b/challs/put_me_in_coach/text.txt new file mode 100644 index 00000000..02356aae --- /dev/null +++ b/challs/put_me_in_coach/text.txt @@ -0,0 +1,11 @@ +Following norms and regulations is essential for electricians. These norms and regulations exist to ensure that proper safety measures are taken while working, and to guarantee safe, high quality installations. In this text, I will discuss what kind of consequences breaching norms and regulations can bring in the field of an electrician. Can a breach of norms and regulations potentially reach the newspaper headlines? + +In vocational professions, a norm is an official standard that an organization is expected to reach. These are not to be confused with social norms. In almost every field in engineering, you have norms that you need to follow, and these are often set according to market standards. Norms are guidelines to maintain official standards. Rules and regulations on the other hand, are set by committees or tribunals, and are mandatory for every electrician. In Norway, the Norwegian law is a foundation for rules and regulations. + +Engineers and electricians alike take pride in making their work look organized and neat. Making the installations functional is only half of the job. There are a lot of unwritten rules for making an organized installation. At what length to strip the cables, where to clamp cables to a wall, or placement of switches and cable boxes are all examples of this. These seemingly trivial skills are vital to an engineer's skillset and are arguably equally important as following the official rules and regulations. Breaking these norms does not pose a threat to personal or structural damage, but it can lead to the customer being dissatisfied. + +A vital aspect of an electrical installation is to choose the correct diameter of the cables. In Norway, the NEK-400 norms (Norwegian Electronic Committee) are used as guidelines for picking the right cable diameter. Varying thickness of cables can conduct different amounts of current without overheating, and it is therefore important to calculate exactly how much current your components will draw. Installing a cable with the wrong dimension can have critical consequences. To have a wider cable than necessary causes no technical problem. However, if the cable is not rated for the appropriate currents, the cable will overheat and potentially catch fire. + +To know the norms and regulations is crucial to an electrician's field. As I have discussed, not following them can have unfortunate consequences. An installation could be certified by official rules while being unorganized. Likewise, you could have an installation that looks expertly executed, but is indeed a fire hazard. Breaching official regulations have the greatest potential to have a critical outcome. Simply choosing too narrow of a cable could have the potential to for example spark a large-scale factory fire. I would argue that this is a headline-worthy event. In conclusion, rules, norms and regulations should always be followed to ensure a safe and expertly done installation. + +dctf{ctfs_would_be_boring_without_some_classical_ciphers} \ No newline at end of file