vb.net - How to make a "key generator" knowing the formula -
i have formula check 9 integers,
first digit(d1) must be: 1, 2, 5, 6, 8 or 9 lastly digit(d9) must be: 0 or 9 9xd1+8xd2+7xd3+6xd4+5xd5+4xd6+3xd7+2xd8+d9 mod 11 = 0
i can "validate" key, how can generate more of this, knowing conditions right?
how can generate 9 different integers 0 9 , check them under formula?
thanks helping!
generate first 7 digits randomly, calculating formula digits. set 9th digit's value 9, , add together formula. calculate value 8th digit based on mod of result of formula causes result of formula mod 11 = 0. for exception case attempting causes mod 11 = 9, set 9th digit 0.
implementation:
private randgen new random() function gennum() integer dim digits(0 8) integer gennum = 0 dim checksum integer digits(0) = randgen.next(6) + 1 if digits(0) >= 3 digits(0) += 2 if digits(0) >= 7 digits(0) += 1 checksum += digits(0) * 9 d integer = 1 6 digits(d) = randgen.next(10) checksum += digits(d) * (9 - d) next digits(8) = 9 checksum += digits(8) if (checksum mod 11) mod 2 = 1 digits(7) = (11 - (checksum mod 11)) \ 2 else digits(7) = ((12 - (checksum mod 11)) \ 2 + 4) mod 10 end if checksum += digits(7) * 2 if checksum mod 11 = 9 digits(8) = 0 dim pow10 integer = 1 d integer = 8 0 step -1 gennum += pow10 * digits(d) pow10 *= 10 next end function
vb.net vb.net-2010
No comments:
Post a Comment