Skip to content

Instantly share code, notes, and snippets.

View ducnhse130201's full-sized avatar

PeterJson ducnhse130201

View GitHub Profile
@ducnhse130201
ducnhse130201 / aes_return.py
Created October 15, 2018 04:29
aes_return(matesCTF 2018 round 1)
import os
import binascii
s_box = [0x00] * 256
def sub_bytes(s):
for i in range(4):
for j in range(4):
s[i][j] = s_box[s[i][j]]
def shift_rows(s):
@ducnhse130201
ducnhse130201 / solve_des.py
Created October 15, 2018 02:02
solve_des FuSecAthon 2018
from telnetlib import *
from des import *
r = Telnet('localhost',34533)
print r.read_until('>>')
r.write('Data Encryption Standard' + '\n')
print r.read_until('>>')
r.write('8'+ '\n')
print r.read_until('>>')
r.write('B' + '\n')
@ducnhse130201
ducnhse130201 / solve_des.py
Created October 15, 2018 02:02
solve_des FuSecAthon 2018
from telnetlib import *
from des import *
r = Telnet('localhost',34533)
print r.read_until('>>')
r.write('Data Encryption Standard' + '\n')
print r.read_until('>>')
r.write('8'+ '\n')
print r.read_until('>>')
r.write('B' + '\n')
@ducnhse130201
ducnhse130201 / recover.py
Created October 15, 2018 02:00
recover a[0],a[1] from a[8],a[9]
from des import *
from binascii import *
WEAK_KEY = unhexlify('0101010101010101')
L = list(KeyScheduler(Str2Bits(WEAK_KEY)))
S = set(map(tuple, L))
assert len(S) == 1 # weak key create just 1 subkey
@ducnhse130201
ducnhse130201 / puredes.py
Created October 15, 2018 01:57
PURE DES
#!/usr/bin/env python3
import functools
import struct
KEY_SIZE = 8
BLOCK_SIZE = 8
# yapf: disable
# Note the 1-based indexing in all the following tables.
IP = [
Recovers some bytes of ciphertext if n is factored, but e was invalid.
(Like e=100) The vast majority of bytes are however lost, as we are taking the
GCD(e, totient(N))th root of the Ciphertext. Therefore only the most significant
bits of the ciphertext may be recovered.
Returns plaintext, since a key can't be formed from a non-integer exponent"""
# Explanation of why this works: There exists no modinv if GCD(e,Totient(N)) != 1
# but let x be e/GCD
# then there is a modular inverse of x to totient n
# c = m^(GCDx) mod n
# c^(x^-1) = m^GCD mod n, where x^-1 denotes modinv(x,totientN)
@ducnhse130201
ducnhse130201 / rsa.py
Created September 16, 2018 14:05
rsa(isitdtu_final)
from hashlib import sha512
import gmpy2
from Crypto.Util.number import *
from Crypto.PublicKey import RSA
from flag import flag
def concat(a,b):
result = long_to_bytes(a) + long_to_bytes(b)
return bytes_to_long(result)
@ducnhse130201
ducnhse130201 / X000R.py
Last active September 16, 2018 13:54
ISITDTU_Final
import struct
def decrypt(block):
num = block >> 32
x = num ^ block
return x
cipher = open('cipher.txt').read()
cipher = cipher.decode('base64')
blocks = struct.unpack('Q'*(len(cipher)/8),cipher)
out = []
@ducnhse130201
ducnhse130201 / solve.py
Created July 31, 2018 13:07
ISITDTU(aes-cnv)
from telnetlib import *
from base64 import *
r = Telnet('35.185.111.53',13337)
r.read_until('Give me content of your request you want to encrypt: ')
r.write('Give me the flab\n')
r.read_until('Your encypted: ')
enc = b64decode(r.read_until('\n').strip())
@ducnhse130201
ducnhse130201 / solve_love_cryptography.py
Created July 31, 2018 12:45
ISITDTU(love_cryptography_solve)
lst = [360575205516272353647725959973923332922859934062623515990157287L, 147121471099487603100103942210642238821212368870164629959708554L, 973776523698456974485285268207248463304785539161797442415515724L, 973776523698456974485285268207248463304785539161797442415515724L, 1989542264845745277130976293069288745712944297723265109141551240L, 2251682090999461666252822948628263912168715816760972058692440747L, 147121471099487603100103942210642238821212368870164629959708554L, 500999802327659646334011021043663318493321568487210306739944859L, 147121471099487603100103942210642238821212368870164629959708554L, 690110490875978577594520719909097376417907156757045161010173205L, 1516765543474947948979702045905703600901480327048677973465980375L, 1446553245069254302636559515370833608116249509836384578091086589L, 1989542264845745277130976293069288745712944297723265109141551240L, 1351997900795094837006304665938116579153956715701467150955972416L, 1516765543474947948979702045905703600901480327048677973465980375L, 16843500253545048724