測試Rockey4Smart加密鎖之模組字和三演算法的用法C#代碼
private void btn_LookZzghjk_Click(object sender, EventArgs e) { if (this.r == null) { MessageBox.Show("先執行[尋找加密鎖]!", "提示"); return; } string val = ""; string sn = ""; //擷取介面上的密碼 this.GetPassword(); r.Find(); //開啟加密鎖 uint ret = r.Open(); Ry4ErrCode enumErrCode = r.GetRetCodeEnum(ret); if (enumErrCode == Ry4ErrCode.ERR_SUCCESS) { string msg = ""; //讀取使用者儲存區資料 ushort pos = 0; ushort len = 100; byte[] buffArray = new byte[1000]; ret = r.Read(pos, len, ref buffArray); enumErrCode = r.GetRetCodeEnum(ret); if (enumErrCode == Ry4ErrCode.ERR_SUCCESS) { string sn_val = r.Get_Buffer_Value(buffArray);// System.Text.Encoding.Default.GetString(buffArray); msg += sn_val; } else { msg += "," + r.GetERR_Cn(ret); } //擷取計時資訊 //if (rb_js.Checked == true) //{ ushort js_val = new ushort(); byte[] t_buff = new byte[1024]; TimerType timertype = TimerType.Hour; ret = r.Get_Timer(0, ref js_val, ref timertype, ref t_buff); string js_val_str = System.Text.Encoding.Default.GetString(t_buff); msg += "," + js_val_str; //} //else //{ //計次資訊 ushort c_val = new ushort(); EnumDecreasable da = EnumDecreasable.NoDecreasable; r.Get_Counter(0, ref c_val, ref da); msg += "," + c_val.ToString(); //} MessageBox.Show(msg, "提示"); //檢查模組字狀態程式0-63個模組字單元 ushort Validate=0; ushort Decreasable=0; msg = ""; for (ushort tpos = 0; tpos < 64; tpos++) { Validate = 0; Decreasable = 0; ret = r.Check_Module(tpos, ref Validate, ref Decreasable); if (ret == 0) { msg +=" pos="+ tpos + "=有效值為" + r.GetHex4(Validate) + ",遞減值:" + r.GetHex4(Decreasable) ; if (tpos % 2 == 0) { msg +="\n"; } } } MessageBox.Show(msg, "檢查模組字狀態-提示"); //演算法一測試 //(1)設定模組字4的值為0x2121,不遞減 r.Set_Module(4, 0x2121, EnumDecreasable.NoDecreasable); string cmds="H=H^H, A=A*23, F=B*17, A=A+F, A=A+G, A=A<C, A=A^D, B=B^B, C=C^C, D=D^D"; //(2)寫入演算法00 ret=r.Write_Arithmetic(0, r.Get_Buffer_Value(cmds)); uint lp1 = 0; //計算地址 uint lp2 = 4; //模組字pos ushort p1 = 5; ushort p2 = 3; ushort p3 = 1; ushort p4 = 0xffff; //(3)計算一 ret=r.Calculate_1(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); msg="Result = ((5*23 + 3*17 + 0x2121) < 1) ^ 0xffff = 0xBC71\n"; msg += "A=" + r.GetHex4(p1) + ",B=" + r.GetHex4(p2) + ",C=" + r.GetHex4(p3) + ",D=" + r.GetHex4(p4); MessageBox.Show(msg, "演算法一測試-提示"); //演算法二測試 msg = ""; //(1)寫入演算法10 string c2_cmds="A=A+B, A=A+C, A=A+D, A=A+E, A=A+F, A=A+G, A=A+H"; r.Write_Arithmetic(10, r.Get_Buffer_Value(c2_cmds)); //(2)種子碼 lp2 = 0x12345678; r.Seed(lp2, ref p1, ref p2, ref p3, ref p4); msg += "種子碼為:"+r.GetHex8(lp2)+",E=" + r.GetHex4(p1) + ",F=" + r.GetHex4(p2) + ",G=" + r.GetHex4(p3) + ",H=" + r.GetHex4(p4)+"\n"; //(3)計算二 lp1 = 10; //計算地址 lp2 = 0x12345678; //種子碼 p1 = 1; p2 = 2; p3 = 3; p4 = 4; ret = r.Calculate_2(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); msg += "Result =d03a + 94d6 + 96a9 + 7f54 + 1 + 2 + 3 + 4=0x7b17\n"; msg += "A=" + r.GetHex4(p1) + ",B=" + r.GetHex4(p2) + ",C=" + r.GetHex4(p3) + ",D=" + r.GetHex4(p4); MessageBox.Show(msg, "演算法二測試-提示"); //演算法三測試 msg = ""; //(1)寫入演算法 string c3_cmds = "A=A+B, A=A+C, A=A+D, A=A+E, A=A+F, A=A+G, A=A+H,A=A+I"; r.Write_Arithmetic(17, r.Get_Buffer_Value(c3_cmds)); //(2)設定模組字的值 r.Set_Module(0, 1, EnumDecreasable.NoDecreasable); r.Set_Module(1, 2, EnumDecreasable.NoDecreasable); r.Set_Module(2, 3, EnumDecreasable.NoDecreasable); r.Set_Module(3, 4, EnumDecreasable.NoDecreasable); r.Set_Module(4, 5, EnumDecreasable.NoDecreasable); //(3)計算三 lp1 = 17; //計算地址 lp2 = 0; //首地址0,1,2,3 p1 = 1; p2 = 2; p3 = 3; p4 = 4; ret = r.Calculate_3(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); msg += "Result = 1+2+3+4+1+2+3+4=0x14\n"; msg += "A=" + r.GetHex4(p1) + ",B=" + r.GetHex4(p2) + ",C=" + r.GetHex4(p3) + ",D=" + r.GetHex4(p4); MessageBox.Show(msg, "演算法三測試-提示"); msg = ""; lp1 = 17; //計算地址 lp2 = 1; //首地址1,2,3,4 p1 = 1; p2 = 2; p3 = 3; p4 = 4; ret = r.Calculate_3(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); msg += "Result = 2+3+4+5+1+2+3+4=0x18\n"; msg += "A=" + r.GetHex4(p1) + ",B=" + r.GetHex4(p2) + ",C=" + r.GetHex4(p3) + ",D=" + r.GetHex4(p4); MessageBox.Show(msg, "演算法三測試-提示"); } //關閉加密鎖 r.Close(); }
---the---end---
---vp:hsg
---create date:2012-05-10