commit 413593ad7361052b30ebe22d381f76fffc06a47d Author: Anish Lakhwara Date: Fri Apr 24 16:04:28 2020 +1000 initial diff --git a/encoding/13377_e3dd25795e7a6053f2df0aa399b3cf34.py b/encoding/13377_e3dd25795e7a6053f2df0aa399b3cf34.py new file mode 100644 index 0000000..a48af18 --- /dev/null +++ b/encoding/13377_e3dd25795e7a6053f2df0aa399b3cf34.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +from Crypto.Util.number import bytes_to_long, long_to_bytes +from utils import listener +import base64 +import codecs +import random + +FLAG = "crypto{????????????????????}" +ENCODINGS = [ + "base64", + "hex", + "rot13", + "bigint", + "utf-8", +] +with open('/usr/share/dict/words') as f: + WORDS = [line.strip().replace("'", "") for line in f.readlines()] + + +class Challenge(): + def __init__(self): + self.challenge_words = "" + self.stage = 0 + + def create_level(self): + self.stage += 1 + self.challenge_words = "_".join(random.choices(WORDS, k=3)) + encoding = random.choice(ENCODINGS) + + if encoding == "base64": + encoded = base64.b64encode(self.challenge_words.encode()).decode() # wow so encode + elif encoding == "hex": + encoded = self.challenge_words.encode().hex() + elif encoding == "rot13": + encoded = codecs.encode(self.challenge_words, 'rot_13') + elif encoding == "bigint": + encoded = hex(bytes_to_long(self.challenge_words.encode())) + elif encoding == "utf-8": + encoded = [ord(b) for b in self.challenge_words] + + return {"type": encoding, "encoded": encoded} + + # + # This challenge function is called on your input, which must be JSON + # encoded + # + def challenge(self, your_input): + if self.stage == 0: + return self.create_level() + elif self.stage == 100: + self.exit = True + return {"flag": FLAG} + + if self.challenge_words == your_input["decoded"]: + return self.create_level() + + return {"error": "Decoding fail"} + + +listener.start_server(port=13377) + diff --git a/encoding/automating.py b/encoding/automating.py new file mode 100644 index 0000000..01dd593 --- /dev/null +++ b/encoding/automating.py @@ -0,0 +1,50 @@ +import socket +import json +from Crypto.Util.number import bytes_to_long, long_to_bytes +#from utils import listener +import base64 +import codecs +import random + +def netcat(hostname, port, content): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((hostname, port)) + s.sendall(content) + s.shutdown(socket.SHUT_WR) + while 1: + data = s.recv(1024) + if data == "": + break + #print "Received:", repr(data) + #print "Connection closed." + s.close() + +host = "socket.cryptohack.org" +port = 13377 + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect((host, port)) +while 1: + data = json.loads(s.recv(1024)) + if 'flag' in data: + print(data['flag']) + encoding = data['type'] + print(encoding) + + if encoding == "base64": + encoded = bytes.decode(base64.b64decode(data['encoded'])) + elif encoding == "hex": + encoded = bytearray.fromhex(data['encoded']).decode() + elif encoding == "rot13": + encoded = codecs.decode(data['encoded'], 'rot_13') + pass + elif encoding == "bigint": + #print(bytearray.fromhex(data['encoded']).decode()) + encoded = bytearray.fromhex(data['encoded'][2:]).decode() + print(encoded) + elif encoding == "utf-8": + encoded = bytes.decode(bytes(''.join([chr(b) for b in data['encoded']]), "UTF-8")) + + jsonEncode = json.JSONEncoder().encode({"decoded": str(encoded)}) + print(jsonEncode) + s.sendall(bytes(jsonEncode, "UTF-8")) diff --git a/maths/euclidAlgo.py b/maths/euclidAlgo.py new file mode 100644 index 0000000..75c3539 --- /dev/null +++ b/maths/euclidAlgo.py @@ -0,0 +1,14 @@ +def Euclid(a, b): + if a < b: + tmp = a + a = b + b = tmp + r = a%b + if r == 0: + return b + return Euclid(b, r) + +def extendedEuclid(a, b): + pass + +print(Euclid(66528, 52920)) diff --git a/xor/1.py b/xor/1.py new file mode 100644 index 0000000..6ee2a59 --- /dev/null +++ b/xor/1.py @@ -0,0 +1,8 @@ +test = "label" +i = 13 +final = "" + +for e in test: + final = final + chr(i ^ ord(e)) + +print(final) diff --git a/xor/2.py b/xor/2.py new file mode 100644 index 0000000..54ae9ad --- /dev/null +++ b/xor/2.py @@ -0,0 +1,9 @@ +i = "73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d" +to_bytes = bytearray.fromhex(i) + +for i in range(256): + final = "" + for e in to_bytes: + final = final + chr(i ^ e) + if ord(final[6]) + 2 == ord(final[-1]): + print(final) diff --git a/xor/3.py b/xor/3.py new file mode 100644 index 0000000..595b47a --- /dev/null +++ b/xor/3.py @@ -0,0 +1,28 @@ +q = "0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104" +to_bytes = bytearray.fromhex(q) + +final = "" +i = 1 +#while i <= 10000000: +# final = "" +# for e in to_bytes: +# final = final + chr(i ^ e) +# if "crypto" == final[0:5]: +# print(final) +# print(i) +# i = i + 1 +# #print(final[7]) +#print(i) + +#key = "" +#for e, i in zip(to_bytes, "crypto{"): +# key = key + chr(ord(i) ^ e) + +#print(key) + +key = "myXORkeymyXORkeymyXORkeymyXORkeymyXORkeymyXORkey" +final = "" +for e, i in zip(to_bytes, key): + final = final + chr(e ^ ord(i)) + +print(final)