Skip to content

Instantly share code, notes, and snippets.

View ShikChen's full-sized avatar
💤
Sleeping from home

ShikChen

💤
Sleeping from home
View GitHub Profile
@niklasb
niklasb / gracias.py
Last active July 15, 2019 02:32
Crypto solutions ASIS CTF finals
from sage.all import continued_fraction, Integer, inverse_mod
pubkey = (1696852658826990842058316561963467335977986730245296081842693913454799128341723605666024757923000936875008280288574503060506225324560725525210728761064310034604441130912702077320696660565727540525259413564999213382434231194132697630244074950529107794905761549606578049632101483460345878198682237227139704889943489709170676301481918176902970896183163611197618458670928730764124354693594769219086662173889094843054787693685403229558143793832013288487194871165461567L, 814161885590044357190593282132583612817366020133424034468187008267919006610450334193936389251944312061685926620628676079561886595567219325737685515818965422518820810326234612624290774570873983198113409686391355443155606621049101005048872030700143084978689888823664771959905075795440800042648923901406744546140059930315752131296763893979780940230041254506456283030727953969468933552050776243515721233426119581636614777596169466339421956338478341355508343072697451L, 17101222758731850777
@elliptic-shiho
elliptic-shiho / solve.py
Last active September 10, 2017 18:02
ASIS CTF Finals 2017: Interested Message
from scryptos import *
import hashlib
import gmpy
'''
References:
[1] Hitachi, Ltd. 2001. Specification of HIME(R) CryptoSystem - http://www.hitachi.com/rd/yrl/crypto/hime/HIME_R_specE.pdf
'''
SECRET = 'ASISCTF-17'
C0 = [ hashlib.sha1(SECRET[i:] + SECRET[:i]).digest()[:16] for i in xrange(10) ]
@elliptic-shiho
elliptic-shiho / boneh_durfee.sage
Last active September 10, 2017 19:02
ASIS CTF Finals 2017: Gracias
from sage.all import *
# Original: https://github.com/mimoo/RSA-and-LLL-attacks/blob/master/boneh_durfee.sage
dimension_min = 7
def remove_unhelpful(BB, monomials, bound, current):
if current == -1 or BB.dimensions()[0] <= dimension_min:
return BB
for ii in range(current, -1, -1):
if BB[ii, ii] >= bound:
function get_flag() {
s = "ASIS{";
var r0 = 65;
var r7 = 0;
for (var r8 = 0; r8 <= 20; r8++) {
var r9 = 47;
r9 = r9 < r0;
if (!(r9 < 58)) {
r9 = 64;
r9 = r9 < r0;
import socket, struct, os, binascii, base64, subprocess
import telnetlib
import base58
def readline(sc, show = True):
res = ""
while len(res) == 0 or res[-1] != "\n":
data = sc.recv(1)
if len(data) == 0:
@hellman
hellman / 0_solve.py
Last active September 4, 2017 08:29
TWCTF 2017 - BabyPinhole
#-*- coding:utf-8 -*-
"""
In this challenge we have a Paillier cryptosystem.
We are given a decryption oracle, which leaks only one bit in the middle of the plaintext.
Due to homomorphic properties of the Paillier cryptosystem, we can recover the full decryption using such an oracle.
1. First, we recover the lower half of the message bit-by-bit.
This can be done by manipulating and observing the carry bit going through the pinhole,
@hellman
hellman / 0server.rb
Last active September 4, 2017 08:33
TWCTF 2017 - Liar's Trap
#!/usr/bin/env ruby
require 'securerandom'
## Parameters
P = 115792089237316195423570985008687907853269984665640564039457584007913129639747
N = 100
K = 25
L = 38 # The number of liars
def apply_polynomial(coeffs, x)
r = 0
@hellman
hellman / code.cpp
Last active February 25, 2019 16:59
TWCTF 2017 - Palindrome Pairs - Challenge Phase
#include <iostream>
#include <stdlib.h>
using namespace std;
#define REP(i,x) for(int i = 0; i < (int)x; i++)
#define M 8
int N;
string s[1000];
long q[M], p[M], hs[M][1000], hr[M][1000];
@rkmylo
rkmylo / rfile__init__.py
Created May 22, 2017 00:46
RCTF 2016 - rFile __init__.py
# uncompyle6 version 2.9.11
# Python bytecode 3.5 (3350)
# Decompiled from: Python 2.7.6 (default, Oct 26 2016, 20:30:19)
# [GCC 4.8.4]
# Embedded file name: /app/rFileStorage/__init__.py
# Compiled at: 2017-04-09 12:19:02
# Size of source mod 2**32: 1891 bytes
from flask import Flask, request, send_file, make_response
from hashlib import md5
from time import time
@rkmylo
rkmylo / rcdn_solution.py
Created May 22, 2017 00:43
RCTF 2017 - rCDN Solution
# coding: utf-8
"""
Unfortunately solved 20 minutes after the end of the CTF :(
"""
import re
import sys
import string
import requests