Skip to content

Instantly share code, notes, and snippets.

@wanderer
Created October 21, 2017 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wanderer/b6a25bdddedaa510edbd243b9aed28c6 to your computer and use it in GitHub Desktop.
Save wanderer/b6a25bdddedaa510edbd243b9aed28c6 to your computer and use it in GitHub Desktop.
(module
(type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(import "env" "printf" (func $printf (param i32 i32) (result i32)))
(table 0 anyfunc)
(memory $0 1)
(data (i32.const 32) "fail\00")
(data (i32.const 48) "\88j?$\d3\08\a3\85\e6!(Ew\13\d08")
(data (i32.const 64) "\ce\fa\ed\fe\ef\be\ad\de\be\ba\ed\fe\ef\be\fe\ca")
(export "memory" (memory $0))
(export "shift_left" (func $shift_left))
(export "shift_right" (func $shift_right))
(export "rotate_left" (func $rotate_left))
(export "rotate_right" (func $rotate_right))
(export "encrypt" (func $encrypt))
(export "decrypt" (func $decrypt))
(export "expand" (func $expand))
(export "test" (func $test))
(export "main" (func $main))
(func $shift_left (param $0 i32) (param $1 i32) (result i32)
(i32.shl
(get_local $0)
(get_local $1)
)
)
(func $shift_right (param $0 i32) (param $1 i32) (result i32)
(i32.shr_u
(get_local $0)
(get_local $1)
)
)
(func $rotate_left (param $0 i32) (param $1 i32) (result i32)
(i32.rotl
(get_local $0)
(get_local $1)
)
)
(func $rotate_right (param $0 i32) (param $1 i32) (result i32)
(i32.rotr
(get_local $0)
(get_local $1)
)
)
(func $encrypt (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(set_local $8
(i32.const 0)
)
(set_local $7
(get_local $0)
)
(loop $label$0
(i32.store
(get_local $1)
(tee_local $3
(i32.add
(tee_local $3
(i32.load
(get_local $7)
)
)
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(i32.rotl
(i32.xor
(tee_local $3
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $6
(i32.add
(i32.rotl
(i32.xor
(tee_local $4
(i32.add
(get_local $3)
(i32.rotl
(i32.xor
(tee_local $5
(i32.add
(i32.load
(i32.add
(get_local $0)
(i32.const 4)
)
)
(i32.load
(tee_local $2
(i32.add
(get_local $1)
(i32.const 4)
)
)
)
)
)
(i32.add
(i32.load
(get_local $0)
)
(i32.load
(get_local $1)
)
)
)
(get_local $5)
)
)
)
(get_local $5)
)
(get_local $4)
)
(tee_local $5
(i32.load
(i32.add
(get_local $7)
(i32.const 4)
)
)
)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $4)
)
(get_local $5)
)
)
(get_local $4)
)
(get_local $6)
)
)
)
(get_local $6)
)
(get_local $3)
)
(get_local $5)
)
)
(get_local $3)
)
(get_local $4)
)
)
)
)
(i32.store
(get_local $2)
(i32.add
(get_local $5)
(i32.rotl
(i32.xor
(get_local $3)
(get_local $4)
)
(get_local $3)
)
)
)
(set_local $7
(i32.add
(get_local $7)
(i32.const 16)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 8)
)
)
(br_if $label$0
(i32.lt_u
(tee_local $8
(i32.add
(get_local $8)
(i32.const 2)
)
)
(i32.const 4)
)
)
)
)
(func $decrypt (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(set_local $8
(i32.const 0)
)
(set_local $7
(get_local $0)
)
(loop $label$0
(set_local $6
(i32.load
(get_local $0)
)
)
(i32.store
(tee_local $2
(i32.add
(get_local $1)
(i32.const 4)
)
)
(i32.sub
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(tee_local $4
(i32.xor
(i32.rotr
(i32.sub
(i32.load
(get_local $2)
)
(tee_local $2
(i32.load
(i32.add
(get_local $7)
(i32.const 4)
)
)
)
)
(tee_local $3
(i32.load
(get_local $1)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(tee_local $5
(i32.load
(get_local $7)
)
)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $3
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $3)
)
)
(get_local $2)
)
(tee_local $2
(i32.xor
(i32.rotr
(i32.sub
(get_local $3)
(get_local $5)
)
(get_local $4)
)
(get_local $4)
)
)
)
(get_local $2)
)
)
(i32.load
(i32.add
(get_local $0)
(i32.const 4)
)
)
)
)
(i32.store
(get_local $1)
(i32.sub
(i32.xor
(i32.rotr
(i32.sub
(get_local $2)
(get_local $5)
)
(get_local $3)
)
(get_local $3)
)
(get_local $6)
)
)
(set_local $7
(i32.add
(get_local $7)
(i32.const 16)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 8)
)
)
(br_if $label$0
(i32.lt_u
(tee_local $8
(i32.add
(get_local $8)
(i32.const 2)
)
)
(i32.const 4)
)
)
)
)
(func $expand (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(i64.store align=4
(get_local $1)
(i64.const 6203931810907378019)
)
(i64.store offset=8 align=4
(get_local $1)
(i64.const -7888126701122599723)
)
(i64.store offset=16 align=4
(get_local $1)
(i64.const -3533441143737993145)
)
(i64.store offset=24 align=4
(get_local $1)
(i64.const 821244417941580729)
)
(i64.store offset=32 align=4
(get_local $1)
(i64.const 5175929979621154603)
)
(i32.store offset=40
(get_local $1)
(i32.const -435416419)
)
(i32.store offset=44
(get_local $1)
(i32.const -2075947946)
)
(i32.store offset=48
(get_local $1)
(i32.const 578487823)
)
(i32.store offset=52
(get_local $1)
(i32.const -1062043704)
)
(i32.store offset=56
(get_local $1)
(i32.const 1592392065)
)
(i32.store offset=60
(get_local $1)
(i32.const -48139462)
)
(i32.store offset=64
(get_local $1)
(i32.const -1688670989)
)
(i32.store offset=68
(get_local $1)
(i32.const 965764780)
)
(i32.store offset=72
(get_local $1)
(i32.const -674766747)
)
(i32.store offset=76
(get_local $1)
(i32.const 1979669022)
)
(i32.store offset=80
(get_local $1)
(i32.const 339137495)
)
(i32.store offset=84
(get_local $1)
(i32.const -1301394032)
)
(i32.store offset=88
(get_local $1)
(i32.const 1353041737)
)
(i32.store offset=92
(get_local $1)
(i32.const -287489790)
)
(i32.store offset=96
(get_local $1)
(i32.const -1928021317)
)
(i32.store offset=100
(get_local $1)
(i32.const 726414452)
)
(set_local $4
(i32.const 0)
)
(set_local $3
(i32.const 78)
)
(set_local $2
(i32.const -1209970333)
)
(set_local $5
(i32.const 0)
)
(set_local $6
(i32.const 0)
)
(set_local $7
(i32.const 0)
)
(block $label$0
(loop $label$1
(i32.store
(i32.add
(get_local $1)
(i32.shl
(get_local $5)
(i32.const 2)
)
)
(tee_local $7
(i32.rotl
(i32.add
(i32.add
(get_local $6)
(get_local $7)
)
(get_local $2)
)
(i32.const 3)
)
)
)
(i32.store
(tee_local $2
(i32.add
(get_local $0)
(i32.shl
(get_local $4)
(i32.const 2)
)
)
)
(tee_local $6
(i32.rotl
(i32.add
(i32.add
(i32.load
(get_local $2)
)
(get_local $6)
)
(get_local $7)
)
(i32.add
(get_local $7)
(get_local $6)
)
)
)
)
(set_local $5
(i32.rem_u
(i32.add
(get_local $5)
(i32.const 1)
)
(i32.const 26)
)
)
(br_if $label$0
(i32.lt_s
(get_local $3)
(i32.const 2)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const -1)
)
)
(set_local $4
(i32.and
(i32.add
(get_local $4)
(i32.const 1)
)
(i32.const 3)
)
)
(set_local $2
(i32.load
(i32.add
(get_local $1)
(i32.shl
(get_local $5)
(i32.const 2)
)
)
)
)
(br $label$1)
)
)
)
(func $test (param $0 i32) (param $1 i32) (result i32)
(i64.store offset=16
(i32.const 0)
(i64.load align=4
(get_local $1)
)
)
(i64.store offset=24
(i32.const 0)
(i64.load align=4
(i32.add
(get_local $1)
(i32.const 8)
)
)
)
(call $encrypt
(get_local $0)
(get_local $1)
)
(call $decrypt
(get_local $0)
(get_local $1)
)
(block $label$0
(block $label$1
(br_if $label$1
(i32.ne
(i32.load
(get_local $1)
)
(i32.load offset=16
(i32.const 0)
)
)
)
(br_if $label$1
(i32.ne
(i32.load offset=4
(get_local $1)
)
(i32.load offset=20
(i32.const 0)
)
)
)
(br_if $label$1
(i32.ne
(i32.load offset=8
(get_local $1)
)
(i32.load offset=24
(i32.const 0)
)
)
)
(set_local $0
(i32.const 1)
)
(br_if $label$0
(i32.eq
(i32.load offset=12
(get_local $1)
)
(i32.load offset=28
(i32.const 0)
)
)
)
)
(drop
(call $printf
(i32.const 32)
(i32.const 0)
)
)
(set_local $0
(i32.const 0)
)
)
(get_local $0)
)
(func $main (result i32)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(set_local $2
(i32.const 0)
)
(i64.store offset=80
(i32.const 0)
(i64.const 6203931810907378019)
)
(i64.store offset=88
(i32.const 0)
(i64.const -7888126701122599723)
)
(i64.store offset=96
(i32.const 0)
(i64.const -3533441143737993145)
)
(i64.store offset=104
(i32.const 0)
(i64.const 821244417941580729)
)
(i64.store offset=112
(i32.const 0)
(i64.const 5175929979621154603)
)
(i32.store offset=120
(i32.const 0)
(i32.const -435416419)
)
(i32.store offset=124
(i32.const 0)
(i32.const -2075947946)
)
(i32.store offset=128
(i32.const 0)
(i32.const 578487823)
)
(i32.store offset=132
(i32.const 0)
(i32.const -1062043704)
)
(i32.store offset=136
(i32.const 0)
(i32.const 1592392065)
)
(i32.store offset=140
(i32.const 0)
(i32.const -48139462)
)
(i32.store offset=144
(i32.const 0)
(i32.const -1688670989)
)
(i32.store offset=148
(i32.const 0)
(i32.const 965764780)
)
(i32.store offset=152
(i32.const 0)
(i32.const -674766747)
)
(i32.store offset=156
(i32.const 0)
(i32.const 1979669022)
)
(i32.store offset=160
(i32.const 0)
(i32.const 339137495)
)
(i32.store offset=164
(i32.const 0)
(i32.const -1301394032)
)
(i32.store offset=168
(i32.const 0)
(i32.const 1353041737)
)
(i32.store offset=172
(i32.const 0)
(i32.const -287489790)
)
(i32.store offset=176
(i32.const 0)
(i32.const -1928021317)
)
(i32.store offset=180
(i32.const 0)
(i32.const 726414452)
)
(set_local $1
(i32.const 78)
)
(set_local $0
(i32.const -1209970333)
)
(set_local $3
(i32.const 0)
)
(set_local $4
(i32.const 0)
)
(set_local $5
(i32.const 0)
)
(block $label$0
(loop $label$1
(i32.store
(i32.add
(i32.shl
(get_local $3)
(i32.const 2)
)
(i32.const 80)
)
(tee_local $5
(i32.rotl
(i32.add
(i32.add
(get_local $4)
(get_local $0)
)
(get_local $5)
)
(i32.const 3)
)
)
)
(i32.store
(tee_local $0
(i32.add
(i32.shl
(get_local $2)
(i32.const 2)
)
(i32.const 48)
)
)
(tee_local $4
(i32.rotl
(i32.add
(i32.add
(i32.load
(get_local $0)
)
(get_local $4)
)
(get_local $5)
)
(i32.add
(get_local $5)
(get_local $4)
)
)
)
)
(set_local $3
(i32.rem_u
(i32.add
(get_local $3)
(i32.const 1)
)
(i32.const 26)
)
)
(br_if $label$0
(i32.le_s
(get_local $1)
(i32.const 1)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const -1)
)
)
(set_local $2
(i32.and
(i32.add
(get_local $2)
(i32.const 1)
)
(i32.const 3)
)
)
(set_local $0
(i32.load
(i32.add
(i32.shl
(get_local $3)
(i32.const 2)
)
(i32.const 80)
)
)
)
(br $label$1)
)
)
(set_local $4
(i32.const 43690)
)
(loop $label$2
(i64.store offset=24
(i32.const 0)
(i64.load offset=72
(i32.const 0)
)
)
(i64.store offset=16
(i32.const 0)
(i64.load offset=64
(i32.const 0)
)
)
(call $encrypt
(i32.const 80)
(i32.const 64)
)
(call $decrypt
(i32.const 80)
(i32.const 64)
)
(block $label$3
(block $label$4
(br_if $label$4
(i32.ne
(i32.load offset=64
(i32.const 0)
)
(i32.load offset=16
(i32.const 0)
)
)
)
(br_if $label$4
(i32.ne
(i32.load offset=68
(i32.const 0)
)
(i32.load offset=20
(i32.const 0)
)
)
)
(br_if $label$4
(i32.ne
(i32.load offset=72
(i32.const 0)
)
(i32.load offset=24
(i32.const 0)
)
)
)
(br_if $label$3
(i32.eq
(i32.load offset=76
(i32.const 0)
)
(i32.load offset=28
(i32.const 0)
)
)
)
)
(drop
(call $printf
(i32.const 32)
(i32.const 0)
)
)
)
(br_if $label$2
(tee_local $4
(i32.add
(get_local $4)
(i32.const -1)
)
)
)
)
(i32.load offset=64
(i32.const 0)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment