Test Rockey4smart Encryption Lock module Word and three algorithm usage C # code
private void Btn_lookzzghjk_click (object sender, EventArgs e) {if (THIS.R = = null) {
MessageBox.Show ("Search for encryption lock]!", "hint");
Return
} string val = "";
String sn = ""; Get the password on the interface this.
GetPassword ();
R.find ();
Open encryption lock UINT RET = R.open ();
Ry4errcode Enumerrcode = R.getretcodeenum (ret);
if (Enumerrcode = = ry4errcode.err_success) {string msg = "";
Read user store data 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 (Buffar Ray);//SYSTEM.TEXT.ENCOding.
Default.getstring (Buffarray);
msg + sn_val;
else {msg = "," + R.GETERR_CN (ret); //Get timing information//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//{//count information 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, "hint"); Check the module Word state program 0-63 modular word units ushort validate=0;
UShort Decreasable=0;
msg = "";
for (ushort TPOs = 0; TPOs < tpos++) {Validate = 0;
decreasable = 0;
ret = R.check_module (TPOs, ref Validate, ref decreasable); if (ret = 0) {msg = "pos=" + tpos + = valid value is "+ r.gethex4 (Validate) +", Descending value: "
+ r.gethex4 (decreasable);
if (tpos% 2 = 0) {msg = "\ n";
}} MessageBox.Show (MSG, "Check module word status-hint"); Algorithm one Test//(1) Set the value of the module Word 4 is 0x2121, not descending r.set_module (4, 0x2121, Enumdecreasable.node
creasable); 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) Write algorithm ret=r.write_arithmetic (0, R.get_buffer_value (CMDS)); UINT LP1 = 0; Compute the address uint LP2 = 4;
Modular Word pos ushort p1 = 5;
ushort P2 = 3;
ushort P3 = 1;
ushort P4 = 0xFFFF;
(3) compute a 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, "algorithm one Test-hint");
Algorithm II Test msg = "";
(1) write algorithm ten 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 (R.get_buffer_value (C2_CMDS));
(2) Seed code LP2 = 0x12345678; R.seed (LP2, ref P1, ref P2, ref P3, ref P4); msg + + "Seed Code:" +r.gethex8 (LP2) + ", e=" + r.gethex4 (p1) + ", f=" + r.gethex4 (p2) + ", g=" + r.gethex4 (P3) + ", h=" + r.gethex4 (P4
) + "\ n"; (3) Calculating two LP1 = 10; Compute address LP2 = 0x12345678;
Seed code 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, "Algorithm II test-hint");
Algorithm three test msg = "";
(1) write algorithm 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 (R.get_buffer_value (C3_CMDS)); (2) Set the value of the module word 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) Calculating three LP1 = 17; Compute the address LP2 = 0;
First address 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, "algorithm three test-hint");
msg = ""; LP1 = 17; Compute the address LP2 = 1;
First address 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, "algorithm three test-hint");
//Turn off Encryption lock R.close (); }
---The---end---
---VP:HSG
---create date:2012-05-10