サブルーチン
#module str2ints_ints2str
// 文字列を数値群に変換する
#deffunc str2ints var r,var p
// 引数の説明
// r:返り値用文字列
// p:変換したい文字列
r=""
l=strlen(p)
// 文字列の長さだけ繰り返す
repeat l
// 一文字抜き出す
of_peek=peek(p,cnt)
// 抜き出した文字列を文字列に変換して返り値文字列に加算
r+=some_at_int2char_02(of_peek)
loop
return
// 数値群を文字列に変換する
#deffunc ints2str var r,var p
// 引数の説明
// r:返り値用文字列
// p:変換したい数値群
r=""
l=strlen(p)
l/=2
// 文字列の長さ/2繰り返す
repeat l
n=cnt*2
// 2文字抜き出す
u=strmid(p,n,2)
// 抜き出した文字を変換して返り値文字列に加算
r+=some_at_char2int_02(u)
loop
return
#global
#module int2char_02
// 引数(0〜15)の16進表記を返す
// 引数の値が0〜15でないとerror
#defcfunc one_at_int2char_02 int cc
if (cc<=-1)|(cc>=16){
logmes "one_at_int2char内のerror"
logmes "引数は0〜15の値にして下さい"
logmes "引数の値:"+str(cc)
return -1
}
switch cc
case 0 :return "0"
case 1 :return "1"
case 2 :return "2"
case 3 :return "3"
case 4 :return "4"
case 5 :return "5"
case 6 :return "6"
case 7 :return "7"
case 8 :return "8"
case 9 :return "9"
case 10 :return "a"
case 11 :return "b"
case 12 :return "c"
case 13 :return "d"
case 14 :return "e"
case 15 :return "f"
swend
return -1
// 引数cを文字列に変換して返す
// 引数cの値が0〜255でないとerror
// 2桁の数字を返す
#defcfunc some_at_int2char_02 int c
if (c<=-1)|(c>=256){
logmes "some_at_int2char内のerror"
logmes "第一引数は0〜255の値にして下さい"
logmes "第一引数の値:"+str(c)
return "error"
}
t=0
tt=0
t=c/16
tt=c\16
return ""+str(one_at_int2char_02(t))+str(one_at_int2char_02(tt))
#global
#module char2int_02
// 16進表記の引数(0〜15)を数値に変換して返す
// 引数の長さが1でないとerror
// 引数の値が0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,fの
// どれかでないとerror
#defcfunc one_at_char2int_02 str cc
f=0
ff=0
fff=0
l=strlen(cc)
if l!=1{
logmes "one_at_char2int内のerror"
logmes "文字列型引数ccの長さは1にして下さい"
logmes "引数の長さ:"+l
return -1
}
if (cc=="0")|(cc=="1")|(cc=="2")|(cc=="3")|(cc=="4"){f=1}
if (cc=="5")|(cc=="6")|(cc=="7")|(cc=="8")|(cc=="9"){ff=1}
if (cc=="a")|(cc=="b")|(cc=="c")|(cc=="d")|(cc=="e")|(cc=="f"){fff=1}
if (f==0)&(ff=0)&(fff=0){
logmes "one_at_char2int内のerror"
logmes "引数は"
logmes "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f"
logmes "のどれかにして下さい"
logmes "引数の値:"+cc
return -1
}
switch cc
case "0":return 0
case "1":return 1
case "2":return 2
case "3":return 3
case "4":return 4
case "5":return 5
case "6":return 6
case "7":return 7
case "8":return 8
case "9":return 9
case "a":return 10
case "b":return 11
case "c":return 12
case "d":return 13
case "e":return 14
case "f":return 15
swend
return -1
// 引数cを文字列に変換して返す
// 引数cの値が0〜255でないとerror
#defcfunc some_at_char2int_02 str c
l=strlen(c)
if (l!=2){
logmes "some_at_char2int内のerror"
logmes "文字列型引数cの長さは2にして下さい"
logmes "引数の長さ:"+l
logmes "引数の値:"+c
return "error"
}
ccc=c
n=strmid(ccc,0,1)
m=strmid(ccc,1,1)
mm= (one_at_char2int_02(n)*16)+(one_at_char2int_02(m))
mmm=""
poke mmm,0,mm
return mmm
#global
#module m_int2str
// intを文字列に変換する
// 32bit表現をそのまま8文字に変換
// p:変換する実数
#defcfunc int2str var p
dim ar,10
i=0
ii=0
repeat 4
// 引数から1byte取得
v1=peek(p,i)
// 上位4bit取得
ar.ii=v1/16
// 下位4bit取得
ar(ii+1)=v1\16
i++
ii+=2
loop
s=""
repeat 8
// 一つずつ文字列に変換して加算
s+=one_at_int2char_on4dbl(ar.cnt)
loop
return s
// 文字列をintに変換する
// 8文字をそのまま32bit表現に変換
// p:変換する文字列
#defcfunc int2int var p
dim ar,10
repeat 8
// 引数から1文字取得して配列に代入
ar.cnt=one_at_char2int_on4dbl(strmid(p,cnt,1))
loop
return write2double(ar)
// 配列化されている数値をdouble変数に書きこんで返す
// p_ar:0〜15までの数値が入っている配列
#defcfunc write2double array p_ar
f=0
i=0
ii=0
repeat 4
// 配列の中身を5〜8bitに代入
m=p_ar.ii*16
// 配列の中身を1〜4bitに代入
m+=p_ar(ii+1)
// 8bitの値をdouble変数に書き込み
poke f,i,m
i++
ii+=2
loop
return f
// 引数(0〜15)の16進表記を返す
// 引数の値が0〜15でないとerror
// http://space.geocities.jp/digital_clock_2006/HSP/module/int2char.htm
// からのコピペw
#defcfunc one_at_int2char_on4dbl int cc
if (cc<=-1)|(cc>=16){
logmes "one_at_int2char内のerror"
logmes "引数は0〜15の値にして下さい"
logmes "引数の値:"+str(cc)
return -1
}
switch cc
case 0 :return "0"
case 1 :return "1"
case 2 :return "2"
case 3 :return "3"
case 4 :return "4"
case 5 :return "5"
case 6 :return "6"
case 7 :return "7"
case 8 :return "8"
case 9 :return "9"
case 10 :return "a"
case 11 :return "b"
case 12 :return "c"
case 13 :return "d"
case 14 :return "e"
case 15 :return "f"
swend
return -1
// この関数編集
// 16進表記の引数(0〜15)を数値に変換して返す
// 引数の長さが1でないとerror
// 引数の値が0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,fの
// どれかでないとerror
// http://space.geocities.jp/digital_clock_2006/HSP/module/char2int.htm
// からのコピペw
#defcfunc one_at_char2int_on4dbl str cc
f=0
ff=0
fff=0
l=strlen(cc)
if l!=1{
logmes "one_at_char2int内のerror"
logmes "文字列型引数ccの長さは1にして下さい"
logmes "引数の長さ:"+l
return -1
}
if (cc=="0")|(cc=="1")|(cc=="2")|(cc=="3")|(cc=="4"){f=1}
if (cc=="5")|(cc=="6")|(cc=="7")|(cc=="8")|(cc=="9"){ff=1}
if (cc=="a")|(cc=="b")|(cc=="c")|(cc=="d")|(cc=="e")|(cc=="f"){fff=1}
if (cc=="A")|(cc=="B")|(cc=="C")|(cc=="D")|(cc=="E")|(cc=="F"){ffff=1}
if (f==0)&(ff=0)&(fff=0)&(ffff=0){
logmes "one_at_char2int内のerror"
logmes "引数は"
logmes "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f"
logmes "のどれかにして下さい"
logmes "引数の値:"+cc
return -1
}
switch cc
case "0":return 0
case "1":return 1
case "2":return 2
case "3":return 3
case "4":return 4
case "5":return 5
case "6":return 6
case "7":return 7
case "8":return 8
case "9":return 9
case "a":case "A":return 10
case "b":case "B":return 11
case "c":case "C":return 12
case "d":case "D":return 13
case "e":case "E":return 14
case "f":case "F":return 15
swend
return -1
#global
// dat set
// strのtest
tmp_r=""
str2ints tmp_r,player_name
logmes tmp_r
repeat 101
tmp_r+="0"
loop
logmes tmp_r
tmp_r=strmid(tmp_r,0,100)
logmes tmp_r
LP4_dat+=tmp_r
// intのtest
logmes "LV:"+str(player_LV)
s=int2str(player_LV)
logmes "s:"+s
logmes "f:"+str(int2int(s))
LP4_dat+=s
logmes "exp:"+str(player_exp)
s=int2str(player_exp)
logmes "s:"+s
logmes "f:"+str(int2int(s))
LP4_dat+=s
logmes "next_exp:"+str(player_next_exp)
s=int2str(player_next_exp)
logmes "s:"+s
logmes "f:"+str(int2int(s))
LP4_dat+=s
// dat set end
// dat 展開
logmes ""+LP4_dat
piyo_name=strmid(LP4_dat,0,100)
logmes ""+piyo_name
cur_name=""
ints2str cur_name,piyo_name
logmes "f:"+cur_name
cur_LV=strmid(LP4_dat,100,8)
logmes ""+cur_LV
logmes "f:"+str(int2int(cur_LV))
cur_exp=strmid(LP4_dat,108,8)
logmes ""+cur_exp
logmes "f:"+str(int2int(cur_exp))
cur_next_exp=strmid(LP4_dat,116,8)
logmes ""+cur_next_exp
logmes "f:"+str(int2int(cur_next_exp))
// dat 展開 end
randomize 100
l=strlen(LP4_dat)
repeat l
hoge=strmid(LP4_dat,cnt,1)
hoge=one_at_char2int_02(hoge)
hoge=hoge xor rnd(16)
hoge=one_at_int2char_02(hoge)
;logmes ""+hoge
poke LP4_dat,cnt,peek(hoge,0)
loop
logmes "dat"
logmes ""+LP4_dat
randomize
data_size=100+24
sdim key_mix,data_size
repeat data_size
piyo=rnd(16)
piyo=one_at_int2char_02(piyo)
poke key_mix,cnt,peek(piyo,0)
loop
key_A_A=1000
key_A_A\=strlen(key_mix)
key_A_A=strmid(key_mix,key_A_A,1)
key_A_A=one_at_char2int_02(key_A_A)
key_A_B=2000
key_A_B\=strlen(key_mix)
key_A_B=strmid(key_mix,key_A_B,1)
key_A_B=one_at_char2int_02(key_A_B)
key_A_C=3000
key_A_C\=strlen(key_mix)
key_A_C=strmid(key_mix,key_A_C,1)
key_A_C=one_at_char2int_02(key_A_C)
key_A_D=4000
key_A_D\=strlen(key_mix)
key_A_D=strmid(key_mix,key_A_D,1)
key_A_D=one_at_char2int_02(key_A_D)
key_A=(key_A_A/2)
key_A*=16
key_A+=key_A_B
key_A*=16
key_A+=key_A_C
key_A*=16
key_A+=key_A_D
logmes "key:"+key_A
randomize key_A
l=strlen(LP4_dat)
repeat l
hoge=strmid(LP4_dat,cnt,1)
hoge=one_at_char2int_02(hoge)
hoge=hoge xor rnd(16)
hoge=one_at_int2char_02(hoge)
;logmes ""+hoge
poke LP4_dat,cnt,peek(hoge,0)
loop
logmes "dat"
logmes ""+LP4_dat
LP4_dat_dat=""+LP4_dat+"\n"
LP4_dat_dat_A=LP4_dat
復号
randomize 100
l=strlen(LP4_dat)
repeat l
hoge=strmid(LP4_dat,cnt,1)
hoge=one_at_char2int_02(hoge)
hoge=hoge xor rnd(16)
hoge=one_at_int2char_02(hoge)
;logmes ""+hoge
poke LP4_dat,cnt,peek(hoge,0)
loop
logmes "dat"
logmes ""+LP4_dat
key_A_A=1000
key_A_A\=strlen(key_mix)
key_A_A=strmid(key_mix,key_A_A,1)
key_A_A=one_at_char2int_02(key_A_A)
key_A_B=2000
key_A_B\=strlen(key_mix)
key_A_B=strmid(key_mix,key_A_B,1)
key_A_B=one_at_char2int_02(key_A_B)
key_A_C=3000
key_A_C\=strlen(key_mix)
key_A_C=strmid(key_mix,key_A_C,1)
key_A_C=one_at_char2int_02(key_A_C)
key_A_D=4000
key_A_D\=strlen(key_mix)
key_A_D=strmid(key_mix,key_A_D,1)
key_A_D=one_at_char2int_02(key_A_D)
key_A=(key_A_A/2)
key_A*=16
key_A+=key_A_B
key_A*=16
key_A+=key_A_C
key_A*=16
key_A+=key_A_D
logmes "key:"+key_A
randomize key_A
l=strlen(LP4_dat_dat_A)
repeat l
hoge=strmid(LP4_dat_dat_A,cnt,1)
hoge=one_at_char2int_02(hoge)
hoge=hoge xor rnd(16)
hoge=one_at_int2char_02(hoge)
;logmes ""+hoge
poke LP4_dat_dat_A,cnt,peek(hoge,0)
loop
logmes "dat"
logmes ""+LP4_dat_dat_A