Skip to content

Instantly share code, notes, and snippets.

@n-ari
n-ari / _redirects
Last active December 30, 2020 12:18
Gated Content with Netlify Identity
/login.html /login.html 200!
/* 200! Role=admin
/* /login.html?redirect=/:splat 302!
@n-ari
n-ari / gbc2020.cpp
Created August 29, 2020 09:30
天下一Game Battle Contest 2020 rickytheta解(C++のみ)
// main関数内以外は全てサンプルコードのままです
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <thread>
#include <chrono>
using namespace std;
@n-ari
n-ari / BeginnersMisc.md
Last active July 12, 2020 14:04
Beginner's Misc writeup

Beginner's Misc

The problem is:

exploit = input('? ')
if eval(b64encode(exploit.encode('UTF-8'))) == math.pi:
  print(open('flag.txt').read())
@n-ari
n-ari / SlowestDecryption.md
Last active July 12, 2020 09:12
Slowest Decryption writeup

Slowest Decryption

This is PPC problem.

For any i, v, x, we define cnt(i,v,x) as the number of P such that GCD(P)=v and P[i]=x. Then, the answer will be \sum_{i,v,x} cnt(i,v,x) * v * c[x] * i. Because cnt(i,v,x) = cnt(i',v,x), the answer can be written as \sum_{v,x} cnt(0,v,x) * v * c[x] * N*(N-1)/2.

To count cnt(0,v,x), we fix x. Then we check v from N-1 to 1 such that x % v = 0.

TSG CTF 2020 writeups (日本語簡略版)

Beginner's Crypto

flag * 2^{10000} mod 10^{175} == val という形で、val が分かっている。

剰余の定義から flag * 2^{10000} - k * 10^{175} == val がわかる。

@n-ari
n-ari / ModulusAmittendus.md
Last active July 12, 2020 08:34
Modulus Amittendus writeup

Modulus Amittendus

You can see that n, e, cf are exported in pubkey.json.

These values are a bit strange:

  def initialize
    # ...
    @cf = modinv(@q, @p)   # (1)
@n-ari
n-ari / Rubikrypto.md
Created July 12, 2020 07:52
Rubikrypto writeup

Rubikrypto

This is only ElGamal cryptosystem on Rubik Cube.

The order of Rubik Cube Group is 43_252_003_274_489_856_000n and this is small enough to use Pohlig-Hellman.

So the algorithm is simple:

  1. get g, h, c1, c2.
  2. calculate y = log_g(c1) using Pohlig-Hellman.
@n-ari
n-ari / SweetLikeApplePie.md
Last active July 12, 2020 08:34
Sweet like Apple Pie writeup

Sweet Like Apple Pie

The output is output = sin(flag % pi()).

We can get flag % pi() = arcsin(output) using a binary search. Note that there are 2 possible answers.

So, we want to calculate k such that flag - k * pi() = arcsin(output).

Due to the Decimal, these values are calculated in 300-digits precision. That means,

@n-ari
n-ari / BeginnersCrypto.md
Last active July 12, 2020 08:34
Beginner's Crypto writeup

Beginner's Crypto

Given val such that flag * 2^{10000} mod 10^{175} == val.

From definition of modulus, we get flag * 2^{10000} - k * 10^{175} == val.

Divide by 2^{175}, flag * 2^{10000-175} - k * 5^{175} == val / 2^{175}

@n-ari
n-ari / sudoku.cpp
Created February 26, 2020 09:13
sudoku ver.1
#include <stdio.h>
#include <algorithm>
namespace sudoku {
const char UNKNOWN = '_';
char board[90];
void input(){
for(int row=0; row<9; row++){
scanf("%s",board + 9*row);
}