Generate Chinese Chinese Character Verification Code Principle

xiaoxiao2021-03-05  28

Original source http://edu.cn700.com/edu_24/2005490187-1.html is only for learning research

///

/// randomly generated a Chinese character /// /// private string createword () {// Chinese character encoding element string [] rbase = new string [ 16] {"0", "1", "2", "4", "5", "6", "7", "8", "9", "a", "b" , "c", "d", "e", "f"}; // random number random rnd = new random ();

// Local code first int R1 = rnd.next (11, 14); // The Chinese character encoding starts from B0, to D7 is commonly used Chinese characters String R1String = rbase [r1] .tostring (). Trim () ;

// location code second RND = new random (r1 * unchecked ((int) datetime.now.ticks)); / / Replacing the random number generator seeds to avoid repeating values ​​INT R2; if (R1 == 13) {R2 = rnd.next (0, 7); // Location D7 The Chinese characters after the beginning of the facts are difficult to see the traditional Chinese characters} else {r2 = rnd.next (0, 16);} String r2string = rbase [r2 ] .ToString (). Trim ();

// location code third RND = new random (R2 * unchecked ((int) DateTime.now.ticks)); int R3 = rnd.next (10, 16); string r3string = rbase [r3] .tostring () .Trim ();

// location code fourth RND = new random (R3 * Unchecked ((int) DateTime.now.ticks)); int R4; if (R3 == 10) {R4 = rnd.next (1, 16); / / The first position per zone is empty} else {if (R3 == 15) {R4 = rnd.next (0, 15); // The last position per zone is also empty} else r4 = RND. Next (0,16);} String R4String = RBASE [R4] .tostring (). Trim ();

/ / Define two types of byte variable storage generated random Chinese character code byte byte1 = convert.tobyte (R1String R2String, 16); byte byte2 = convert.tobyte (R3String R4String, 16);

// Put the byte arrays of one of the generated characters into a BYTE array byte [] wordbyte = new byte [] {byte1, byte2};

// Output Encoding GB = Encoding.Getencoding ("GB2312"); string word = gb.getstring (Wordbyte, 0, WordbyTe.Length); Return Word;}

转载请注明原文地址:https://www.9cbs.com/read-34246.html

New Post(0)