Skip to content

Instantly share code, notes, and snippets.

@inaz2
inaz2 / 01-poland.py
Created November 17, 2012 02:49
2012-11-16 g6k.rb #2
#!/usr/bin/env python
import sys
class PolandParser:
"""
EXPR := '(' EXPR ')' | OP TERM TERM
TERM := EXPR | NUM
OP := '+' | '-' | '*' | '/'
NUM := (any integer)
@inaz2
inaz2 / three_by_three.py
Last active October 13, 2015 04:28
三目並べが常に引き分けとなることを、minimax法総当たりによって検証
$ python three_by_three.py
0
@inaz2
inaz2 / rsa.py
Last active March 15, 2020 14:57
RSAアルゴリズムの確認
$ python rsa.py
prime p: 101
prime q: 109
public key ... n=11009, e=65537
private key ... d=3473
message integer m (< 11009): 1000
encrypted message ... c=9787
decrypted message ... m2=1000
@inaz2
inaz2 / hit_and_blow.py
Last active December 10, 2015 02:38
Hit&Blow
inspired from http://blogs.wankuma.com/episteme/archive/2012/12/23/310246.aspx
$ python hit_and_blow.py
各桁が1~9である3桁の数を入力してほしい。各桁で数が重複するのは避けてくれ
987
君が選んだのは 987 だね。では僕がその数を推理しよう。
1回目: 正解となる数の候補は 504 あるが... 427 ではないかな?
1Hit / 0Blow
2回目: 正解となる数の候補は 90 あるが... 496 ではないかな?
0Hit / 1Blow
@inaz2
inaz2 / yes.asm
Last active December 26, 2015 07:09
x86アセンブリでyesコマンドの実装
$ uname -a
Linux vm-ubuntu32 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:42:40 UTC 2014 i686 i686 i386 GNU/Linux
$ gcc -nostdlib -o yes yes.s
$ ./yes
y
y
y^C
$ ls -l yes
-rwxr-xr-x 1 user user 629 Mar 17 22:22 yes*
@inaz2
inaz2 / ads-compress.txt
Last active December 26, 2015 14:29
ADS圧縮形式についてのメモ(NTFSのAlternate Data Streamsにデータを隠す)
> dir
2013/10/26 14:46 <DIR> .
2013/10/26 14:46 <DIR> ..
2013/10/26 14:37 1,048,576 foobar.txt
1 個のファイル 1,048,576 バイト
2 個のディレクトリ 603,434,876,928 バイトの空き領域
> type NUL > compressed.ads
> type foobar.txt > compressed.ads:foobar.txt
@inaz2
inaz2 / fb_friends_in_group.html
Last active December 27, 2015 05:29
Facebookで特定のグループにいるfriendのリストを取得
<script>
// https://www.facebook.com/groups/$gid/
var gid = '$gid';
FB.api('/'+gid+'/members', function(v){
Log.info('/'+gid+'/members', v);
var members = v.data.map(function(v){return v.id});
FB.api('/me/friends', function(v){
Log.info('/me/friends', v);
var friends= v.data.map(function(v){return v.id});
var friends_in_group = members.filter(function(v){return friends.indexOf(v) !== -1});
@inaz2
inaz2 / write_stdin.py
Last active December 27, 2015 17:59
子プロセスの標準入力に書き込む
$ python write_stdin.py
6
20
13
@inaz2
inaz2 / hello.cpp
Last active December 28, 2015 18:39
C++11: use "range-based for" with argv
$ g++ --version
g++ (GCC) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --std=c++11 -o hello hello.cpp
$ ./hello reni kanako shiori ayaka momoka
@inaz2
inaz2 / list_gadgets.py
Created March 23, 2014 08:37
list ROP gadgets in a library
$ python list_gadgets.py libc.so.6 | head
78a: dec edi
877: or al,BYTE PTR [ecx]
8ee: dec esp
cf2: add BYTE PTR [eax],al
106e: add BYTE PTR [eax],al
122e: add BYTE PTR [eax],al
13ea: add BYTE PTR [eax],al
1736: add BYTE PTR [eax],al
1735: pop es; add BYTE PTR [eax],al