#code=936T950
@TEAM ENVI^ EnviMode=1| ENVI^ ForceLocal=1


SET &SRCFILE=%&CurFile%     //测试源文件
SET &JMFILE=%&SRCFILE%.jm   //加密文件


SET &RAWDAT=   //未加密数据
SET &SECDAT=   //加密数据
//GETF#   "%&SRCFILE%",0,&SRCDAT

_SUB  JiaMi  //&SECDAT
CODE *jm  %~1,#,100,1,0,64     //头64字节和后面交换，让人找不到北
CODE *jm  %~1,+,0x31323334,    // + 0x31323334
CODE *jm  %~1,^,0x20A12093,    // ^ 0x20A12093
CODE *jm  %~1,>,4,4,           // 右移 +4bit
_END

_SUB JieMi  //&SRCDAT
CODE *jm  %~1,>,-4,4,          // 右移 -4bit
CODE *jm  %~1,^,0x20A12093,    // ^ 0x20A12093
CODE *jm  %~1,+,-0x31323334,   // + -0x31323334
CODE *jm  %~1,#,100,1,0,64     //头64字节和后面交换，
_END

WIN1
_SUB WIN1,W287H254,加密/解密演示,
    ITEM ITEMA,L110T58W60H30,加密,OnJiaMi
    ITEM ITEME,L110T134W60H30,解密,OnJieMi
    IFEX %JMFILE%,! ENVI @ITEME.Enable=0
_END

_SUB OnJiaMi
    IFEX %SRCFILE%,! TEAM MESS %SRCFILE% 不存在| EXIT
    GETF#   "%&SRCFILE%",0#0x7FFFFFFFFFFFFFFF,&SECDAT
    JiaMi &SECDAT                 //内存中加密
    PUTF -dd -len=0 %JMFILE%,0,zero //清除旧数据
    PUTF#*  %JMFILE%,0,&SECDAT    //保存加密的数据到加密文件
    IFEX %JMFILE%,  ENVI @ITEME.Enable=1
_END

_SUB OnJieMi
    IFEX %JMFILE%,! TEAM MESS %JMFILE% 不存在| EXIT
    GETF#   "%JMFILE%",0#0x7FFFFFFFFFFFFFFF,&SRCDAT  //读入加密的文件
    JieMi &SRCDAT               //内存中解密
    MESS. %&SRCDAT%
_END

