1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
| m = "Koreハ平文デス♪ Koreハ平文デス♪ ひゃっはー"
mes "平文 = 『"+m+"』\n"
mes "フェイステル構造の場合"
keys = $0ABCDEF0, $FF00FF00, $512, $92843
c = encrypt_feistel_a(m,keys)
mes "暗号化文章(Feistel) = 『"+c+"』"
cc = decrypt_feistel_a(c,keys)
mes "復号化文章(Feistel) = 『"+cc+"』"
mes "※本来なら鍵は1本だけで、上手く繁殖させて4本にするらしい"
mes "round_func_a関数を色々いじくる事で耐久度が上下する\n"
#module
#defcfunc encrypt_feistel_a str m, array keys \
, local mm, local r1, local l1, local c, local index \
, local key, local l2, local r2
mm = m
sdim c, strlen(mm)+8
r1 = 0
l1 = 0
repeat (strlen(mm)+7)/8
index = cnt*8
lpoke l1, 0, lpeek(mm,index)
lpoke r1, 0, lpeek(mm,index+4)
repeat length(keys)
l2 = r1
r2 = (round_func_a(keys(cnt),r1) xor l1)
l1 = l2
r1 = r2
loop
memcpy c, l1, 4, index
memcpy c, r1, 4, index+4
loop
return c
#defcfunc round_func_a int i1, int i2
return i1+499*i2+398
#defcfunc decrypt_feistel_a str c, array keys \
, local cc, local r1, local l1, local m, local index \
, local key, local l2, local r2
cc = c
sdim m, strlen(cc)+8
r1 = 0
l1 = 0
repeat (strlen(cc)+7)/8
index = cnt*8
lpoke l1, 0, lpeek(cc,index)
lpoke r1, 0, lpeek(cc,index+4)
repeat length(keys)
key = length(keys)-cnt-1
r2 = l1
l2 = (round_func_a(keys(key),l1) xor r1)
l1 = l2
r1 = r2
loop
memcpy m, l1, 4, index
memcpy m, r1, 4, index+4
loop
return m
#global
|