中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-24 18:00
47,812 topics / 349,910 posts / today 1 new / 48,262 members
WinPE、PowerShell及其它命令行系统专区 » Ask about the calculation of the serial number?
Printable Version  2,661 / 4
Floor1 donpps Posted 2006-12-30 07:40
初级用户 Posts 20 Credits 56
The problem is as follows:
Input a serial number (a string consisting only of digits and uppercase letters). First, determine whether the input of the serial number is correct. If it does not meet the requirements (a string consisting only of digits and uppercase letters), return to re-enter. If it meets the requirements, start to calculate the registration code. Take the character that is the previous 1 bit of the ASCII code of the first character (for example, A is @, 9 is 8), take the character that is the previous 2 bits of the ASCII code of the second character (for example, A is?, 9 is 7), take the character that is the previous 4 bits of the ASCII code of the third character (for example, A is =, 9 is 5), take the character that is the previous 5 bits of the ASCII code of the fourth character (for example, A is <, 9 is 4), take the character that is the previous 1 bit of the ASCII code of the fourth from the last character, take the character that is the previous 2 bits of the ASCII code of the third from the last character, take the character that is the previous 4 bits of the ASCII code of the second from the last character, take the character that is the previous 5 bits of the ASCII code of the last character, (the middle several characters do not participate in the calculation), and form an 8 (or 6, 4, 2)-bit character registration code. For example, the serial number: W1D0W7M5A0J593459609490, the registration number: V/@+825+
It is easier to do with Excel. With p processing, I don't know how to do it! I want to use the following text file for query, first check the ASCII code by character, then do the subtraction calculation, and then query the character with the calculation result. Unfortunately, I always can't write it well. Maybe the solution with debug is simpler. Please ask for the optimal solution, thank you.
+ 43
, 44
- 45
. 46
/ 47
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
: 58
; 59
< 60
= 61
> 62
? 63
@ 64
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
Floor2 electronixtar Posted 2006-12-30 13:24
铂金会员 Posts 2,672 Credits 7,493
p processing can also be considered as sn, top~
Floor3 tigerpower Posted 2006-12-31 12:46
中级用户 Posts 99 Credits 377
Use mawk :



C:\>mawk "BEGIN{for(k=43;k<=90;k++){m=sprintf(\"%c\",k);n2i=k};for(i=1;i==1;){printf \"\nPlease enter the SN: \";getline;if(length($0)<8){print \"SN must more than 8 characters\";continue};for(j=1;j<=length($0);j++){if (substr($0,j,1)!~//){print \"All characters must in !!!\";break}};if (j>length($0)){i=0}};key_gen(0,-1);key_gen(1,-2);key_gen(2,-4);key_gen(3,-5);key_gen(-4,-1);key_gen(-3,-2);key_gen(-2,-4);key_gen(-1,-5);print \"The KEY is: \" key};function key_gen(p,q){key=sprintf(\"%s%c\",key,n2i+q)}"



For more command-line tools, please go to the WinPE, PowerShell section of this forum (click to enter)

Floor4 lxmxn Posted 2007-05-10 01:34
版主 Posts 4,938 Credits 11,386
tigerpower is really an expert, Orz
Floor5 dqls889 Posted 2007-05-17 00:18
初级用户 Posts 36 Credits 68
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023