It is said that the encryption algorithm has different encryption results each time, but the decryption results are the same.
Using system;
Namespace test001
{
/**
Encrypt and decrypt ssource.
@ Param ssource string: Operation string
@ Param iflag INT: Operation Type 1-encryption 2-decryption
@ Return string: Encrypted or decrypted string
**/
Public class Password
{
Public password ()
{
}
Public static string pword (string ssource, int iflag)
{
If (ssource = NULL)
Return NULL;
If (ssource. Equals (""))
Return "";
Int li_len, I, li_asc, li_rand, li_head;
String ls_ I, ls_code = "";
If (iflag = 1)
{
Li_len = ssource. length;
Random rdm1 = new random (~ Unchecked (INT) datetime. Now. ticks ));
Li_head = (INT) (rdm1.nextdouble () * 10 );
If (li_head = 0)
Li_head = 1;
For (I = 0; I <li_len; I ++)
{
Random rdm2 = new random (~ Unchecked (INT) datetime. Now. ticks ));
Int rand2 = (INT) (rdm2.nextdouble () * 94 );
If (rand2 = 0)
Rand2 = 1;
Li_rand = rand2 + 32;
Li_asc = convert. toint32 (ssource. tochararray (I, 1) [0]);
Ls_ I = (char) (li_asc-I). tostring ();
If (li_asc + I + li_heads> 126)
{
If (li_rand % 2 = 1)
Li_rand = li_rand + 1;
Ls_ I = (char) (li_rand). tostring () + (char) (li_asc-I-li_head). tostring ();
}
Else
{
If (li_rand % 2 = 0)
Li_rand = li_rand + 1;
Ls_ I = (char) (li_rand). tostring () + (char) (li_asc + I + li_head). tostring ();
}
Ls_code = ls_code + ls_ I;
}
Random rdm3 = new random (~ Unchecked (INT) datetime. Now. ticks ));
Int rand1 = (INT) (rdm3.nextdouble () * 9 );
If (rand1 = 0)
Rand1 = 1;
Ls_code = (char) (rand1*10 + li_head + 40). tostring () + ls_code;
}
Else
{
Int li_ret;
Li_len = ssource. length;
Ls_code = "";
Li_ret = convert. toint32 (ssource. tochararray (0, 1) [0]) % 10;
For (I = 2; I <li_len; I = I + 2)
{
Li_asc = convert. toint32 (ssource. tochararray (I, 1) [0]);
If (convert. toint32 (ssource. tochararray (I-1,1) [0]) % 2 = 0)
{
Ls_ I = (char) (li_asc + (I-1)/2 + li_ret). tostring ();
}
Else
{
Ls_ I = (char) (li_asc-(I-1)/2-li_ret). tostring ();
}
Ls_code = ls_code + ls_ I;
}
}
Return ls_code;
}
}
}
If the same method is executed, the interval should be greater than 10 milliseconds. Otherwise, the encryption result will be very likely to be the same.
As follows:
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
In general, the following three results are the same. The results are indeed different ~~~
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Thread. Sleep (100 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Thread. Sleep (100 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );
Thread. Sleep (100 );
Password. pword ("sfdaslkfklsdngnsdgnsdgs @ 22", 1 );