China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-24 19:56
中国DOS联盟论坛 » WinPE、PowerShell及其它命令行系统专区 » Ask about the calculation of the serial number? View 2,662 Replies 4
Original Poster Posted 2006-12-30 07:40 ·  中国 湖南 永州 电信
初级用户
Credits 56
Posts 20
Joined 2006-04-23 12:47
20-year member
UID 54313
Status Offline
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
Floor 2 Posted 2006-12-30 13:24 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
p processing can also be considered as sn, top~
Floor 3 Posted 2006-12-31 12:46 ·  中国 上海 电信
中级用户
★★
大师兄
Credits 377
Posts 99
Joined 2005-08-26 07:37
20-year member
UID 41945
Status Offline
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)

Floor 4 Posted 2007-05-10 01:34 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
tigerpower is really an expert, Orz
Floor 5 Posted 2007-05-17 00:18 ·  中国 四川 绵阳 电信
初级用户
Credits 68
Posts 36
Joined 2006-12-19 09:47
19-year member
UID 73948
Gender Male
Status Offline
Forum Jump: