Skip to content

Commit 137b31e

Browse files
Add more sols (picoctf, pwnable.kr, cryptohack)
1 parent 49c9eb0 commit 137b31e

14 files changed

+171
-0
lines changed

cryptohack/Encoding_Challenge.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pwn import *
2+
import json
3+
import base64
4+
import codecs
5+
r = remote('socket.cryptohack.org', 13377)
6+
def respond(data):
7+
r.sendline(json.dumps({'decoded':data}).encode('ascii'))
8+
for i in range(100):
9+
data = json.loads(r.recvline().decode('ascii'))
10+
if data['type'] == 'base64':
11+
respond(base64.b64decode(data['encoded']).decode('ascii'))
12+
elif data['type'] == 'hex':
13+
respond(bytes.fromhex(data['encoded']).decode('ascii'))
14+
elif data['type'] == 'rot13':
15+
respond(codecs.encode(data['encoded'], 'rot_13'))
16+
elif data['type'] == 'bigint':
17+
respond(bytes.fromhex(data['encoded'][2:]).decode('ascii'))
18+
elif data['type'] == 'utf-8':
19+
respond(''.join([chr(i) for i in data['encoded']]))
20+
print(r.recvall())

cryptohack/Extended_GCD.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def extended_gcd(a,b):
2+
x1, y1, x2, y2, gcd1, gcd2 = 0, 1, 1, 0, b, a
3+
while gcd1 > 0:
4+
q = gcd2 // gcd1
5+
gcd2, gcd1 = (gcd1, gcd2 - q*gcd1)
6+
x2, x1 = x1, x2 - q*x1
7+
y2, y1 = y1, y2 - q*y1
8+
return (x2, y2)
9+
print(extended_gcd(26513, 32321))
10+

cryptohack/Favourite_byte.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pwn import *
2+
ciphertext = bytes.fromhex('73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d')
3+
for key in range(0,255+1):
4+
plaintext = xor(ciphertext, key)
5+
if plaintext.startswith(b'crypto{'):
6+
print(f'possible: key={hex(key)}, plaintext="{plaintext}"')

cryptohack/GCD.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def gcd(a, b):
2+
x = min(a, b)
3+
y = max(a, b)
4+
while x != 0:
5+
y, x = x, y % x
6+
return y
7+
print(gcd(66528, 52920))

cryptohack/Legendre_Symbol.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
p = 101524035174539890485408575671085261788758965189060164484385690801466167356667036677932998889725476582421738788500738738503134356158197247473850273565349249573867251280253564698939768700489401960767007716413932851838937641880157263936985954881657889497583485535527613578457628399173971810541670838543309159139
2+
3+
ints = [25081841204695904475894082974192007718642931811040324543182130088804239047149283334700530600468528298920930150221871666297194395061462592781551275161695411167049544771049769000895119729307495913024360169904315078028798025169985966732789207320203861858234048872508633514498384390497048416012928086480326832803, 45471765180330439060504647480621449634904192839383897212809808339619841633826534856109999027962620381874878086991125854247108359699799913776917227058286090426484548349388138935504299609200377899052716663351188664096302672712078508601311725863678223874157861163196340391008634419348573975841578359355931590555, 17364140182001694956465593533200623738590196990236340894554145562517924989208719245429557645254953527658049246737589538280332010533027062477684237933221198639948938784244510469138826808187365678322547992099715229218615475923754896960363138890331502811292427146595752813297603265829581292183917027983351121325, 14388109104985808487337749876058284426747816961971581447380608277949200244660381570568531129775053684256071819837294436069133592772543582735985855506250660938574234958754211349215293281645205354069970790155237033436065434572020652955666855773232074749487007626050323967496732359278657193580493324467258802863, 4379499308310772821004090447650785095356643590411706358119239166662089428685562719233435615196994728767593223519226235062647670077854687031681041462632566890129595506430188602238753450337691441293042716909901692570971955078924699306873191983953501093343423248482960643055943413031768521782634679536276233318, 85256449776780591202928235662805033201684571648990042997557084658000067050672130152734911919581661523957075992761662315262685030115255938352540032297113615687815976039390537716707854569980516690246592112936796917504034711418465442893323439490171095447109457355598873230115172636184525449905022174536414781771, 50576597458517451578431293746926099486388286246142012476814190030935689430726042810458344828563913001012415702876199708216875020997112089693759638454900092580746638631062117961876611545851157613835724635005253792316142379239047654392970415343694657580353333217547079551304961116837545648785312490665576832987, 96868738830341112368094632337476840272563704408573054404213766500407517251810212494515862176356916912627172280446141202661640191237336568731069327906100896178776245311689857997012187599140875912026589672629935267844696976980890380730867520071059572350667913710344648377601017758188404474812654737363275994871, 4881261656846638800623549662943393234361061827128610120046315649707078244180313661063004390750821317096754282796876479695558644108492317407662131441224257537276274962372021273583478509416358764706098471849536036184924640593888902859441388472856822541452041181244337124767666161645827145408781917658423571721, 18237936726367556664171427575475596460727369368246286138804284742124256700367133250078608537129877968287885457417957868580553371999414227484737603688992620953200143688061024092623556471053006464123205133894607923801371986027458274343737860395496260538663183193877539815179246700525865152165600985105257601565]
4+
for a in ints:
5+
if pow(a,(p-1)//2,p) == 1:
6+
# x^2 = a
7+
# a^(p-1)/2 = 1
8+
# a = a^(p+1)/2
9+
# a = 3 mod 4, so this works
10+
print(pow(a, ((p+1)//2)//2, p))
11+
12+

cryptohack/Modular_Arithmetic_1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print(11 % 6, 8146798528947 % 17)

cryptohack/Network_Attacks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pwn import *
2+
import json
3+
r = remote('socket.cryptohack.org', 11112)
4+
r.sendline(json.dumps({'buy': 'flag'}))
5+
r.interactive()

cryptohack/Quadratic_Residues.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
p = 29
2+
ints = [14, 6, 11]
3+
for n in ints:
4+
for a in range(0, int((p-1)/2)+1):
5+
if (a*a - n) % p == 0:
6+
print(f'{a}^2 = {n} (mod {p})')

cryptohack/XOR_Properties.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from Crypto.Util.number import long_to_bytes
2+
key1 = 0xa6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313
3+
key2 = 0x37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e ^ key1
4+
key3 = key2 ^ 0xc1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1
5+
flag = 0x04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf ^ key2 ^ key3 ^ key1
6+
print(long_to_bytes(flag))

cryptohack/XOR_Starter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
data = b'label'
2+
flag = b'crypto{'
3+
for b in data:
4+
flag += bytes([b ^ 13])
5+
flag += b'}'
6+
print(flag)

0 commit comments

Comments
 (0)