├── .gitignore ├── ComputerNetwork ├── 150120526_殷悦.zip ├── Exp01 │ ├── 1 │ ├── README.md │ ├── a.out │ ├── a2.out │ ├── a3.out │ ├── recv.c │ ├── threadrecv.c │ ├── time.c │ ├── 实验报告.doc │ └── 网络编程实验.docx ├── Exp02 │ ├── README.md │ ├── a.out │ ├── a2.out │ ├── a3.out │ ├── echo_udp.c │ ├── echo_udp2.c │ ├── test.c │ ├── 实验报告.doc │ └── 网络编程实验.doc ├── Exp03 │ ├── README.md │ ├── a.out │ ├── a2.out │ ├── icmp.c │ ├── rawsniffer.c │ ├── 实验报告.doc │ └── 网络编程实验.doc ├── Exp04 │ ├── README.md │ ├── a.out │ ├── select.c │ ├── 实验报告.doc │ └── 网络编程实验.doc ├── README.md ├── 实验报告.doc ├── 实验报告.pdf └── 说明.txt ├── Cryptography ├── 150120526_殷悦.zip ├── DES.c ├── DES.exe ├── README.md ├── RSA.c ├── RSA.exe ├── cipher.bmp ├── encipher.bmp ├── encipher2.bmp ├── passwd.bmp ├── 密码学实验报告.doc └── 密码学实验报告.pdf ├── DataBase ├── 150120526_殷悦.zip ├── Exp01 │ ├── README.md │ ├── 实验一-实验代码.sql │ └── 数据库备份.sql.bak ├── Exp02 │ ├── README.md │ ├── 实验二-数据库查询语句.sql │ └── 数据库备份.sql.bak ├── Exp03 │ ├── PB3 4.sql.bak │ ├── README.md │ ├── calculator.pbl │ ├── calculator.pbt │ ├── dbcon.pbl │ ├── dbcon.pbt │ ├── equation.pbl │ ├── equation.pbt │ ├── pms.pbl │ ├── pms.pbt │ ├── 实验三-数据库连接.pbw │ ├── 实验三-研究生院管理系统.pbw │ ├── 实验三-解方程.pbw │ └── 实验三-计算器.pbw ├── Exp04 │ ├── PB3 4.sql.bak │ ├── README.md │ ├── pms.pbl │ ├── pms.pbt │ ├── search.pbl │ ├── search.pbt │ ├── 实验四-信息搜索.pbw │ └── 实验四-研究生管理系统.pbw ├── README.md ├── 实验报告.doc ├── 实验报告.pdf └── 说明.txt ├── ElectronicCommerce ├── 150120526_殷悦.zip ├── Exp01 │ ├── README.md │ ├── conn.asp │ ├── create.sql │ ├── goods.asp │ ├── index.htm │ ├── login.asp │ ├── opr.asp │ ├── reg.asp │ ├── reg.htm │ └── 电子商务与安全实验报告(实验一).doc ├── Exp02 │ ├── README.md │ ├── RSA │ ├── RSA.c │ └── 电子商务与安全实验报告(实验二).doc ├── Exp03 │ ├── README.md │ ├── conn.asp │ ├── create.sql │ ├── index.asp │ ├── opr.asp │ ├── order.asp │ ├── shoppingCart.asp │ ├── test.asp │ └── 电子商务与安全实验报告(实验三).doc ├── README.md ├── 电子商务与安全实验报告.doc ├── 电子商务与安全实验报告.pdf └── 说明.txt ├── InformationContentSecurity └── README.md ├── InformationSystemSecurity ├── 150120526_殷悦_实验报告.doc ├── 150120526_殷悦_实验报告.pdf ├── 150120526_殷悦_计算机系统安全实验报告.zip ├── Exp01 │ ├── Client.py │ ├── README.md │ ├── Server.php │ ├── ServerSql.sql │ └── yinyue.txt ├── Exp02 │ ├── README.md │ ├── 殷悦威胁列表.doc │ ├── 殷悦已有安全措施确认表.doc │ ├── 殷悦脆弱性列表.doc │ ├── 殷悦资产识别清单.doc │ ├── 殷悦重要资产清单.doc │ ├── 殷悦风险处理计划.doc │ ├── 殷悦风险评估报告.doc │ └── 殷悦风险评估方案.doc └── README.md ├── LICENSE ├── OperatingSystem ├── Exp01 │ ├── 1PRO_CON.DSW │ ├── 1PRO_CON.OPT │ ├── 1PRO_CON.ncb │ ├── 1pro_con.c │ ├── 1pro_con.c_back │ ├── 1pro_con.dsp │ ├── 1pro_con.exe │ ├── 1pro_con.plg │ ├── README.md │ └── a.out ├── Exp02 │ ├── MEM_OPR2.DSW │ ├── MEM_OPR2.OPT │ ├── MEM_OPR2.ncb │ ├── README.md │ ├── a.out │ ├── mem_opr.c │ ├── mem_opr2.c │ ├── mem_opr2.dsp │ └── mem_opr2.plg ├── Exp03 │ ├── README.md │ ├── a.out │ ├── lib3.c │ └── main3.cpp ├── Exp04 │ ├── README.md │ ├── a.out │ ├── lib4.c │ ├── lib4.c_ │ ├── os.c │ └── os.cpp ├── README.md ├── zip │ ├── README.md │ ├── 殷悦_操作系统实验一.zip │ ├── 殷悦_操作系统实验三.zip │ ├── 殷悦_操作系统实验二.zip │ └── 殷悦_操作系统实验四.zip ├── 殷悦_操作系统实验一.doc ├── 殷悦_操作系统实验一.pdf ├── 殷悦_操作系统实验三.doc ├── 殷悦_操作系统实验三.pdf ├── 殷悦_操作系统实验二.doc ├── 殷悦_操作系统实验二.pdf ├── 殷悦_操作系统实验四.doc └── 殷悦_操作系统实验四.pdf └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /ComputerNetwork/150120526_殷悦.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/150120526_殷悦.zip -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/1: -------------------------------------------------------------------------------- 1 | [root@VM_21_212_centos 2.1]# vim recv.c 2 | [root@VM_21_212_centos 2.1]# gcc recv.c 3 | [root@VM_21_212_centos 2.1]# ./a.out s 8080 4 | Using recvlen: 5 | recv:test 6 | send:echo:test 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp01/a.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/a2.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp01/a2.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/a3.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp01/a3.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/recv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int prierr(char *msg){ 9 | printf("%s\n",msg); 10 | exit(1); 11 | return 0; 12 | } 13 | 14 | int recvn(int socket,char* buf,int len){ 15 | int msglen; 16 | int left=len; 17 | while(msglen>0){ 18 | msglen=read(socket,buf,left); 19 | if(msglen<0) 20 | printf("recv data err\n"); 21 | else if(msglen==0) 22 | return len-left; 23 | left-=msglen; 24 | buf+=msglen; 25 | } 26 | return len-left; 27 | } 28 | 29 | int recvl(int socket,char* buf){ 30 | int len; 31 | int rcvlen; 32 | char *p=buf; 33 | do{ 34 | rcvlen=read(socket,p,sizeof(buf)); 35 | if(rcvlen==-1) 36 | printf("recv error\n"); 37 | else if(rcvlen==0) 38 | printf("connection closed\n"); 39 | len+=rcvlen; 40 | p+=rcvlen; 41 | printf("%s",p); 42 | }while(rcvlen>0); 43 | return len; 44 | } 45 | 46 | int recvlen(int socket,char* buf){ 47 | int len; 48 | int rcvlen; 49 | char *p=buf; 50 | 51 | do{ 52 | rcvlen=read(socket,p,1); 53 | if(rcvlen==-1) 54 | printf("recv len\n"); 55 | len++; 56 | p++; 57 | }while(*p!='\n'); 58 | return len; 59 | } 60 | 61 | int main(int argc,char** argv){ 62 | int sockfd; 63 | int port; 64 | int server; 65 | int rcvlen; 66 | struct sockaddr_in addr; 67 | char msg[2000]; 68 | char msg2[2000]; 69 | int choice=0; 70 | if(argc != 3 && argc != 4) 71 | prierr("Usage:\n \ 72 | Server: s \n \ 73 | Client: c "); 74 | 75 | sockfd=socket(AF_INET,SOCK_STREAM,0); 76 | if(!strcmp(argv[1],"s")) 77 | server=1; 78 | else if (!strcmp(argv[1],"c")) 79 | server=0; 80 | else 81 | prierr("Wroung input"); 82 | memset(&addr,0,sizeof(addr)); 83 | addr.sin_family=AF_INET; 84 | if(server){ 85 | addr.sin_addr.s_addr=htonl(INADDR_ANY); 86 | addr.sin_port=htons(atoi(argv[2])); 87 | if(bind(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 88 | prierr("bind err"); 89 | if(listen(sockfd,5)==-1) 90 | prierr("listen err"); 91 | while(1){ 92 | int cliaddr; 93 | socklen_t clilen=sizeof(cliaddr); 94 | cliaddr=accept(sockfd,(struct sockaddr*)&cliaddr,&clilen); 95 | if(cliaddr==-1) 96 | prierr("accept err"); 97 | //rcvlen=read(cliaddr,msg,sizeof(msg)); 98 | ///* 99 | choice=0;//choice one you want to use 100 | switch(choice){ 101 | case 0: 102 | printf("Using recvn:\n"); 103 | rcvlen=recvn(cliaddr,msg,10); 104 | break; 105 | case 1: 106 | printf("Using recvl:\n"); 107 | rcvlen=recvl(cliaddr,msg); 108 | break; 109 | case 2: 110 | printf("Using recvlen:\n"); 111 | rcvlen=recvlen(cliaddr,msg); 112 | break; 113 | } 114 | //*/ 115 | printf("recv:%s\n",msg); 116 | //printf("recv len:%d\n",rcvlen); 117 | sprintf(msg2,"echo:%s",msg); 118 | if(!strcmp(msg,"q")) 119 | prierr("Bye bye"); 120 | strcpy(msg,msg2); 121 | write(cliaddr,msg,rcvlen); 122 | printf("send:%s\n",msg); 123 | close(cliaddr); 124 | } 125 | close(sockfd); 126 | }else{ 127 | addr.sin_addr.s_addr=inet_addr(argv[2]); 128 | addr.sin_port=htons(atoi(argv[3])); 129 | if(connect(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 130 | prierr("connect error!"); 131 | scanf("%s",&msg); 132 | write(sockfd,msg,sizeof(msg)); 133 | int rcvlen; 134 | char *p=msg; 135 | do{ 136 | rcvlen=read(sockfd,p,sizeof(msg)); 137 | if(rcvlen==-1) 138 | printf("recv error\n"); 139 | // else if(rcvlen==0) 140 | // printf("connection closed\n"); 141 | p=(char *)(p+sizeof(char)*rcvlen); 142 | }while(rcvlen>0); 143 | printf("recv %s\n",msg); 144 | close(sockfd); 145 | } 146 | 147 | 148 | return 0; 149 | } 150 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/threadrecv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int prierr(char *msg){ 10 | printf("%s\n",msg); 11 | exit(1); 12 | return 0; 13 | } 14 | void thread(void *arg){ 15 | int cliaddr=*(int *)arg; 16 | int rcvlen; 17 | char msg[2000]; 18 | char msg2[2000]; 19 | printf("tid:%u\n",(unsigned short)pthread_self()); 20 | rcvlen=read(cliaddr,msg,sizeof(msg)); 21 | if(rcvlen==-1) 22 | printf("recv err\n"); 23 | printf("recv:%s\n",msg); 24 | //printf("recv len:%d\n",rcvlen); 25 | sprintf(msg2,"echo:%s",msg); 26 | strcpy(msg,msg2); 27 | write(cliaddr,msg,rcvlen); 28 | printf("send:%s\n",msg); 29 | close(cliaddr); 30 | } 31 | 32 | int main(int argc,char** argv){ 33 | int sockfd; 34 | int port; 35 | int server; 36 | int rcvlen; 37 | char msg[2000]; 38 | pthread_t id; 39 | struct sockaddr_in addr; 40 | int choice=0; 41 | if(argc != 3 && argc != 4) 42 | prierr("Usage:\n \ 43 | Server: s \n \ 44 | Client: c "); 45 | 46 | sockfd=socket(AF_INET,SOCK_STREAM,0); 47 | if(!strcmp(argv[1],"s")) 48 | server=1; 49 | else if(!strcmp(argv[1],"c")) 50 | server=0; 51 | else 52 | prierr("Wroung input"); 53 | memset(&addr,0,sizeof(addr)); 54 | addr.sin_family=AF_INET; 55 | if(server){ 56 | addr.sin_addr.s_addr=htonl(INADDR_ANY); 57 | addr.sin_port=htons(atoi(argv[2])); 58 | if(bind(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 59 | prierr("bind err"); 60 | if(listen(sockfd,5)==-1) 61 | prierr("listen err"); 62 | while(1){ 63 | int cliaddr; 64 | socklen_t clilen=sizeof(cliaddr); 65 | cliaddr=accept(sockfd,(struct sockaddr*)&cliaddr,&clilen); 66 | if(cliaddr==-1) 67 | prierr("accept err"); 68 | int ret=pthread_create(&id,NULL,(void *)thread,&cliaddr); 69 | if(ret!=0) 70 | prierr("create thread error"); 71 | } 72 | close(sockfd); 73 | }else{ 74 | addr.sin_addr.s_addr=inet_addr(argv[2]); 75 | addr.sin_port=htons(atoi(argv[3])); 76 | if(connect(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 77 | prierr("connect error!"); 78 | scanf("%s",&msg); 79 | write(sockfd,msg,sizeof(msg)); 80 | int rcvlen; 81 | char *p=msg; 82 | do{ 83 | rcvlen=read(sockfd,p,sizeof(msg)); 84 | if(rcvlen==-1) 85 | printf("recv error\n"); 86 | // else if(rcvlen==0) 87 | // printf("connection closed\n"); 88 | p=(char *)(p+sizeof(char)*rcvlen); 89 | }while(rcvlen>0); 90 | printf("recv %s\n",msg); 91 | close(sockfd); 92 | } 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int prierr(char *msg){ 10 | printf("%s\n",msg); 11 | exit(1); 12 | return 0; 13 | } 14 | 15 | int main(int argc,char** argv){ 16 | int sockfd; 17 | int port; 18 | int server; 19 | struct sockaddr_in addr; 20 | char msg[2000]; 21 | if(argc != 3 && argc != 4) 22 | prierr("Usage:\n \ 23 | Server: s \n \ 24 | Client: c "); 25 | 26 | sockfd=socket(AF_INET,SOCK_STREAM,0); 27 | if(!strcmp(argv[1],"s")) 28 | server=1; 29 | else if (!strcmp(argv[1],"c")) 30 | server=0; 31 | else 32 | prierr("Wroung input"); 33 | memset(&addr,0,sizeof(addr)); 34 | addr.sin_family=AF_INET; 35 | if(server){ 36 | addr.sin_addr.s_addr=htonl(INADDR_ANY); 37 | addr.sin_port=htons(atoi(argv[2])); 38 | if(bind(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 39 | prierr("bind err"); 40 | if(listen(sockfd,5)==-1) 41 | prierr("listen err"); 42 | while(1){ 43 | int cliaddr; 44 | socklen_t clilen=sizeof(cliaddr); 45 | cliaddr=accept(sockfd,(struct sockaddr*)&cliaddr,&clilen); 46 | if(cliaddr==-1) 47 | prierr("accept err"); 48 | time_t timep; 49 | time(&timep); 50 | sprintf(msg,"Time now:%s\n",asctime(gmtime(&timep))); 51 | printf("send %s\n",msg); 52 | write(cliaddr,msg,sizeof(msg)); 53 | close(cliaddr); 54 | } 55 | close(sockfd); 56 | }else{ 57 | addr.sin_addr.s_addr=inet_addr(argv[2]); 58 | addr.sin_port=htons(atoi(argv[3])); 59 | if(connect(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1) 60 | prierr("connect error!"); 61 | int rcvlen; 62 | char *p=msg; 63 | do{ 64 | rcvlen=read(sockfd,p,2000); 65 | if(rcvlen==-1) 66 | printf("recv error\n"); 67 | else if(rcvlen==0) 68 | printf("connection closed\n"); 69 | p=(char *)(p+sizeof(char)*rcvlen); 70 | }while(rcvlen>0); 71 | printf("recv %s\n",msg); 72 | close(sockfd); 73 | } 74 | 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp01/实验报告.doc -------------------------------------------------------------------------------- /ComputerNetwork/Exp01/网络编程实验.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp01/网络编程实验.docx -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp02/a.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/a2.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp02/a2.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/a3.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp02/a3.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/echo_udp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int prierr(char *msg){ 10 | printf("%s\n",msg); 11 | exit(1); 12 | return 0; 13 | } 14 | 15 | int main(int argc,char** argv){ 16 | int sockfd; 17 | int port; 18 | socklen_t len; 19 | int server; 20 | struct sockaddr_in saddr; 21 | struct sockaddr_in raddr; 22 | char msg[1500]; 23 | char msg2[1500]; 24 | int msglen; 25 | if(argc != 3 && argc != 4) 26 | prierr("Usage:\n \ 27 | Server: s \n \ 28 | Client: c "); 29 | 30 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 31 | if(!strcmp(argv[1],"s")) 32 | server=1; 33 | else if (!strcmp(argv[1],"c")) 34 | server=0; 35 | else 36 | prierr("Wroung input"); 37 | memset(&saddr,0,sizeof(saddr)); 38 | saddr.sin_family=AF_INET; 39 | if(server){ 40 | saddr.sin_addr.s_addr=htonl(INADDR_ANY); 41 | saddr.sin_port=htons(atoi(argv[2])); 42 | if(bind(sockfd,(struct sockaddr*)&saddr,sizeof(saddr))==-1) 43 | prierr("bind err"); 44 | while(1){ 45 | if((msglen=recvfrom(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,&len))<0) 46 | prierr("recvfrom error"); 47 | msg[msglen]=0; 48 | printf("%s\n",msg); 49 | sprintf(msg2,"echo:%s",msg); 50 | strcpy(msg,msg2); 51 | printf("%s\n",msg); 52 | len=sizeof(raddr); 53 | sendto(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,len); 54 | } 55 | close(sockfd); 56 | }else{ 57 | saddr.sin_addr.s_addr=inet_addr(argv[2]); 58 | saddr.sin_port=htons(atoi(argv[3])); 59 | while(1){ 60 | scanf("%s",msg); 61 | if(!strcmp(msg,"q")) 62 | close(sockfd); 63 | len=sizeof(saddr); 64 | sendto(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&saddr,len); 65 | if((msglen=recvfrom(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,&len))<0) 66 | prierr("recvfrom error"); 67 | msg[msglen]=0; 68 | fputs(msg,stdout); 69 | //printf("%s\n",msg); 70 | } 71 | } 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/echo_udp2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int prierr(char *msg){ 10 | printf("%s\n",msg); 11 | exit(1); 12 | return 0; 13 | } 14 | 15 | int main(int argc,char** argv){ 16 | int sockfd; 17 | int sockfd2; 18 | int port; 19 | socklen_t len; 20 | int server; 21 | struct sockaddr_in saddr; 22 | struct sockaddr_in raddr; 23 | char msg[1500]; 24 | char msg2[1500]; 25 | int msglen; 26 | pid_t fpid; 27 | if(argc != 3 && argc != 4) 28 | prierr("Usage:\n \ 29 | Server: s \n \ 30 | Client: c "); 31 | 32 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 33 | if(sockfd<0) 34 | prierr("father socket error"); 35 | if(!strcmp(argv[1],"s")) 36 | server=1; 37 | else if (!strcmp(argv[1],"c")) 38 | server=0; 39 | else 40 | prierr("Wroung input"); 41 | memset(&saddr,0,sizeof(saddr)); 42 | saddr.sin_family=AF_INET; 43 | if(server){ 44 | saddr.sin_addr.s_addr=htonl(INADDR_ANY); 45 | saddr.sin_port=htons(atoi(argv[2])); 46 | if(bind(sockfd,(struct sockaddr*)&saddr,sizeof(saddr))==-1) 47 | prierr("bind err"); 48 | while(1){ 49 | if((msglen=recvfrom(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,&len))<0) 50 | prierr("recvfrom error"); 51 | msg[msglen]=0; 52 | fpid=fork(); 53 | if(fpid<0) 54 | prierr("fork error\n"); 55 | else if(fpid==0)//Son 56 | break; 57 | } 58 | printf("fork\n"); 59 | sockfd2=socket(AF_INET,SOCK_DGRAM,0); 60 | if(sockfd2<0) 61 | prierr("son socket error"); 62 | printf("%s\n",msg); 63 | sprintf(msg2,"echo:%s",msg); 64 | strcpy(msg,msg2); 65 | printf("%s\n",msg); 66 | len=sizeof(raddr); 67 | if((msglen=sendto(sockfd2,msg,sizeof(msg),0,(struct sockaddr*)&raddr,len))<0) 68 | prierr("sendto error"); 69 | return 0; 70 | 71 | close(sockfd); 72 | }else{ 73 | saddr.sin_addr.s_addr=inet_addr(argv[2]); 74 | saddr.sin_port=htons(atoi(argv[3])); 75 | while(1){ 76 | scanf("%s",msg); 77 | if(!strcmp(msg,"q")) 78 | close(sockfd); 79 | len=sizeof(saddr); 80 | if((msglen=sendto(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&saddr,len))<0) 81 | prierr("sendto error"); 82 | if((msglen=recvfrom(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,&len))<0) 83 | prierr("recvfrom error"); 84 | msg[msglen]=0; 85 | fputs(msg,stdout); 86 | //printf("%s\n",msg); 87 | } 88 | } 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp02/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int prierr(char *msg){ 11 | printf("%s\n",msg); 12 | exit(1); 13 | return 0; 14 | } 15 | 16 | int main(int argc,char** argv){ 17 | int sockfd; 18 | int port; 19 | socklen_t len; 20 | int server; 21 | struct sockaddr_in saddr; 22 | struct sockaddr_in raddr; 23 | char msg[1500]; 24 | char msg2[1500]; 25 | int msglen; 26 | if(argc != 3 && argc != 4) 27 | prierr("Usage:\n \ 28 | Server: s \n \ 29 | Client: c "); 30 | 31 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 32 | if(!strcmp(argv[1],"s")) 33 | server=1; 34 | else if(!strcmp(argv[1],"c")) 35 | server=0; 36 | else 37 | prierr("Wroung input"); 38 | memset(&saddr,0,sizeof(saddr)); 39 | saddr.sin_family=AF_INET; 40 | if(server){ 41 | saddr.sin_addr.s_addr=htonl(INADDR_ANY); 42 | saddr.sin_port=htons(atoi(argv[2])); 43 | if(bind(sockfd,(struct sockaddr*)&saddr,sizeof(saddr))==-1) 44 | prierr("bind err"); 45 | while(1){ 46 | if((msglen=recvfrom(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,&len))<0) 47 | printf("recvfrom error\n"); 48 | msg[msglen]=0; 49 | printf("%s\n",msg); 50 | sprintf(msg2,"echo:%s",msg); 51 | strcpy(msg,msg2); 52 | printf("%s\n",msg); 53 | len=sizeof(raddr); 54 | sendto(sockfd,msg,sizeof(msg),0,(struct sockaddr*)&raddr,len); 55 | } 56 | close(sockfd); 57 | }else{ 58 | saddr.sin_addr.s_addr=inet_addr(argv[2]); 59 | saddr.sin_port=htons(atoi(argv[3])); 60 | //while(1){ 61 | //fgets(msg,sizeof(msg),stdin); 62 | //strcpy(msg,"test message"); 63 | if(!strcmp(msg,"q")) 64 | close(sockfd); 65 | len=sizeof(saddr); 66 | int i,j=0,k; 67 | printf("How many times do you want to test:\n"); 68 | scanf("%d",&k); 69 | struct timeval tv={1,0}; 70 | setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO,(char*)&tv, sizeof(tv)); 71 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define PACKET_SIZE 4096 11 | #define ERROR 0 12 | #define SUCCESS 1 13 | 14 | unsigned short cal_chksum(unsigned short *addr,int len){ 15 | int nleft=len; 16 | int sum=0; 17 | unsigned short *w=addr; 18 | unsigned short answer=0; 19 | 20 | while(nleft > 1){ 21 | sum += *w++; 22 | nleft -= 2; 23 | } 24 | 25 | if(nleft==1){ 26 | *(unsigned char *)(&answer)=*(unsigned char *)w; 27 | sum += answer; 28 | } 29 | sum=(sum >> 16) +(sum & 0xffff); 30 | sum +=(sum >> 16); 31 | answer=~sum; 32 | 33 | return answer; 34 | } 35 | 36 | int ping(char *ips,int timeout){ 37 | struct timeval *tval; 38 | int maxfds=0; 39 | fd_set readfds; 40 | 41 | struct sockaddr_in addr; 42 | struct sockaddr_in from; 43 | bzero(&addr,sizeof(addr)); 44 | addr.sin_family=AF_INET; 45 | addr.sin_addr.s_addr=inet_addr(ips); 46 | int sockfd; 47 | sockfd=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); 48 | if(sockfd < 0){ 49 | printf("ip:%s,socket error\n",ips); 50 | return ERROR; 51 | } 52 | 53 | struct timeval timeo; 54 | timeo.tv_sec=timeout / 1000; 55 | timeo.tv_usec=timeout % 1000; 56 | 57 | if(setsockopt(sockfd,SOL_SOCKET,SO_SNDTIMEO,&timeo,sizeof(timeo))==-1){ 58 | printf("ip:%s,setsockopt error\n",ips); 59 | return ERROR; 60 | } 61 | 62 | char sendpacket[PACKET_SIZE]; 63 | char recvpacket[PACKET_SIZE]; 64 | memset(sendpacket,0,sizeof(sendpacket)); 65 | 66 | pid_t pid; 67 | pid=getpid(); 68 | 69 | struct ip *iph; 70 | struct icmp *icmp; 71 | 72 | 73 | icmp=(struct icmp*)sendpacket; 74 | icmp->icmp_type=ICMP_ECHO; 75 | icmp->icmp_code=0; 76 | icmp->icmp_cksum=0; 77 | icmp->icmp_seq=0; 78 | icmp->icmp_id=pid; 79 | tval=(struct timeval *)icmp->icmp_data; 80 | gettimeofday(tval,NULL); 81 | icmp->icmp_cksum=cal_chksum((unsigned short *)icmp,sizeof(struct icmp)); 82 | 83 | int n; 84 | n=sendto(sockfd,(char *)&sendpacket,sizeof(struct icmp),0,(struct sockaddr *)&addr,sizeof(addr)); 85 | if(n < 1){ 86 | printf("ip:%s,sendto error\n",ips); 87 | return ERROR; 88 | } 89 | 90 | while(1){ 91 | FD_ZERO(&readfds); 92 | FD_SET(sockfd,&readfds); 93 | maxfds=sockfd + 1; 94 | n=select(maxfds,&readfds,NULL,NULL,&timeo); 95 | if(n <= 0){ 96 | printf("ip:%s,Time out error\n",ips); 97 | close(sockfd); 98 | return ERROR; 99 | } 100 | 101 | memset(recvpacket,0,sizeof(recvpacket)); 102 | int fromlen=sizeof(from); 103 | n=recvfrom(sockfd,recvpacket,sizeof(recvpacket),0,(struct sockaddr *)&from,(socklen_t *)&fromlen); 104 | if(n < 1) { 105 | break; 106 | } 107 | 108 | iph=(struct ip *)recvpacket; 109 | 110 | icmp=(struct icmp *)(recvpacket +(iph->ip_hl<<2)); 111 | 112 | printf("ip:%s\ticmp_type:%d\ticmp_id:%d\n",ips,icmp->icmp_type,icmp->icmp_id); 113 | if(icmp->icmp_type==ICMP_ECHOREPLY && icmp->icmp_id==pid) 114 | break; 115 | else 116 | continue; 117 | } 118 | } 119 | 120 | int main(){ 121 | char cPing[16]; 122 | printf("please input ping ip:"); 123 | scanf("%s",cPing); 124 | if(ping(cPing,10000)) 125 | printf("ping succeed!\n"); 126 | else 127 | printf("ping wrong!\n"); 128 | } 129 | 130 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp03/rawsniffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc,char **argv){ 10 | int sock,n; 11 | char buffer[2048]; 12 | unsigned char *iphead,*ethhead; 13 | if((sock=socket(PF_PACKET,SOCK_RAW,htons(ETH_P_IP)))<0){ 14 | perror("socket"); 15 | return 1; 16 | } 17 | while(1){ 18 | n = recvfrom(sock,buffer,2048,0,NULL,NULL); 19 | if(n<42){ 20 | perror("recvfrom():"); 21 | printf("Incomplete packet(errno is %d)\n", 22 | errno); 23 | close(sock); 24 | return 0; 25 | } 26 | 27 | iphead = buffer+14; /* Skip Ethernet header */ 28 | if(*iphead==0x45){ /* Double check for IPv4 29 | * and no options present */ 30 | if(iphead[9]==6 && ( 31 | (iphead[20]<<8)+iphead[21]==21 || 32 | (iphead[22]<<8)+iphead[23]==21) 33 | ){ 34 | printf("%d bytes read\n",n); 35 | printf("-----\n"); 36 | /* 37 | ethhead = buffer; 38 | printf("Source MAC address: " 39 | "%02x:%02x:%02x:%02x:%02x:%02x\n", 40 | ethhead[0],ethhead[1],ethhead[2], 41 | ethhead[3],ethhead[4],ethhead[5]); 42 | printf("Destination MAC address: " 43 | "%02x:%02x:%02x:%02x:%02x:%02x\n", 44 | ethhead[6],ethhead[7],ethhead[8], 45 | ethhead[9],ethhead[10],ethhead[11]); 46 | */ 47 | iphead = buffer+14; /* Skip Ethernet header */ 48 | printf("Source host %d.%d.%d.%d\n", 49 | iphead[12],iphead[13], 50 | iphead[14],iphead[15]); 51 | printf("Dest host %d.%d.%d.%d\n", 52 | iphead[16],iphead[17], 53 | iphead[18],iphead[19]); 54 | printf("Source,Dest ports %d,%d\n", 55 | (iphead[20]<<8)+iphead[21], 56 | (iphead[22]<<8)+iphead[23]); 57 | printf("Layer-4 protocol %d\n",iphead[9]); 58 | //*(buffer+n)=0; 59 | switch(iphead[9]){ 60 | case 6://tcp 61 | printf("TCP protocol,data:\n%s",buffer+14+20+20); 62 | break; 63 | case 17://udp 64 | printf("UDP protocol,data:\n%s",buffer+14+20+8); 65 | break; 66 | } 67 | printf("-----\n"); 68 | } 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp03/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp03/实验报告.doc -------------------------------------------------------------------------------- /ComputerNetwork/Exp03/网络编程实验.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp03/网络编程实验.doc -------------------------------------------------------------------------------- /ComputerNetwork/Exp04/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp04/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp04/a.out -------------------------------------------------------------------------------- /ComputerNetwork/Exp04/select.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //#include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define PORT 8000 10 | 11 | int prierr(char *msg){ 12 | printf("%s\n",msg); 13 | exit(1); 14 | return 0; 15 | } 16 | 17 | int main(int argc,char **argv) 18 | { 19 | int listenfd,connfd,udpfd,nready; 20 | char msg[2000]; 21 | pid_t childpid; 22 | fd_set rset; 23 | int rcvlen; 24 | socklen_t len; 25 | const int on=1; 26 | struct sockaddr_in cliaddr,servaddr; 27 | 28 | if((listenfd=socket(AF_INET,SOCK_STREAM,0))==-1) 29 | prierr("tcp socket error"); 30 | 31 | bzero(&servaddr,sizeof(servaddr)); 32 | servaddr.sin_family=AF_INET; 33 | servaddr.sin_addr.s_addr=htonl(INADDR_ANY); 34 | servaddr.sin_port=htons(PORT); 35 | 36 | setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)); 37 | if(bind(listenfd,(struct sockaddr*)&servaddr,sizeof(servaddr))==-1) 38 | prierr("tcp bind error"); 39 | 40 | listen(listenfd,10); 41 | 42 | if((udpfd=socket(AF_INET,SOCK_DGRAM,0))==-1) 43 | prierr("upd socket error"); 44 | 45 | bzero(&servaddr,sizeof(servaddr)); 46 | servaddr.sin_family =AF_INET; 47 | servaddr.sin_addr.s_addr=htonl(INADDR_ANY); 48 | servaddr.sin_port =htons(PORT); 49 | 50 | if(bind(udpfd,(struct sockaddr*) &servaddr,sizeof(servaddr))==-1) 51 | prierr("udp bind error"); 52 | 53 | 54 | FD_ZERO(&rset); 55 | while(1){ 56 | FD_SET(listenfd,&rset); 57 | FD_SET(udpfd,&rset); 58 | if((nready=select((listenfd>udpfd)?listenfd+1:udpfd+1 59 | ,&rset,NULL,NULL,NULL)) < 0){ 60 | } 61 | 62 | if(FD_ISSET(listenfd,&rset)){ 63 | len=sizeof(cliaddr); 64 | if((connfd=accept(listenfd,(struct sockaddr*) &cliaddr,&len))==-1) 65 | prierr("accept error"); 66 | 67 | if((childpid=fork())==0){ 68 | close(listenfd); 69 | if((rcvlen=recv(connfd,msg,sizeof(msg),0))==-1) 70 | prierr("recv error"); 71 | printf("tcp recv:%s\n",msg); 72 | send(connfd,msg,rcvlen,0); 73 | printf("tcp send:%s\n",msg); 74 | exit(0); 75 | } 76 | close(connfd); 77 | } 78 | 79 | if(FD_ISSET(udpfd,&rset)){ 80 | len=sizeof(cliaddr); 81 | if((rcvlen=recvfrom(udpfd,msg,sizeof(msg),0,(struct sockaddr*) &cliaddr,&len))==-1) 82 | prierr("recvfrom error"); 83 | printf("udp recv:%s\n",msg); 84 | sendto(udpfd,msg,rcvlen,0,(struct sockaddr*) &cliaddr,len); 85 | printf("udp send:%s\n",msg); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /ComputerNetwork/Exp04/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp04/实验报告.doc -------------------------------------------------------------------------------- /ComputerNetwork/Exp04/网络编程实验.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/Exp04/网络编程实验.doc -------------------------------------------------------------------------------- /ComputerNetwork/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ComputerNetwork/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/实验报告.doc -------------------------------------------------------------------------------- /ComputerNetwork/实验报告.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ComputerNetwork/实验报告.pdf -------------------------------------------------------------------------------- /ComputerNetwork/说明.txt: -------------------------------------------------------------------------------- 1 | 说明: 2 | 根目录下有实验总报告 3 | 每个分目录下有每次的实验报告 4 | 每个分目录下有每次的实验题目 5 | 所有程序均在Linux下可以正常运行 6 | 程序已经用GCC编译好,若程序版本出错,请参考实验报告重新编译即可 7 | 实验环境: 8 | 联系方式: 9 | 学号 150120526 10 | 姓名 殷悦 11 | 班级 1504201 12 | 电话 17863137381 13 | -------------------------------------------------------------------------------- /Cryptography/150120526_殷悦.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/Cryptography/150120526_殷悦.zip -------------------------------------------------------------------------------- /Cryptography/DES.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //#include 4 | //#include 5 | #include 6 | 7 | 8 | static unsigned char ip[64]={//Initial permutation IP 9 | 58, 50, 42, 34, 26, 18, 10, 2, 10 | 60, 52, 44, 36, 28, 20, 12, 4, 11 | 62, 54, 46, 38, 30, 22, 14, 6, 12 | 64, 56, 48, 40, 32, 24, 16, 8, 13 | 57, 49, 41, 33, 25, 17, 9, 1, 14 | 59, 51, 43, 35, 27, 19, 11, 3, 15 | 61, 53, 45, 37, 29, 21, 13, 5, 16 | 63, 55, 47, 39, 31, 23, 15, 7 17 | }; 18 | 19 | static unsigned char ip1[64]={// initial replacement IP reverse IP-1 20 | 40, 8, 48, 16, 56, 24, 64, 32, 21 | 39, 7, 47, 15, 55, 23, 63, 31, 22 | 38, 6, 46, 14, 54, 22, 62, 30, 23 | 37, 5, 45, 13, 53, 21, 61, 29, 24 | 36, 4, 44, 12, 52, 20, 60, 28, 25 | 35, 3, 43, 11, 51, 19, 59, 27, 26 | 34, 2, 42, 10, 50, 18, 58, 26, 27 | 33, 1, 41, 9, 49, 17, 57, 25 28 | }; 29 | 30 | static unsigned char pc1[56]={// key replacement 1 31 | 57, 49, 41, 33, 25, 17, 9, 32 | 1, 58, 50, 42, 34, 26, 18, 33 | 10, 2, 59, 51, 43, 35, 27, 34 | 19, 11, 3, 60, 52, 44, 36, 35 | 63, 55, 47, 39, 31, 23, 15, 36 | 7, 62, 54, 46, 38, 30, 22, 37 | 14, 6, 61, 53, 45, 37, 29, 38 | 21, 13, 5, 28, 20, 12, 4 39 | }; 40 | 41 | static unsigned char pc2[48]={// key replacement 2 42 | 14, 17, 11, 24, 1, 5, 43 | 3, 28, 15, 6, 21, 10, 44 | 23, 19, 12, 4, 26, 8, 45 | 16, 7, 27, 20, 13, 2, 46 | 41, 52, 31, 37, 47, 55, 47 | 30, 40, 51, 45, 33, 48, 48 | 44, 49, 39, 56, 34, 53, 49 | 46, 42, 50, 36, 29, 32 50 | }; 51 | 52 | static unsigned char e[48]={// Extended replacement E 53 | 32, 1, 2, 3, 4, 5, 54 | 4, 5, 6, 7, 8, 9, 55 | 8, 9, 10, 11, 12, 13, 56 | 12, 13, 14, 15, 16, 17, 57 | 16, 17, 18, 19, 20, 21, 58 | 20, 21, 22, 23, 24, 25, 59 | 24, 25, 26, 27, 28, 29, 60 | 28, 29, 30, 31, 32, 1 61 | }; 62 | 63 | static unsigned char lcircle[16]={// the number of rounds to be rounded 64 | 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 65 | }; 66 | 67 | static unsigned char s[8][4][16]={// S table 68 | // S1 69 | 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 70 | 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 71 | 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 72 | 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, 73 | // S2 74 | 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 75 | 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 76 | 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 77 | 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, 78 | // S3 79 | 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 80 | 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 81 | 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 82 | 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, 83 | // S4 84 | 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 85 | 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 86 | 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 87 | 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, 88 | // S5 89 | 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 90 | 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 91 | 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 92 | 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, 93 | // S6 94 | 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 95 | 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 96 | 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 97 | 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, 98 | // S7 99 | 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 100 | 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 101 | 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 102 | 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, 103 | // S8 104 | 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 105 | 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 106 | 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 107 | 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 108 | }; 109 | 110 | static unsigned char P[32]={// replace P 111 | 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 112 | 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 113 | }; 114 | 115 | #define max 100 116 | unsigned char firstkey[32];//password 117 | unsigned char random_key[64];// Random sequence for CBC encryption 118 | unsigned char r_key[64]; // random sequence 119 | unsigned char temp_key[64]; // temporary key store 120 | unsigned char mw[8]; // Random sequence for CBC encryption 121 | unsigned char m[64]; // plaintext / ciphertext array 122 | unsigned char charkey[8]; // char type key 123 | unsigned char ejzkey[64]; // binary key 124 | unsigned char ER[48];// 32 bits extended by 32 bits later 125 | unsigned char dmw[8]={0}; // encoded plaintext / ciphertext 126 | unsigned char lskey[56]; // temporary storage key 127 | unsigned char childkey[16][56]; // 16 subkeys 128 | 129 | FILE* fptr=NULL, *dfptr; 130 | int size; 131 | int mode_cbc; 132 | unsigned char* L, *R; 133 | 134 | void Thekey(unsigned char* firstkey, unsigned char* bkey); // generate a 64-bit key based on the password 135 | void encode(); // encryption 136 | void decode(); // decryption 137 | void getbit(unsigned char* m, unsigned char* mw);//// char to binary 138 | void replace(unsigned char* a, unsigned char* b, int n);// replace function 139 | void circle(unsigned char* key, int n); // left shift function 140 | void yihuo(unsigned char* a, unsigned char* b, int n);// exclusive OR function 141 | void S_box(unsigned char* a);// S box 142 | void getchars(unsigned char* a, unsigned char* mw); //binary to char 143 | int add(unsigned char* a); //summation function 144 | void getdkey(unsigned char* key);//produces 16 subkeys 145 | void enrepeat();// encryption loop 146 | void derepeat();// decrypt the loop 147 | void getbmphead(FILE* fptr, FILE* dfptr);// read the BMP header 148 | void randomkey(unsigned char* random_key); // Generates a 64-bit random sequence 149 | 150 | 151 | 152 | void Thekey(unsigned char* firstkey, unsigned char* bkey)// generate a key greater than 64 bits, less than completion 153 | { 154 | int i, j=0; 155 | 156 | for(i=0;i<8;i++) 157 | { 158 | if(firstkey[j]=='\n') 159 | { 160 | j=0; 161 | i--; 162 | } 163 | else 164 | { 165 | bkey[i]=firstkey[j]; 166 | j++; 167 | } 168 | } 169 | return ; 170 | }; 171 | 172 | void encode() // encryption 173 | { 174 | int i, n, j=0; 175 | 176 | while(ftell(fptr)=0;j--) 439 | { 440 | a[i*4+j]=c[i]%2; 441 | c[i]/=2; 442 | } 443 | } 444 | return; 445 | }; 446 | 447 | void getchars(unsigned char* a, unsigned char* dmw) 448 | { 449 | int i; 450 | for(i=0;i<8;i++) 451 | dmw[i]=add(&a[i*8]);//binary conversion to decimal char 452 | return; 453 | } ; 454 | 455 | int add(unsigned char* a) 456 | { 457 | return a[0]*128+a[1]*64+a[2]*32+a[3]*16+a[4]*8+a[5]*4+a[6]*2+a[7]; 458 | } ; 459 | 460 | void getbmphead(FILE* fptr, FILE* dfptr) 461 | { 462 | int i; 463 | char c; 464 | 465 | for(i=0;i<55;i++) 466 | { 467 | c=fgetc(fptr); 468 | fputc(c, dfptr); 469 | } 470 | return ; 471 | } ; 472 | 473 | void randomkey(unsigned char* random_key) 474 | { 475 | int i; 476 | 477 | srand(time(0)); 478 | for(i=0;i<64;i++) 479 | random_key[i]=rand()%2; 480 | return; 481 | } ; 482 | 483 | int main() 484 | { 485 | int i, n; 486 | char filename[256]={'p','a','s','s','w','d','.','b','m','p',0}, c; 487 | int function,ret; 488 | 489 | printf("Please choose the function:\n"); 490 | printf("1.picture encrypt\t2.login\n"); 491 | scanf("%d",&function); 492 | getchar(); 493 | function--; 494 | if(function) 495 | { 496 | printf("1.Login\t2.Set password\n"); 497 | ret=scanf("%d",&function); 498 | //if(ret!=2)fflush(stdin); 499 | getchar(); 500 | }else 501 | { 502 | for(i=0;i<256;i++) 503 | filename[i]=0; 504 | printf("please type the picture name that you want to encrypt:\n"); 505 | gets(filename); 506 | 507 | } 508 | fptr=fopen(filename, "rb"); 509 | if(fptr==NULL) 510 | { 511 | printf("Cant open the file\n"); 512 | return 0; 513 | } 514 | fseek(fptr,0,SEEK_END); 515 | size=ftell(fptr); 516 | rewind(fptr); 517 | 518 | randomkey(random_key); 519 | 520 | 521 | printf("please type the password\n"); 522 | i=0; 523 | firstkey[i]=getchar(); 524 | while(firstkey[i]!='\n') 525 | { 526 | i++; 527 | firstkey[i]=getchar(); 528 | } 529 | if(firstkey[0]=='\n') 530 | { 531 | printf("illegal password"); 532 | return 0; 533 | } 534 | Thekey(firstkey, charkey); 535 | 536 | getbit(ejzkey, charkey);//convert the key to binary 537 | 538 | replace(ejzkey, pc1, n=56); //key is replaced by 56 bits 539 | 540 | getdkey(ejzkey); // get 16 subkeys 541 | if(function==0){ 542 | printf("Choose the encrypt mode:\t0.EBC\t1.CBC\n"); 543 | scanf("%d",&mode_cbc); 544 | } 545 | else 546 | mode_cbc=1; 547 | if(function==0 || function==2) 548 | { 549 | 550 | if(mode_cbc!=0 && mode_cbc!=1) 551 | { 552 | printf("illegal choice\n"); 553 | } 554 | printf("encrypting...\n"); 555 | dfptr=fopen("encipher.bmp", "wb+"); 556 | getbmphead(fptr, dfptr); // read the file header 557 | encode(); //encryption 558 | printf("Finish.The new file is encipher.bmp\n"); 559 | fclose(fptr); 560 | fclose(dfptr); 561 | } 562 | if(function==0 || function==1) 563 | { 564 | printf("decryteing...\n"); 565 | fptr=fopen("encipher.bmp", "rb"); 566 | dfptr=fopen("cipher.bmp", "wb+"); 567 | if(fptr==NULL || dfptr==NULL){ 568 | printf("Fail to open the file\n"); 569 | } 570 | getbmphead(fptr, dfptr); 571 | decode(); //decrypt 572 | printf("Finish.The new file is cipher.bmp\n"); 573 | //fclose(fptr); 574 | 575 | printf("Login successfully\n"); 576 | if(function==1){ 577 | fptr=fopen("password","rb"); 578 | dfptr=fopen("cipher.bmp","rb"); 579 | char cmp,cmp2; 580 | do{ 581 | printf("123\n"); 582 | cmp=fgetc(fptr); 583 | cmp2=fgetc(dfptr); 584 | printf("\n1"); 585 | if(cmp!=cmp2){ 586 | printf("Fail to login,please check the password and try again\n"); 587 | break; 588 | 589 | } 590 | }while(cmp!=EOF||cmp2!=EOF); 591 | if(cmp==cmp2) 592 | printf("Login successfully\n"); 593 | fclose(fptr); 594 | fclose(dfptr); 595 | 596 | } 597 | } 598 | 599 | 600 | 601 | 602 | 603 | return 0; 604 | } 605 | 606 | -------------------------------------------------------------------------------- /Cryptography/DES.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/Cryptography/DES.exe -------------------------------------------------------------------------------- /Cryptography/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Cryptography/RSA.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef unsigned long long ull; 6 | 7 | ull gcd(ull a,ull b){ 8 | int t; 9 | while(b){ 10 | t=a; 11 | a=b; 12 | b=t%b; 13 | } 14 | return a; 15 | } 16 | 17 | void generateKey(ull p,ull q,ull* e,ull* d){ 18 | 19 | //generatePubKey 20 | int r; 21 | (*e)=2; 22 | r=(p-1)*(q-1); 23 | 24 | (*e)=65537; 25 | while((*e)<1||(*e)>r||gcd((*e),r)!=1){ 26 | (*e)++; 27 | if((*e)==-1){ 28 | printf("error,can't find e,overflow\n"); 29 | return; 30 | } 31 | } 32 | printf("e:%llu",*e); 33 | 34 | //generateSecKey 35 | *d=1; 36 | while((*e)*(*d)%r!=1){ 37 | *d=rand()%r; 38 | //(*d)++; 39 | //printf("d:%llu",*d); 40 | if((*d)==-1){ 41 | printf("error,can't find b,overflow\n"); 42 | return; 43 | } 44 | } 45 | printf("d:%llu",*d); 46 | } 47 | /* 48 | ull MulMod(ull a,ull b,ull mod){ 49 | int num1[64],num2[64],res[128]; 50 | int opr1,opr2,i; 51 | ull o1,o2; 52 | for(opr1=0,opr2=0;opr1<64;opr1++){ 53 | num1[opr1]=0; 54 | num2[opr1]=0; 55 | res[opr2++]=0; 56 | res[opr2+0 57 | o1=1;o2=1; 58 | for(opr1=0;opr1<64;opr1++){ 59 | num1[opr1]=(a&o1)?1:0; 60 | o1<<=1; 61 | } 62 | for(opr2=0;opr2<64;opr2++){ 63 | num2[opr2]=(a&o2)?1:0; 64 | o2<<=1; 65 | } 66 | for(opr1=0;opr1<64;opr1++){ 67 | for(opr2=0;opr2<64;opr2++){ 68 | if(num1[opr1]&num2[opr2]) 69 | res[opr1+opr2-1]++; 70 | } 71 | for(i=0;i<128;i++){ 72 | if(res[i]>1){ 73 | res[i]=0;res[i+1]++; 74 | } 75 | } 76 | } 77 | 78 | o2=1; 79 | for(i=0;i<64;i++){ 80 | if(res[i]) 81 | o1+=o2; 82 | o2<<=1; 83 | } 84 | return o1; 85 | } 86 | */ 87 | /* 88 | ull powAndMod(ull x,ull m,ull mod){ 89 | ull y; 90 | y=1; 91 | while(m!=0){ 92 | if(m%2==1){ 93 | y=(x*y)%mod; 94 | m--; 95 | }else{ 96 | x=(x*x)%mod; 97 | m/=2; 98 | } 99 | } 100 | return y; 101 | } 102 | */ 103 | ull quickMod(ull a,ull b,ull mod){ 104 | //a^10%c=a^(1*2^3+0*2^2+1*2^1+0*2^0)%c=((a^(2^3)%c)*(a^(2^1)%c))%c 105 | ull aus=1; 106 | while(b){ 107 | if(b&0x1) 108 | aus=aus*a%mod; 109 | a=a*a%mod; 110 | b>>=1; 111 | } 112 | return aus; 113 | } 114 | 115 | int fermatPrime(ull num){ 116 | //a^(n-1)=1(mod n) 117 | int i; 118 | for(i=0;i<5;i++) 119 | if(quickMod(1+rand()%(num-1),num-1,num)!=1) 120 | break; 121 | if(i==5)return 1; 122 | return 0; 123 | } 124 | 125 | void generateBigPrime(ull* p,ull* q){ 126 | int i; 127 | ull temp; 128 | srand((unsigned)time(NULL)); 129 | do{ 130 | *p=0; 131 | for(i=0;i<1;i++){ 132 | temp=rand()%65535; 133 | temp<<=16*i; 134 | *p|=temp; 135 | } 136 | // printf("p:%llu\tq:%llu\n",*p,*q); 137 | }while(!fermatPrime(*p)); 138 | 139 | do{ 140 | *q=0; 141 | for(i=0;i<1;i++){ 142 | temp=rand()%65535; 143 | temp<<=16*i; 144 | *q|=temp; 145 | } 146 | }while(p==q||!fermatPrime(*q)); 147 | printf("p:%llu\tq:%llu\n",*p,*q); 148 | } 149 | 150 | void enc(char plaintext[],ull ciphertext[],ull n,ull e){ 151 | int i; 152 | for(i=0;plaintext[i]!=0;i++){ 153 | ciphertext[i]=quickMod((ull)plaintext[i],e,n); 154 | printf("%c",plaintext[i]); 155 | } 156 | ciphertext[i]=0; 157 | } 158 | void dec(ull ciphertext[],char plaintext[],ull n,ull d){ 159 | int i; 160 | for(i=0;ciphertext[i]!=0;i++) 161 | plaintext[i]=(char)quickMod(ciphertext[i],d,n); 162 | ciphertext[i]=0; 163 | } 164 | void printfx(ull ciphertext[]){ 165 | int i; 166 | for(i=0;ciphertext[i]!=0;i++){ 167 | printf("%llu\t",ciphertext[i]); 168 | } 169 | printf("\n"); 170 | } 171 | 172 | int main(){ 173 | /* prime p q 174 | * n=p*q r=(p-1)(q-1) 175 | * e 1 Then 9 | Response.write "Faild to connect Sql!" 10 | Response.End 11 | End If 12 | %> 13 | -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/create.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE account 2 | ( 3 | username varchar(20) NOT NULL , 4 | password varchar(20) NOT NULL 5 | ); 6 | 7 | CREATE TABLE buy 8 | ( 9 | ONum int NOT NULL , 10 | BCount int NULL , 11 | BName varchar(20) NOT NULL 12 | ); 13 | 14 | CREATE TABLE goods 15 | ( 16 | GName varchar(20) NOT NULL , 17 | GPrice float NULL , 18 | GCount int NULL 19 | ); 20 | 21 | CREATE TABLE orders 22 | ( 23 | ONum int NOT NULL , 24 | OTime datetime NULL , 25 | username varchar(20) NOT NULL , 26 | consignee varchar(20) NULL , 27 | location varchar(50) NULL , 28 | zipcode varchar(20) NULL , 29 | tel varchar(20) NULL , 30 | cfm int NOT NULL 31 | ); -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/goods.asp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Goods information 5 | 6 | 7 | 8 |

Username:<%Response.write Session("username")%> 9 |

10 |

Goods information

11 |
12 |

Add goods

13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 |
Goods name:
Price:
Count:
  30 | 31 | 32 |
35 |
36 |

Goods list

37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | <% 45 | strSql="select GName,GPrice,GCount from goods" 46 | Set rs=server.CreateObject("adodb.recordset") 47 | rs.open strSql,conn,1,1 48 | If Not rs.eof And Not rs.bof Then 49 | Do While Not rs.eof 50 | %> 51 | 52 | 53 | 54 | 55 | 59 | 60 | <% 61 | rs.movenext 62 | Loop 63 | End If 64 | rs.close 65 | %> 66 |
NamePriceCountOperate
<%=rs("GName")%><%=rs("GPrice")%><%=rs("GCount")%> 56 | ">Buy 57 | ">Delete 58 |
67 | 68 | -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/index.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp01/index.htm -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/login.asp: -------------------------------------------------------------------------------- 1 | 2 | <% 3 | Dim username,password 4 | Dim conn,rs 5 | username=Trim(Request("username")) 6 | password=Trim(Request("password")) 7 | If username <> "" and password <>"" Then 8 | 9 | strSql="select * from account where username='"&username&"' and password='"&password&"'" 10 | Set rs=server.CreateObject("adodb.recordset") 11 | rs.open strSql,conn,1,1 12 | If rs.eof Or rs.bof Then 13 | Response.write "" 14 | Response.end 15 | End If 16 | rs.close 17 | Session("username")=username 18 | Response.Redirect("goods.asp") 19 | Response.End 20 | Else 21 | Response.write "" 22 | End If 23 | %> -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/opr.asp: -------------------------------------------------------------------------------- 1 | 2 | <% 3 | Dim Name,GPrice,GCount,submit 4 | submit=Trim(Request("submit")) 5 | If submit="Add" Then 6 | GName=Trim(Request("GName")) 7 | GPrice=Trim(Request("GPrice")) 8 | GCount=Trim(Request("GCount")) 9 | Response.write GName&GPrice&GCount 10 | If GName <> "" and GPrice <> "" and GCount <> "" Then 11 | strSql="select * from goods where GName='"&GName&"'" 12 | Set rs=server.CreateObject("adodb.recordset") 13 | rs.open strSql,conn,1,1 14 | If rs.eof Or rs.bof Then 15 | strSql="insert Into goods(GName,GPrice,GCount) Values ('"&GName&"','"&GPrice&"','"&GCount&"')" 16 | Set rs=server.CreateObject("adodb.recordset") 17 | rs.open strSql,conn,1,1 18 | Response.write "" 19 | Response.End 20 | Else 21 | Response.write "" 22 | Response.End 23 | End If 24 | Response.End 25 | Else 26 | Response.write "" 27 | End If 28 | ElseIf submit="Buy" Then 29 | GName=Trim(Request("GName")) 30 | strSql="update goods set GCount=GCount-1 where GName='"&GName&"'" 31 | Set rs=server.CreateObject("adodb.recordset") 32 | rs.open strSql,conn,1,1 33 | Response.write "" 34 | ElseIf submit="Delete" Then 35 | GName=Trim(Request("GName")) 36 | strSql="delete from goods where GName='"&GName&"'" 37 | Set rs=server.CreateObject("adodb.recordset") 38 | rs.open strSql,conn,1,1 39 | Response.write "" 40 | End If 41 | %> -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/reg.asp: -------------------------------------------------------------------------------- 1 | 2 | <% 3 | Dim username,password 4 | Dim conn,rs 5 | username=Trim(Request("username")) 6 | password=Trim(Request("password")) 7 | confirm=Trim(Request("confirm")) 8 | If username <> "" and password <> "" Then 9 | If password <> confirm Then 10 | Response.write "" 11 | End if 12 | strSql="select * from account where username='"&username&"'" 13 | Set rs=server.CreateObject("adodb.recordset") 14 | rs.open strSql,conn,1,1 15 | If rs.eof Or rs.bof Then 16 | strSql="insert Into account(username,password) Values ('"&username&"','"&password&"')" 17 | 'Set rs=server.CreateObject("adodb.recordset") 18 | 'rs.open strSql,conn,1,1 19 | Set rs=conn.execute(strSql) 20 | Response.write "" 21 | Response.End 22 | Else 23 | Response.write "" 24 | Response.End 25 | End If 26 | Response.End 27 | rs.close 28 | Else 29 | Response.write "" 30 | End If 31 | %> -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/reg.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp01/reg.htm -------------------------------------------------------------------------------- /ElectronicCommerce/Exp01/电子商务与安全实验报告(实验一).doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp01/电子商务与安全实验报告(实验一).doc -------------------------------------------------------------------------------- /ElectronicCommerce/Exp02/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ElectronicCommerce/Exp02/RSA: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp02/RSA -------------------------------------------------------------------------------- /ElectronicCommerce/Exp02/RSA.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef unsigned long long ull; 6 | 7 | ull gcd(ull a,ull b){ 8 | int t; 9 | while(b){ 10 | t=a; 11 | a=b; 12 | b=t%b; 13 | } 14 | return a; 15 | } 16 | 17 | void generateKey(ull p,ull q,ull* e,ull* d){ 18 | 19 | //generatePubKey 20 | int r; 21 | (*e)=2; 22 | r=(p-1)*(q-1); 23 | 24 | (*e)=65537; 25 | while((*e)<1||(*e)>r||gcd((*e),r)!=1){ 26 | (*e)++; 27 | if((*e)==-1){ 28 | printf("error,can't find e,overflow\n"); 29 | return; 30 | } 31 | } 32 | printf("e:%llu",*e); 33 | 34 | //generateSecKey 35 | *d=1; 36 | while((*e)*(*d)%r!=1){ 37 | *d=rand()%r; 38 | //(*d)++; 39 | //printf("d:%llu",*d); 40 | if((*d)==-1){ 41 | printf("error,can't find b,overflow\n"); 42 | return; 43 | } 44 | } 45 | printf("d:%llu",*d); 46 | } 47 | /* 48 | ull MulMod(ull a,ull b,ull mod){ 49 | int num1[64],num2[64],res[128]; 50 | int opr1,opr2,i; 51 | ull o1,o2; 52 | for(opr1=0,opr2=0;opr1<64;opr1++){ 53 | num1[opr1]=0; 54 | num2[opr1]=0; 55 | res[opr2++]=0; 56 | res[opr2+0 57 | o1=1;o2=1; 58 | for(opr1=0;opr1<64;opr1++){ 59 | num1[opr1]=(a&o1)?1:0; 60 | o1<<=1; 61 | } 62 | for(opr2=0;opr2<64;opr2++){ 63 | num2[opr2]=(a&o2)?1:0; 64 | o2<<=1; 65 | } 66 | for(opr1=0;opr1<64;opr1++){ 67 | for(opr2=0;opr2<64;opr2++){ 68 | if(num1[opr1]&num2[opr2]) 69 | res[opr1+opr2-1]++; 70 | } 71 | for(i=0;i<128;i++){ 72 | if(res[i]>1){ 73 | res[i]=0;res[i+1]++; 74 | } 75 | } 76 | } 77 | 78 | o2=1; 79 | for(i=0;i<64;i++){ 80 | if(res[i]) 81 | o1+=o2; 82 | o2<<=1; 83 | } 84 | return o1; 85 | } 86 | */ 87 | /* 88 | ull powAndMod(ull x,ull m,ull mod){ 89 | ull y; 90 | y=1; 91 | while(m!=0){ 92 | if(m%2==1){ 93 | y=(x*y)%mod; 94 | m--; 95 | }else{ 96 | x=(x*x)%mod; 97 | m/=2; 98 | } 99 | } 100 | return y; 101 | } 102 | */ 103 | ull quickMod(ull a,ull b,ull mod){ 104 | //a^10%c=a^(1*2^3+0*2^2+1*2^1+0*2^0)%c=((a^(2^3)%c)*(a^(2^1)%c))%c 105 | ull aus=1; 106 | while(b){ 107 | if(b&0x1) 108 | aus=aus*a%mod; 109 | a=a*a%mod; 110 | b>>=1; 111 | } 112 | return aus; 113 | } 114 | 115 | int fermatPrime(ull num){ 116 | //a^(n-1)=1(mod n) 117 | int i; 118 | for(i=0;i<5;i++) 119 | if(quickMod(1+rand()%(num-1),num-1,num)!=1) 120 | break; 121 | if(i==5)return 1; 122 | return 0; 123 | } 124 | 125 | void generateBigPrime(ull* p,ull* q){ 126 | int i; 127 | ull temp; 128 | srand((unsigned)time(NULL)); 129 | do{ 130 | *p=0; 131 | for(i=0;i<1;i++){ 132 | temp=rand()%20000; 133 | temp<<=16*i; 134 | *p|=temp; 135 | } 136 | // printf("p:%llu\tq:%llu\n",*p,*q); 137 | }while(!fermatPrime(*p)); 138 | 139 | do{ 140 | *q=0; 141 | for(i=0;i<1;i++){ 142 | temp=rand()%20000; 143 | temp<<=16*i; 144 | *q|=temp; 145 | } 146 | }while(p==q||!fermatPrime(*q)); 147 | printf("p:%llu\tq:%llu\n",*p,*q); 148 | } 149 | 150 | void enc(char plaintext[],ull ciphertext[],ull n,ull e){ 151 | int i; 152 | for(i=0;plaintext[i]!=0;i++){ 153 | ciphertext[i]=quickMod((ull)plaintext[i],e,n); 154 | printf("%c",plaintext[i]); 155 | } 156 | ciphertext[i]=0; 157 | } 158 | void dec(ull ciphertext[],char plaintext[],ull n,ull d){ 159 | int i; 160 | for(i=0;ciphertext[i]!=0;i++) 161 | plaintext[i]=(char)quickMod(ciphertext[i],d,n); 162 | ciphertext[i]=0; 163 | } 164 | void printfx(ull ciphertext[]){ 165 | int i; 166 | for(i=0;ciphertext[i]!=0;i++){ 167 | printf("%llu\t",ciphertext[i]); 168 | } 169 | printf("\n"); 170 | } 171 | 172 | int main(){ 173 | /* prime p q 174 | * n=p*q r=(p-1)(q-1) 175 | * e 1 Then 9 | Response.write "Faild to connect Sql!" 10 | Response.End 11 | End If 12 | %> 13 | -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/create.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE account 2 | ( 3 | username varchar(20) NOT NULL , 4 | password varchar(20) NOT NULL 5 | ); 6 | 7 | CREATE TABLE buy 8 | ( 9 | ONum int NOT NULL , 10 | BCount int NULL , 11 | BName varchar(20) NOT NULL 12 | ); 13 | 14 | CREATE TABLE goods 15 | ( 16 | GName varchar(20) NOT NULL , 17 | GPrice float NULL , 18 | GCount int NULL 19 | ); 20 | 21 | CREATE TABLE orders 22 | ( 23 | ONum int NOT NULL , 24 | OTime datetime NULL , 25 | username varchar(20) NOT NULL , 26 | consignee varchar(20) NULL , 27 | location varchar(50) NULL , 28 | zipcode varchar(20) NULL , 29 | tel varchar(20) NULL , 30 | cfm int NOT NULL 31 | ); -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/index.asp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp03/index.asp -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/opr.asp: -------------------------------------------------------------------------------- 1 | 2 | <% 3 | Dim Name,GPrice,GCount,submit 4 | Set conn=Server.createobject("adodb.connection") 5 | submit=Trim(Request("submit")) 6 | If submit="Add" Then 7 | GName=Trim(Request("GName")) 8 | GPrice=Trim(Request("GPrice")) 9 | GCount=Trim(Request("GCount")) 10 | Response.write GName&GPrice&GCount 11 | If GName <> "" and GPrice <> "" and GCount <> "" Then 12 | strSql="select * from goods where GName='"&GName&"'" 13 | Set rs=server.CreateObject("adodb.recordset") 14 | rs.open strSql,conn,1,1 15 | If rs.eof Or rs.bof Then 16 | strSql="insert Into goods(GName,GPrice,GCount) Value ('"&GName&"','"&GPrice&"','"&GCount&"')" 17 | Set rs=server.CreateObject("adodb.recordset") 18 | rs.open strSql,conn,1,1 19 | Response.write "" 20 | Response.End 21 | Else 22 | Response.write "" 23 | Response.End 24 | End If 25 | Response.End 26 | Else 27 | Response.write "" 28 | End If 29 | ElseIf submit="Buy" Then 30 | GName=Trim(Request("GName")) 31 | strSql="update goods set GCount=GCount-1 where GName='"&GName&"'" 32 | Set rs=server.CreateObject("adodb.recordset") 33 | rs.open strSql,conn,1,1 34 | Response.write "" 35 | ElseIf submit="Delete" Then 36 | GName=Trim(Request("GName")) 37 | strSql="delete from goods where GName='"&GName&"'" 38 | Set rs=server.CreateObject("adodb.recordset") 39 | rs.open strSql,conn,1,1 40 | Response.write "" 41 | End If 42 | %> -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/order.asp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp03/order.asp -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/shoppingCart.asp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp03/shoppingCart.asp -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/test.asp: -------------------------------------------------------------------------------- 1 | <% 2 | Response.write "hello" 3 | set Conn=server.CreateObject("ADODB.CONNECTION") 4 | StrConn="driver={SQL Server};server=qds167524598.my3w.com;uid=qds167524598;pwd=yinyue123;database=qds167524598_db" 5 | Conn.open StrConn 6 | 7 | %> -------------------------------------------------------------------------------- /ElectronicCommerce/Exp03/电子商务与安全实验报告(实验三).doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/Exp03/电子商务与安全实验报告(实验三).doc -------------------------------------------------------------------------------- /ElectronicCommerce/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ElectronicCommerce/电子商务与安全实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/电子商务与安全实验报告.doc -------------------------------------------------------------------------------- /ElectronicCommerce/电子商务与安全实验报告.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/电子商务与安全实验报告.pdf -------------------------------------------------------------------------------- /ElectronicCommerce/说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/ElectronicCommerce/说明.txt -------------------------------------------------------------------------------- /InformationContentSecurity/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /InformationSystemSecurity/150120526_殷悦_实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/150120526_殷悦_实验报告.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/150120526_殷悦_实验报告.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/150120526_殷悦_实验报告.pdf -------------------------------------------------------------------------------- /InformationSystemSecurity/150120526_殷悦_计算机系统安全实验报告.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/150120526_殷悦_计算机系统安全实验报告.zip -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp01/Client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -* 2 | import os 3 | import socket 4 | import hashlib 5 | import tkinter.messagebox 6 | from tkinter import * 7 | from urllib import request,parse,error 8 | 9 | class Login(Frame): 10 | url='http://115.159.155.95/skey.php' 11 | N=0; 12 | def __init__(self, master): 13 | # abc 14 | frame=Frame(master) 15 | frame.pack() 16 | self.lab1=Label(frame,text = "用户:") 17 | self.lab1.grid(row=0,column=0,sticky=W) 18 | self.lab2=Label(frame,text="密码:") 19 | self.lab2.grid(row=1,column=0,sticky=W) 20 | self.lab2=Label(frame,text="验证码:") 21 | self.lab2.grid(row=2,column=0,sticky=W) 22 | self.ent1=Entry(frame) 23 | self.ent1.grid(row=0,column=1,sticky=W) 24 | self.ent2=Entry(frame,show="*") 25 | self.ent2.grid(row=1,column=1,sticky=W) 26 | self.ent3=Entry(frame) 27 | self.ent3.grid(row=2,column=1,sticky=W) 28 | self.button1=Button(frame,text="登录",command=self.Log) 29 | self.button1.grid(row=3,column=0,sticky=W) 30 | self.button2=Button(frame,text="注册",command=self.Reg) 31 | self.button2.grid(row=3,column=1,sticky=W) 32 | self.button3=Button(frame,text="退出",command=frame.quit) 33 | self.button3.grid(row=3,column=1,sticky=E) 34 | def md5n(self,pas,n): 35 | while n>0: 36 | n=n-1 37 | hash=hashlib.md5() 38 | hash.update(pas.encode("utf8")) 39 | pas=hash.hexdigest() 40 | print(pas) 41 | return pas 42 | 43 | def Log(self): 44 | s1=self.ent1.get() 45 | s2=self.ent2.get() 46 | s3=self.ent3.get() 47 | info=[] 48 | info.append(('action','login')) 49 | info.append(('user',s1)) 50 | tkinter.messagebox.showinfo('提示', "消息:接受种子成功") 51 | seed='seedseed' 52 | with open(s1 + '.txt', 'r') as f: 53 | N=eval(f.read()) 54 | f.close() 55 | md5npas = self.md5n(s2, N - 1) 56 | self.ent3.delete(0, len(s3)) 57 | self.ent3.insert(0, md5npas) 58 | info.append(('pass', md5npas)) 59 | print(info) 60 | data = bytes(parse.urlencode(info), encoding='utf8') 61 | print(data) 62 | with request.urlopen(self.url,data=data) as rsp: 63 | msg = rsp.read().decode('utf8') 64 | if msg.find('成功')!=-1: 65 | with open(s1 + '.txt', 'w') as f: 66 | f.write(str(N-1)) 67 | f.close() 68 | tkinter.messagebox.showinfo('提示', "消息:\n%s" % msg) 69 | 70 | def Reg(self): 71 | s1 = self.ent1.get() 72 | s2 = self.ent2.get() 73 | s3 = self.ent3.get() 74 | N=100 75 | info = [] 76 | info.append(('action', 'register')) 77 | info.append(('user', s1)) 78 | md5npas = self.md5n(s2, N) 79 | self.ent3.delete(0, len(s3)) 80 | self.ent3.insert(0, md5npas) 81 | info.append(('pass', md5npas)) 82 | info.append(('count',N)) 83 | print(info) 84 | data = bytes(parse.urlencode(info), encoding='utf8') 85 | print(data) 86 | with request.urlopen(self.url, data=data) as rsp: 87 | msg = rsp.read().decode('utf8') 88 | print(rsp) 89 | print(msg) 90 | if msg.find('成功')!=-1: 91 | with open(s1 + '.txt', 'w') as f: 92 | f.write(str(N)) 93 | f.close() 94 | 95 | tkinter.messagebox.showinfo('提示', "消息:\n%s" % msg) 96 | s1=self.ent1.get() 97 | s2=self.ent2.get() 98 | 99 | root=Tk() 100 | root.title("登录") 101 | app=Login(root) 102 | root.mainloop() 103 | -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp01/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp01/Server.php: -------------------------------------------------------------------------------- 1 | '; 44 | } 45 | } 46 | ?> 47 | -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp01/ServerSql.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.7.20, for macos10.12 (x86_64) 2 | -- 3 | -- Host: 115.159.155.95 Database: test 4 | -- ------------------------------------------------------ 5 | -- Server version 5.1.73 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `log` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `log`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `log` ( 26 | `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 27 | `record` varchar(45) CHARACTER SET utf8 NOT NULL, 28 | PRIMARY KEY (`time`), 29 | UNIQUE KEY `time_UNIQUE` (`time`) 30 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 31 | /*!40101 SET character_set_client = @saved_cs_client */; 32 | 33 | -- 34 | -- Dumping data for table `log` 35 | -- 36 | 37 | LOCK TABLES `log` WRITE; 38 | /*!40000 ALTER TABLE `log` DISABLE KEYS */; 39 | INSERT INTO `log` VALUES ('2018-04-19 12:27:27','用户yinyue注册成功'),('2018-04-19 12:29:09','用户yinyue登录成功'),('2018-04-19 12:30:34','用户yinyue登录成功'),('2018-04-19 12:31:27','查询日志'); 40 | /*!40000 ALTER TABLE `log` ENABLE KEYS */; 41 | UNLOCK TABLES; 42 | 43 | -- 44 | -- Table structure for table `user` 45 | -- 46 | 47 | DROP TABLE IF EXISTS `user`; 48 | /*!40101 SET @saved_cs_client = @@character_set_client */; 49 | /*!40101 SET character_set_client = utf8 */; 50 | CREATE TABLE `user` ( 51 | `user` varchar(20) NOT NULL, 52 | `pass` varchar(64) NOT NULL, 53 | `count` int(11) NOT NULL, 54 | PRIMARY KEY (`user`), 55 | UNIQUE KEY `user_UNIQUE` (`user`) 56 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 57 | /*!40101 SET character_set_client = @saved_cs_client */; 58 | 59 | -- 60 | -- Dumping data for table `user` 61 | -- 62 | 63 | LOCK TABLES `user` WRITE; 64 | /*!40000 ALTER TABLE `user` DISABLE KEYS */; 65 | INSERT INTO `user` VALUES ('yinyue','07f91a95d0813f28ba4dd824f6be6467',98); 66 | /*!40000 ALTER TABLE `user` ENABLE KEYS */; 67 | UNLOCK TABLES; 68 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 69 | 70 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 71 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 72 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 73 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 74 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 75 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 76 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 77 | 78 | -- Dump completed on 2018-04-20 13:29:32 79 | -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp01/yinyue.txt: -------------------------------------------------------------------------------- 1 | 98 -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦威胁列表.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦威胁列表.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦已有安全措施确认表.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦已有安全措施确认表.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦脆弱性列表.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦脆弱性列表.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦资产识别清单.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦资产识别清单.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦重要资产清单.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦重要资产清单.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦风险处理计划.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦风险处理计划.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦风险评估报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦风险评估报告.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/Exp02/殷悦风险评估方案.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/InformationSystemSecurity/Exp02/殷悦风险评估方案.doc -------------------------------------------------------------------------------- /InformationSystemSecurity/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1PRO_CON.DSW: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/1PRO_CON.DSW -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1PRO_CON.OPT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/1PRO_CON.OPT -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1PRO_CON.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/1PRO_CON.ncb -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1pro_con.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct resource{ 5 | int RID; 6 | char status; //resource status F:free A:allocated 7 | struct pcb *block_list; 8 | struct resource *next; 9 | struct resource *pNext; 10 | }RES; 11 | 12 | typedef struct pcb{ 13 | int id; //process id 14 | char name[20]; 15 | int mem; // 16 | RES *res; //other resource 17 | char status;//process status W:wait R:running B:block 18 | int priority; //priority 19 | // struct pcb father; //generation tree 20 | // struct pcb son; //generation tree 21 | struct pcb *next; 22 | }PCB; 23 | 24 | PCB *ready; 25 | PCB *block; 26 | PCB *run;//only one 27 | PCB *prc; 28 | RES *res; 29 | 30 | void scheduler(){ 31 | PCB *temp; 32 | PCB *superTemp=NULL; 33 | PCB *superLastTemp=NULL; 34 | PCB *lastTemp=NULL; 35 | for(temp=ready;temp;temp=temp->next){ 36 | if(superTemp==NULL || temp->priority > superTemp->priority){ 37 | superTemp=temp; 38 | superLastTemp=lastTemp; 39 | } 40 | lastTemp=temp; 41 | } 42 | if(ready){ 43 | if(run!=NULL && run->priority < superTemp->priority){ 44 | printf("Process %d is deprived of operation rights\n",run->id); 45 | if(superLastTemp==NULL){ 46 | ready=run; 47 | }else{ 48 | superLastTemp->next=superTemp->next; 49 | lastTemp->next=run; //Put the run process to the last position of the quene 50 | } 51 | run->status='W'; 52 | } 53 | run=superTemp; 54 | run->status='R'; 55 | run->next=NULL; 56 | printf("Process %d starts running\n",run->id); 57 | } 58 | 59 | //if(self->priority < p->priority || self->status.type!='R'|| self=nil) 60 | // preempt(p,self); 61 | } 62 | 63 | void request(int pid,int rid){ 64 | PCB *temp; 65 | RES *tempRes; 66 | RES *tempPRes; 67 | 68 | if(run->id!=pid){ 69 | printf("This process is not running\n"); 70 | return; 71 | } 72 | for(tempRes=run->res;res;tempRes=tempRes->pNext){ 73 | if(tempRes->RID==rid){ 74 | printf("Process %d is using the resource %d\n",pid,rid); 75 | return; 76 | } 77 | } 78 | for(tempRes=res;tempRes;tempRes=tempRes->next){ 79 | if(tempRes->RID==rid){ 80 | if(tempRes->status=='F'){ 81 | tempRes->status='A'; 82 | if(run->res){ 83 | for(tempPRes=run->res;tempPRes->pNext!=NULL;tempPRes=tempPRes->pNext); 84 | tempPRes->pNext=tempRes; 85 | } 86 | else 87 | run->res=tempRes; 88 | printf("Process %d request resource %d successfully\n",pid,rid); 89 | } 90 | else{ 91 | if(tempRes->block_list){ 92 | tempRes->block_list=run; 93 | run->status='B'; 94 | if(block) 95 | block=run; 96 | else{ 97 | for(temp=block;temp->next==NULL;temp=temp->next); 98 | temp->next=run; 99 | } 100 | printf("Process %d is blocked",pid); 101 | scheduler(); 102 | } 103 | } 104 | } 105 | } 106 | /* res r=get_RCB(rid); 107 | if(r->status=='F'){ 108 | r->status='A'; 109 | insert(self->other_resource,r); 110 | }else{ 111 | self->status.type='B'; 112 | self->status.list=r; 113 | remove(RL,self); 114 | insert(r->waiting,self); 115 | } 116 | scheduler(); 117 | */ 118 | } 119 | void request_(){ 120 | int pid,rid; 121 | printf("Please type the request pid with process rid\n"); 122 | scanf("%d %d",&rid,&pid); 123 | request(pid,rid); 124 | } 125 | 126 | void release(int pid,int rid){ 127 | RES *tempRes; 128 | RES *lastTempRes; 129 | PCB *temp; 130 | PCB *temp2; 131 | // PCB lastTemp; 132 | if(pid==run->id){ 133 | printf("Process %d is running.you cant release it\n",pid); 134 | } 135 | for(tempRes=run->res;tempRes;tempRes=tempRes->pNext){ 136 | if(tempRes->RID==rid){ 137 | lastTempRes->next=tempRes->next; 138 | printf("Process %d free resource %d successfully",pid,rid); 139 | tempRes->status='F'; 140 | if(tempRes->block_list!=NULL){ 141 | temp=tempRes->block_list; 142 | tempRes->block_list=tempRes->block_list->next; 143 | 144 | for(temp2=ready;temp2->next!=NULL;temp2=temp2->next); 145 | temp2->next=temp; 146 | temp->status='W'; 147 | 148 | for(lastTempRes=temp->res;lastTempRes->next!=NULL;lastTempRes=lastTempRes->pNext) 149 | lastTempRes->next=tempRes; 150 | printf("Blocked process %d get resource\n",temp->id); 151 | tempRes->status='A'; 152 | printf("Blocked process %d enter ready quene",temp->id); 153 | if(run->priority < temp->priority){ 154 | printf("Process %d is deprived of operation rights",run->id); 155 | for(temp2=ready;temp2->next!=NULL;temp2=temp2->next); 156 | temp2->next=temp; 157 | run->status='W'; 158 | run=temp; 159 | run->status='R'; 160 | printf("Process %d start running",run->id); 161 | } 162 | break; 163 | 164 | } 165 | /* 166 | for(temp=run->res;temp;temp=temp->pNext){ 167 | if(temp->RID==rid){ 168 | temp 169 | } 170 | }*/ 171 | } 172 | lastTempRes=tempRes; 173 | } 174 | /* r=get_RCB(RID); 175 | remove(self->other_resource,r); 176 | if(waiting_list==NULL) 177 | r->status='F'; 178 | else { 179 | remove(r->waiting_list,q); 180 | q->status.type='R'; 181 | q->status.list=RL; 182 | insert(RL,q); 183 | } 184 | scheduler(); 185 | */ 186 | } 187 | void release_(){ 188 | int pid,rid; 189 | printf("Please type the release rid with process pid\n"); 190 | scanf("%d %d",&rid,&pid); 191 | release(pid,rid);; 192 | } 193 | 194 | void createInit(){ 195 | PCB *p=(PCB*)malloc(sizeof(PCB)); 196 | p->id=0; 197 | p->name[0]='i';p->name[1]='n';p->name[2]='i';p->name[3]='t';p->name[4]='\0'; 198 | p->priority=0; 199 | p->status='R'; 200 | p->next=NULL; 201 | run=p; 202 | scheduler(); 203 | } 204 | 205 | void createProcess(){ 206 | PCB *newProcess=(PCB *)malloc(sizeof(PCB)); 207 | PCB *lastTemp; 208 | PCB *temp; 209 | printf("Please type the process id,process name,priority\n"); 210 | scanf("%d %s %d",&(newProcess->id),newProcess->name,&(newProcess->priority)); 211 | newProcess->status='W'; 212 | newProcess->next=NULL; 213 | if(ready==NULL) 214 | ready=newProcess; 215 | else{ 216 | for(temp=ready;temp;temp=temp->next){ 217 | if(temp->id==newProcess->id){ 218 | printf("Process id is repeat\n"); 219 | free(newProcess); 220 | return; 221 | } 222 | lastTemp=temp; 223 | } 224 | if(newProcess->priority<0 || newProcess->priority>10){ 225 | printf("The process priority is out of range\n"); 226 | return ; 227 | } 228 | lastTemp->next=newProcess; 229 | } 230 | printf("Create process successfully\n"); 231 | scheduler(); 232 | } 233 | 234 | void deleteProcess(){ 235 | PCB *temp; 236 | PCB *lastTemp; 237 | int pid; 238 | printf("Please type the process id\n"); 239 | scanf("%d",&pid); 240 | if(run->id==pid){ 241 | free(run); 242 | run=NULL; 243 | printf("Delete process successfully\n"); 244 | return; 245 | } 246 | for(temp=ready;temp;temp=temp->next){ 247 | if(temp->id==pid){ 248 | lastTemp->next=temp->next; 249 | free(run); 250 | run=NULL; 251 | printf("Delete process successfully\n"); 252 | return; 253 | } 254 | lastTemp=temp; 255 | } 256 | for(temp=block;temp;temp=temp->next){ 257 | if(temp->id==pid){ 258 | lastTemp->next=temp->next; 259 | free(run); 260 | run=NULL; 261 | printf("Delete process successfully\n"); 262 | return; 263 | } 264 | lastTemp=temp; 265 | } 266 | printf("Pid is not exist\n"); 267 | } 268 | 269 | void listAllProcess(){ 270 | PCB *p; 271 | printf("quene:\tid\tname\tpriority\tstatue\n"); 272 | printf("run:\t%d\t%s\t%d\t\t%c\n",run->id,run->name,run->priority,run->status); 273 | for(p=ready;p;p=p->next){ 274 | printf("ready:\t%d\t%s\t%d\t\t%c\n",p->id,p->name,p->priority,p->status); 275 | } 276 | for(p=block;p;p=p->next){ 277 | printf("block:\t%d\t%s\t%d\t\t%c\n",p->id,p->name,p->priority,p->status); 278 | } 279 | } 280 | 281 | void addResource(){ 282 | RES *temp=NULL; 283 | RES *lastTemp=NULL; 284 | RES *newRes; 285 | int resID; 286 | printf("Please type the rid\n"); 287 | scanf("%d",&resID); 288 | for(temp=res;temp;temp=temp->next){ 289 | if(temp->RID==resID){ 290 | printf("RID is repeat\n"); 291 | return ; 292 | } 293 | lastTemp=temp; 294 | } 295 | newRes=(RES*)malloc(sizeof(RES)); 296 | newRes->RID=resID; 297 | newRes->status='F'; 298 | newRes->block_list=NULL; 299 | newRes->next=NULL; 300 | if(lastTemp) 301 | res=newRes; 302 | else 303 | lastTemp->next=newRes; 304 | printf("Add resource success successfully\n"); 305 | } 306 | 307 | void deleteResource(){ 308 | RES *temp; 309 | RES *lastTemp; 310 | RES *oprTemp; 311 | int resID; 312 | printf("Please type the rid\n"); 313 | scanf("%d",&resID); 314 | for(temp=res;temp;temp=temp->next){ 315 | if(temp->RID==resID){ 316 | oprTemp=temp->next; 317 | free(temp); 318 | lastTemp->next=oprTemp; 319 | printf("Free resource successfully\n"); 320 | } 321 | lastTemp=temp; 322 | } 323 | } 324 | 325 | void help(){ 326 | printf("C:Create Process\t D:Delete Process\n"); 327 | printf("A:Add Resource\t\t K:Delete Resource\n"); 328 | printf("N:Request resource\t F:Release Resource\n"); 329 | printf("L:List All Process\t Q:quit\n"); 330 | } 331 | 332 | int main(){ 333 | char ch='\0'; 334 | ready=NULL;//init quene 335 | block=NULL;//init quene 336 | //create a process 337 | res=NULL; 338 | 339 | help(); 340 | createInit(); 341 | 342 | while(ch!='Q'){ 343 | printf(">"); 344 | ch=getchar(); 345 | if(ch>='a' && ch<='z') 346 | ch=ch+'A'-'a';//Lowercase to uppercase 347 | switch(ch){ 348 | case 'A': 349 | addResource(); 350 | break; 351 | case 'C': 352 | createProcess(); 353 | break; 354 | case 'D': 355 | deleteProcess(); 356 | break; 357 | case 'K': 358 | deleteResource(); 359 | break; 360 | case 'L': 361 | listAllProcess(); 362 | break; 363 | case 'N': 364 | request_(); 365 | break; 366 | case 'F': 367 | release_(); 368 | break; 369 | case '\n': 370 | continue; 371 | default: 372 | printf("Wrong commond\n"); 373 | help(); 374 | break; 375 | } 376 | } 377 | free(res); 378 | 379 | } 380 | -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1pro_con.c_back: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct resource{ 5 | int RID; 6 | char status; //resource status F:free A:allocated 7 | struct pcb *block_list; 8 | struct resource *next; 9 | struct resource *pNext; 10 | }RES; 11 | 12 | typedef struct pcb{ 13 | int id; //process id 14 | char name[20]; 15 | int mem; // 16 | RES *res; //other resource 17 | char status;//process status W:wait R:running B:block 18 | int priority; //priority 19 | // struct pcb father; //generation tree 20 | // struct pcb son; //generation tree 21 | struct pcb *next; 22 | }PCB; 23 | 24 | PCB *ready; 25 | PCB *block; 26 | PCB *run;//only one 27 | PCB *prc; 28 | RES *res; 29 | 30 | 31 | void scheduler(){ 32 | PCB *temp; 33 | PCB *superTemp=NULL; 34 | PCB *superLastTemp=NULL; 35 | PCB *lastTemp=NULL; 36 | for(temp=ready;temp;temp=temp->next){ 37 | if(superTemp==NULL || temp->priority > superTemp->priority){ 38 | superTemp=temp; 39 | superLastTemp=temp; 40 | } 41 | lastTemp=temp; 42 | } 43 | if(temp){ 44 | if(run!=NULL && run->priority>superTemp->priority){ 45 | printf("Process %d is deprived of operation rights\n",run->id); 46 | superLastTemp->next=superTemp->next; 47 | lastTemp->next=run; //Put the run process to the last position of the quene 48 | run->next=NULL; 49 | } 50 | run=superTemp; 51 | printf("Process %d starts running",run->id); 52 | } 53 | 54 | //if(self->priority < p->priority || self->status.type!='R'|| self=nil) 55 | // preempt(p,self); 56 | } 57 | 58 | void request(int pid,int rid){ 59 | PCB *temp; 60 | RES *tempRes; 61 | RES *tempPRes; 62 | 63 | if(run->id!=pid){ 64 | printf("This process is not running\n"); 65 | return; 66 | } 67 | for(tempRes=run->res;res;tempRes=tempRes->pNext){ 68 | if(tempRes->RID==rid){ 69 | printf("Process %d is using the resource %d\n",pid,rid); 70 | return; 71 | } 72 | } 73 | for(tempRes=res;tempRes;tempRes=tempRes->next){ 74 | if(tempRes->RID==rid){ 75 | if(tempRes->status=='F'){ 76 | tempRes->status='A'; 77 | if(run->res){ 78 | for(tempPRes=run->res;tempPRes->pNext!=NULL;tempPRes=tempPRes->pNext); 79 | tempPRes->pNext=tempRes; 80 | } 81 | else 82 | run->res=tempRes; 83 | printf("Process %d request resource %d successfully\n",pid,rid); 84 | } 85 | else{ 86 | if(tempRes->block_list){ 87 | tempRes->block_list=run; 88 | run->status='B'; 89 | if(block) 90 | block=run; 91 | else{ 92 | for(temp=block;temp->next==NULL;temp=temp->next); 93 | temp->next=run; 94 | } 95 | printf("Process %d is blocked",pid); 96 | scheduler(); 97 | } 98 | } 99 | } 100 | } 101 | /* res r=get_RCB(rid); 102 | if(r->status=='F'){ 103 | r->status='A'; 104 | insert(self->other_resource,r); 105 | }else{ 106 | self->status.type='B'; 107 | self->status.list=r; 108 | remove(RL,self); 109 | insert(r->waiting,self); 110 | } 111 | scheduler(); 112 | */ 113 | } 114 | void request_(){ 115 | int pid,rid; 116 | printf("Please type the request pid with process rid\n"); 117 | scanf("%d %d",&rid,&pid); 118 | request(pid,rid); 119 | } 120 | 121 | void release(int pid,int rid){ 122 | RES *tempRes; 123 | RES *lastTempRes; 124 | PCB *temp; 125 | PCB *temp2; 126 | PCB lastTemp; 127 | if(pid==run->id){ 128 | printf("Process %d is running.you cant release it\n",pid); 129 | } 130 | for(tempRes=run->res;tempRes;tempRes=tempRes->pNext){ 131 | if(tempRes->RID==rid){ 132 | lastTempRes->next=tempRes->next; 133 | printf("Process %d free resource %d successfully",pid,rid); 134 | tempRes->status='F'; 135 | if(tempRes->block_list!=NULL){ 136 | temp=tempRes->block_list; 137 | tempRes->block_list=tempRes->block_list->next; 138 | 139 | for(temp2=ready;temp2->next!=NULL;temp2=temp2->next); 140 | temp2->next=temp; 141 | temp->status='W'; 142 | 143 | for(lastTempRes=temp->res;lastTempRes->next!=NULL;lastTempRes=lastTempRes->pNext) 144 | lastTempRes->next=tempRes; 145 | printf("Blocked process %d get resource\n",temp->id); 146 | tempRes->status='A'; 147 | printf("Blocked process %d enter ready quene",temp->id); 148 | if(run->priority < temp->priority){ 149 | printf("Process %d is deprived of operation rights",run->id); 150 | for(temp2=ready;temp2->next!=NULL;temp2=temp2->next); 151 | temp2->next=temp; 152 | run->status='W'; 153 | run=temp; 154 | run->status='R'; 155 | printf("Process %d start running",run->id); 156 | } 157 | break; 158 | 159 | } 160 | /* 161 | for(temp=run->res;temp;temp=temp->pNext){ 162 | if(temp->RID==rid){ 163 | temp 164 | } 165 | }*/ 166 | } 167 | lastTempRes=tempRes; 168 | } 169 | /* r=get_RCB(RID); 170 | remove(self->other_resource,r); 171 | if(waiting_list==NULL) 172 | r->status='F'; 173 | else { 174 | remove(r->waiting_list,q); 175 | q->status.type='R'; 176 | q->status.list=RL; 177 | insert(RL,q); 178 | } 179 | scheduler(); 180 | */ 181 | } 182 | void release_(){ 183 | int pid,rid; 184 | printf("Please type the release rid with process pid\n"); 185 | scanf("%d %d",&rid,&pid); 186 | release(pid,rid);; 187 | } 188 | 189 | void createInit(){ 190 | PCB *p=(PCB*)malloc(sizeof(PCB)); 191 | p->id=0; 192 | p->name[0]='i';p->name[1]='n';p->name[2]='i';p->name[3]='t'; 193 | p->priority=0; 194 | p->status='R'; 195 | p->next=NULL; 196 | ready=p; 197 | scheduler(); 198 | } 199 | 200 | void createProcess(){ 201 | PCB *newProcess=(PCB *)malloc(sizeof(PCB)); 202 | PCB *lastTemp; 203 | PCB *temp; 204 | printf("Please type the process id,process name,priority\n"); 205 | scanf("%d %s %d",&(newProcess->id),newProcess->name,&(newProcess->priority)); 206 | newProcess->status='W'; 207 | newProcess->next=NULL; 208 | for(temp=ready;temp;temp=temp->next){ 209 | if(temp->id==newProcess->id){ 210 | printf("Process id is repeat\n"); 211 | free(newProcess); 212 | return; 213 | } 214 | lastTemp=temp; 215 | } 216 | if(newProcess->priority<0 || newProcess->priority>10){ 217 | printf("The process priority is out of range\n"); 218 | return ; 219 | } 220 | lastTemp->next=newProcess; 221 | printf("Create process successfully\n"); 222 | scheduler(); 223 | } 224 | 225 | void deleteProcess(){ 226 | PCB *temp; 227 | PCB *lastTemp; 228 | int pid; 229 | printf("Please type the process id\n"); 230 | scanf("%d",&pid); 231 | if(run->id==pid){ 232 | free(run); 233 | run=NULL; 234 | printf("Delete process successfully\n"); 235 | return; 236 | } 237 | for(temp=ready;temp;temp=temp->next){ 238 | if(temp->id==pid){ 239 | lastTemp->next=temp->next; 240 | free(run); 241 | run=NULL; 242 | printf("Delete process successfully\n"); 243 | return; 244 | } 245 | lastTemp=temp; 246 | } 247 | for(temp=block;temp;temp=temp->next){ 248 | if(temp->id==pid){ 249 | lastTemp->next=temp->next; 250 | free(run); 251 | run=NULL; 252 | printf("Delete process successfully\n"); 253 | return; 254 | } 255 | lastTemp=temp; 256 | } 257 | printf("Pid is not exist\n"); 258 | } 259 | 260 | void listBlockedProcess(){ 261 | PCB *p; 262 | printf("Blocked process:\n"); 263 | printf("id\tname\tpriority\tstatue\n"); 264 | for(p=block;p;p=p->next){ 265 | printf("%d\t%s\t%d\t\t%c\n",p->id,p->name,p->priority,p->status); 266 | } 267 | } 268 | 269 | void listReadyProcess(){ 270 | PCB *p; 271 | printf("Ready process:\n"); 272 | printf("id\tname\tpriority\tstatue\n"); 273 | for(p=ready;p;p=p->next){ 274 | printf("%d\t%s\t%d\t\t%c\n",p->id,p->name,p->priority,p->status); 275 | } 276 | } 277 | 278 | void addResource(){ 279 | RES *temp=res; 280 | RES *newRes; 281 | int resID; 282 | printf("Please type the rid\n"); 283 | scanf("%d",&resID); 284 | do{ 285 | if(temp->RID==resID){ 286 | printf("RID is repeat\n"); 287 | return ; 288 | } 289 | temp=temp->next; 290 | }while(temp->next!=NULL); 291 | newRes=(RES*)malloc(sizeof(RES)); 292 | newRes->RID=resID; 293 | newRes->status='F'; 294 | newRes->block_list=NULL; 295 | newRes->next=NULL; 296 | temp->next=newRes; 297 | printf("Add resource success successfully\n"); 298 | } 299 | 300 | void deleteResource(){ 301 | RES *temp; 302 | RES *lastTemp; 303 | RES *oprTemp; 304 | int resID; 305 | printf("Please type the rid\n"); 306 | scanf("%d",&resID); 307 | for(temp=res;temp;temp=temp->next){ 308 | if(temp->RID==resID){ 309 | oprTemp=temp->next; 310 | free(temp); 311 | lastTemp->next=oprTemp; 312 | printf("Free resource successfully\n"); 313 | } 314 | lastTemp=temp; 315 | } 316 | } 317 | 318 | void help(){ 319 | printf("C:Create Process\t D:Delete Process\n"); 320 | printf("R:List Ready Process\t B:List Blocked Process\n"); 321 | printf("A:Add Resource\t\t K:Delete Resource\n"); 322 | printf("N:Request resource\t F:Release Resource\n"); 323 | } 324 | 325 | int main(){ 326 | char ch='\0'; 327 | ready=NULL;//init quene 328 | block=NULL;//init quene 329 | //create a process 330 | res=(RES*)malloc(sizeof(RES)); 331 | res->RID=1; 332 | res->status='F'; 333 | res->block_list=NULL; 334 | 335 | help(); 336 | createInit(); 337 | 338 | while(ch!='Q'){ 339 | printf(">"); 340 | ch=getchar(); 341 | if(ch>'a' && ch<'z') 342 | ch=ch+'A'-'a';//Lowercase to uppercase 343 | switch(ch){ 344 | case 'A': 345 | addResource(); 346 | break; 347 | case 'C': 348 | createProcess(); 349 | break; 350 | case 'D': 351 | deleteProcess(); 352 | break; 353 | case 'K': 354 | deleteResource(); 355 | break; 356 | case 'R': 357 | listReadyProcess(); 358 | break; 359 | case 'B': 360 | listBlockedProcess(); 361 | break; 362 | case 'N': 363 | request_(); 364 | break; 365 | case 'F': 366 | release_(); 367 | break; 368 | case '\n': 369 | continue; 370 | default: 371 | printf("Wrong commond\n"); 372 | help(); 373 | break; 374 | } 375 | } 376 | free(res); 377 | 378 | } 379 | -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1pro_con.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="1pro_con" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=1pro_con - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "1pro_con.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "1pro_con.mak" CFG="1pro_con - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "1pro_con - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "1pro_con - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "1pro_con - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 46 | # ADD RSC /l 0x804 /d "NDEBUG" 47 | BSC32=bscmake.exe 48 | # ADD BASE BSC32 /nologo 49 | # ADD BSC32 /nologo 50 | LINK32=link.exe 51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | 54 | !ELSEIF "$(CFG)" == "1pro_con - Win32 Debug" 55 | 56 | # PROP BASE Use_MFC 0 57 | # PROP BASE Use_Debug_Libraries 1 58 | # PROP BASE Output_Dir "Debug" 59 | # PROP BASE Intermediate_Dir "Debug" 60 | # PROP BASE Target_Dir "" 61 | # PROP Use_MFC 0 62 | # PROP Use_Debug_Libraries 1 63 | # PROP Output_Dir "Debug" 64 | # PROP Intermediate_Dir "Debug" 65 | # PROP Target_Dir "" 66 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 67 | # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 68 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 69 | # ADD RSC /l 0x804 /d "_DEBUG" 70 | BSC32=bscmake.exe 71 | # ADD BASE BSC32 /nologo 72 | # ADD BSC32 /nologo 73 | LINK32=link.exe 74 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 75 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 76 | 77 | !ENDIF 78 | 79 | # Begin Target 80 | 81 | # Name "1pro_con - Win32 Release" 82 | # Name "1pro_con - Win32 Debug" 83 | # Begin Source File 84 | 85 | SOURCE=.\1pro_con.c 86 | # End Source File 87 | # End Target 88 | # End Project 89 | -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1pro_con.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/1pro_con.exe -------------------------------------------------------------------------------- /OperatingSystem/Exp01/1pro_con.plg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/1pro_con.plg -------------------------------------------------------------------------------- /OperatingSystem/Exp01/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OperatingSystem/Exp01/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp01/a.out -------------------------------------------------------------------------------- /OperatingSystem/Exp02/MEM_OPR2.DSW: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/MEM_OPR2.DSW -------------------------------------------------------------------------------- /OperatingSystem/Exp02/MEM_OPR2.OPT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/MEM_OPR2.OPT -------------------------------------------------------------------------------- /OperatingSystem/Exp02/MEM_OPR2.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/MEM_OPR2.ncb -------------------------------------------------------------------------------- /OperatingSystem/Exp02/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OperatingSystem/Exp02/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/a.out -------------------------------------------------------------------------------- /OperatingSystem/Exp02/mem_opr.c: -------------------------------------------------------------------------------- 1 | //Coding:UTF-8 2 | #include 3 | #include 4 | #include 5 | #define MEMSIZE 3000 6 | typedef struct memNode{ 7 | int pid; 8 | char* begin; 9 | char* end; 10 | int len; 11 | struct memNode *next; 12 | struct memNode *pre; 13 | }mem; 14 | 15 | 16 | typedef struct quene{ 17 | mem *head; 18 | mem *tail; 19 | }Quene; 20 | 21 | typedef struct proc_quene{ 22 | int len; 23 | int pid; 24 | struct proc_quene *next; 25 | }PQuene; 26 | 27 | Quene busy; 28 | Quene Free; 29 | PQuene *pQuene; 30 | char *MEM; 31 | int choice; 32 | int processnum=0; 33 | 34 | void addFreeNode(mem *node){ 35 | mem *pNode; 36 | if(Free.head==NULL){ 37 | node->pre=NULL; 38 | node->next=NULL; 39 | Free.head=node; 40 | Free.tail=node; 41 | return; 42 | } 43 | switch(choice){ 44 | case 1: 45 | node->pre=Free.tail; 46 | Free.tail->next=node; 47 | node->next=NULL; 48 | Free.tail=node; 49 | break; 50 | case 2: 51 | case 3: 52 | if(choice==2) 53 | for(pNode=Free.head;pNode!=NULL&&pNode->lenlen;pNode=pNode->next); 54 | else 55 | for(pNode=Free.head;pNode!=NULL&&pNode->len>node->len;pNode=pNode->next); 56 | if(pNode==Free.tail){//last one 57 | node->pre=Free.tail; 58 | node->next=NULL; 59 | //Free.tail->next=node;//? 60 | Free.tail=node; 61 | }else if(pNode==Free.head){//first one 62 | node->pre=NULL; 63 | node->next=pNode; 64 | pNode->pre=node; 65 | Free.head=node; 66 | }else{ 67 | if(node==NULL) 68 | return; 69 | node->next=pNode; 70 | node->pre=pNode->pre; 71 | pNode->pre->next=node; 72 | pNode->pre=node; 73 | 74 | 75 | //node->pre=pNode->pre; 76 | //pNode->pre->next=node;//? 77 | //pNode->pre=node; 78 | } 79 | break; 80 | } 81 | } 82 | 83 | void addBusyNode(mem *node){ 84 | node->next=busy.head; 85 | busy.head=node; 86 | } 87 | 88 | void memInit(){ 89 | int reqSize; 90 | int allocatedSize=0; 91 | int remainSize=MEMSIZE; 92 | int flag=0; 93 | 94 | mem* pNode; 95 | MEM=(char*)malloc(MEMSIZE*sizeof(char)); 96 | printf("内存从%p到%p",MEM,(MEM+MEMSIZE)); 97 | while(remainSize){ 98 | while((reqSize=rand()%(MEMSIZE)/4)<2); 99 | pNode=(mem*)malloc(sizeof(mem)); 100 | pNode->next=NULL; 101 | pNode->pre=NULL; 102 | if(remainSize<=reqSize){ 103 | reqSize=remainSize; 104 | } 105 | pNode->begin=MEM+allocatedSize+1; 106 | pNode->end=MEM-reqSize-2; 107 | pNode->len=reqSize; 108 | remainSize-=reqSize; 109 | allocatedSize=reqSize; 110 | if(flag==0){//Alloc free space 111 | addFreeNode(pNode); 112 | flag=1; 113 | }else{ 114 | processnum++; 115 | pNode->pid=processnum; 116 | addBusyNode(pNode); 117 | flag=0; 118 | } 119 | } 120 | } 121 | 122 | 123 | 124 | mem *deleteNode(Quene que,mem *delNode){ 125 | mem* pNode=que.head; 126 | mem* preNode=pNode; 127 | for(;pNode!=NULL&&pNode!=delNode;preNode=pNode,pNode=pNode->next); 128 | if(pNode==NULL){ 129 | printf("找不到此进程内存表\n"); 130 | return NULL; 131 | }else if(pNode==que.head){ 132 | que.head=pNode->next; 133 | que.head->pre=NULL; 134 | }else{ 135 | pNode->next->pre=pNode->pre; 136 | preNode->next=pNode->next; 137 | } 138 | return pNode; 139 | } 140 | 141 | void printt(Quene *que,int symbol){ 142 | mem *p; 143 | for(p=que->head;p!=NULL;p=p->next) 144 | if(symbol)//free 145 | printf("%p\t%p\t%d\n",p->begin,p->end,p->len); 146 | else//busy 147 | printf("%d\t%p\t%p\t%d\n",p->pid,p->begin,p->end,p->len); 148 | 149 | } 150 | 151 | void joinQuene(int pid,int n,int flag){ 152 | PQuene *req=(PQuene*)malloc(sizeof(PQuene)); 153 | PQuene *end; 154 | req->len=n; 155 | req->pid=pid; 156 | if(pQuene==NULL) 157 | pQuene=req; 158 | else 159 | for(end=pQuene;end->next!=NULL;end=end->next); 160 | end->next=pQuene; 161 | } 162 | 163 | void *req(int pid,int n,int flag){ 164 | if(pQuene!=NULL && flag==1){ 165 | joinQuene(pid,n,flag); 166 | printf("内存分配失败,加入队列\n"); 167 | return NULL; 168 | }else{ 169 | mem *pNode=Free.head; 170 | for(;pNode!=NULL&&pNode->lennext); 171 | if(pNode==NULL){ 172 | joinQuene(pid,n,flag); 173 | printf("没有剩余空间,加入请求队列中\n"); 174 | return NULL; 175 | }else{ 176 | mem* busyNode=(mem*)malloc(sizeof(mem)); 177 | busyNode->begin=pNode->begin; 178 | if(pNode->len-n<2){ 179 | busyNode->len=pNode->len; 180 | busyNode->end=pNode->end; 181 | deleteNode(Free,pNode); 182 | }else{ 183 | busyNode->len=n; 184 | busyNode->end=busyNode->begin+n; 185 | pNode->len=pNode->len-n; 186 | pNode->begin=pNode->begin+n+1; 187 | } 188 | busyNode->pid=pid; 189 | addBusyNode(busyNode); 190 | printf("进程%d申请内存成功",pid); 191 | printf("空闲分区:\nStart\t\tEnd\t\tSize\n"); 192 | printt(&Free,1); 193 | printf("已用分区:\nPID\tStart\t\tEnd\t\tSize\n"); 194 | printt(&busy,0); 195 | return busyNode; 196 | } 197 | } 198 | } 199 | 200 | void mm_release(int pid){ 201 | mem *delNode; 202 | mem *FreeNode=(mem*)malloc(sizeof(mem)); 203 | mem *pNode; 204 | for(delNode=busy.head;delNode!=NULL && delNode->pid==pid;delNode=delNode->next); 205 | if(delNode==NULL){ 206 | printf("没有找到对应PID的进程\n"); 207 | return; 208 | } 209 | 210 | FreeNode->begin=delNode->begin; 211 | FreeNode->end=delNode->end; 212 | FreeNode->len=delNode->len; 213 | FreeNode->next=NULL; 214 | for(pNode=Free.head;pNode!=NULL;pNode=pNode->next) 215 | if(pNode->end+1==FreeNode->begin){ 216 | FreeNode->len=FreeNode->len+delNode->len; 217 | FreeNode->begin=delNode->begin; 218 | break; 219 | } 220 | 221 | pNode=deleteNode(busy,delNode); 222 | free(pNode); 223 | } 224 | 225 | int main(){ 226 | char opt; 227 | busy.head=NULL; 228 | busy.tail=NULL; 229 | Free.head=NULL; 230 | Free.tail=NULL; 231 | srand(time(NULL)); 232 | pQuene=NULL; 233 | printf("1.最先适应\t2.最佳适应\t3.最坏适应\n>"); 234 | scanf("%d",&choice); 235 | if(choice!=1 && choice!=2 && choice!=3){ 236 | printf("输入错误\n"); 237 | return 0; 238 | } 239 | memInit(); 240 | printf("内存总大小:%d",MEMSIZE); 241 | printf("空闲分区:\nStart\t\tEnd\t\tSize\n"); 242 | printt(&Free,1); 243 | printf("已用分区:\nPID\tStart\t\tEnd\t\tSize\n"); 244 | printt(&busy,0); 245 | while(opt){ 246 | int i; 247 | printf("r:申请内存\tf:释放内存\tq:退出\n"); 248 | scanf("%c %d",&opt,&i); 249 | if(opt=='r'){ 250 | processnum++; 251 | req(processnum,i,1); 252 | }else if(opt=='f'){ 253 | mm_release(i); 254 | }else if(opt=='q'){ 255 | break; 256 | }else printf("错误输入\n"); 257 | } 258 | return 0; 259 | 260 | } 261 | -------------------------------------------------------------------------------- /OperatingSystem/Exp02/mem_opr2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/mem_opr2.c -------------------------------------------------------------------------------- /OperatingSystem/Exp02/mem_opr2.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="mem_opr2" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=mem_opr2 - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "mem_opr2.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "mem_opr2.mak" CFG="mem_opr2 - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "mem_opr2 - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "mem_opr2 - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "mem_opr2 - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 46 | # ADD RSC /l 0x804 /d "NDEBUG" 47 | BSC32=bscmake.exe 48 | # ADD BASE BSC32 /nologo 49 | # ADD BSC32 /nologo 50 | LINK32=link.exe 51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | 54 | !ELSEIF "$(CFG)" == "mem_opr2 - Win32 Debug" 55 | 56 | # PROP BASE Use_MFC 0 57 | # PROP BASE Use_Debug_Libraries 1 58 | # PROP BASE Output_Dir "Debug" 59 | # PROP BASE Intermediate_Dir "Debug" 60 | # PROP BASE Target_Dir "" 61 | # PROP Use_MFC 0 62 | # PROP Use_Debug_Libraries 1 63 | # PROP Output_Dir "Debug" 64 | # PROP Intermediate_Dir "Debug" 65 | # PROP Target_Dir "" 66 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 67 | # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 68 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 69 | # ADD RSC /l 0x804 /d "_DEBUG" 70 | BSC32=bscmake.exe 71 | # ADD BASE BSC32 /nologo 72 | # ADD BSC32 /nologo 73 | LINK32=link.exe 74 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 75 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 76 | 77 | !ENDIF 78 | 79 | # Begin Target 80 | 81 | # Name "mem_opr2 - Win32 Release" 82 | # Name "mem_opr2 - Win32 Debug" 83 | # Begin Source File 84 | 85 | SOURCE=.\mem_opr2.c 86 | # End Source File 87 | # End Target 88 | # End Project 89 | -------------------------------------------------------------------------------- /OperatingSystem/Exp02/mem_opr2.plg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp02/mem_opr2.plg -------------------------------------------------------------------------------- /OperatingSystem/Exp03/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OperatingSystem/Exp03/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp03/a.out -------------------------------------------------------------------------------- /OperatingSystem/Exp03/lib3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MaxNumber 200 5 | int PageOrder[MaxNumber]; 6 | int PageNum,LackNum,MinBlockNum; 7 | int PageDisCount[MaxNumber]; 8 | int LRUtime[MaxNumber]; 9 | 10 | float LackPageRate; 11 | int LackPageNum; 12 | int VirtualQueue[MaxNumber]; 13 | 14 | void input(); 15 | void initial(); 16 | void FIFO();//先进先出 17 | void OPI();//最佳置换 18 | void LRU();//最久未使用 19 | void display(); 20 | 21 | void input(){ 22 | printf("请输入最小物理块数:"); 23 | scanf("%d",&MinBlockNum); 24 | printf("请输入页面个数:"); 25 | scanf("%d",&PageNum); 26 | printf("请输入页面序列:"); 27 | for (int i=0;i=0;i++){ 196 | printf("%d\t",VirtualQueue[i]); 197 | } 198 | printf("\n"); 199 | } 200 | 201 | int main(){ 202 | input(); 203 | int chooseAlgorithm; 204 | 205 | while(1) 206 | { 207 | printf("1使用FIFO算法\n"); 208 | printf("2使用最佳页面置换算法\n"); 209 | printf("3使用最久未使用算法\n"); 210 | printf("4退出\n"); 211 | printf("请选择:\n"); 212 | scanf("%d",&chooseAlgorithm); 213 | switch(chooseAlgorithm) 214 | { 215 | case 1: 216 | FIFO(); 217 | break; 218 | case 2: 219 | OPI(); 220 | break; 221 | case 3: 222 | LRU(); 223 | break; 224 | case 4: 225 | return 0; 226 | default: 227 | printf("输入错误,请重新输入\n\n");break; 228 | } 229 | } 230 | return 0; 231 | } 232 | 233 | -------------------------------------------------------------------------------- /OperatingSystem/Exp03/main3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | class PageReplacement 7 | { 8 | public: 9 | PageReplacement(); 10 | ~PageReplacement(); 11 | void run(); 12 | void LRU(); 13 | 14 | private: 15 | void addInfo() const; 16 | 17 | private: 18 | int pages; // 虚拟内存的尺寸P 19 | int firstPageFramePos; // 工作面的起始位置p 20 | int pageFrames; // 工作面中包含的页数e 21 | int rateM; // 工作面移动率m 22 | std::vector seqVec; // 序列号 23 | std::vector mem; // 内存块 24 | }; 25 | 26 | 27 | PageReplacement::PageReplacement() 28 | : mem(3, -1) 29 | { 30 | this->run(); 31 | } 32 | 33 | PageReplacement::~PageReplacement() 34 | { 35 | } 36 | 37 | void PageReplacement::run() 38 | { 39 | std::cout << "请输入虚拟内存尺寸P:"; 40 | std::cin >> pages; 41 | std::cout << "请输入工作面的起始位置p:"; 42 | std::cin >> firstPageFramePos; 43 | std::cout << "请输入工作面中包含的页数e:"; 44 | std::cin >> pageFrames; 45 | std::cout << "请输入工作面移动率m:"; 46 | std::cin >> rateM; 47 | //std::cout << "请输入在0和1之间的值t:"; 48 | //std::cin >> t; 49 | 50 | for (int i = 0; i < rateM; ++i) 51 | { 52 | int randomNum = (rand() % pageFrames) + firstPageFramePos; 53 | seqVec.push_back(randomNum); 54 | } 55 | 56 | std::cout << "序列号:"; 57 | for (int i = 0; i < seqVec.size(); ++i) 58 | { 59 | std::cout << seqVec.at(i) << " "; 60 | } 61 | 62 | std::cout << std::endl; 63 | } 64 | 65 | void PageReplacement::LRU() 66 | { 67 | int nLack = 0; // 缺页数 68 | std::list seqList(seqVec.begin(), seqVec.end()); 69 | int nTotal = seqList.size(); 70 | 71 | std::vector timer(mem.size(), 0); // 每个内存块对应的时钟 72 | 73 | while (!seqList.empty()) 74 | { 75 | int head = *seqList.begin(); // 去队头的页面 76 | seqList.pop_front(); 77 | bool equal = false; // 标识内存中是否有与队头相等的页面 78 | int vacant = -1; // 标识内存中是否有空闲页面 79 | 80 | for (int i = 0; i < mem.size(); ++i) 81 | { 82 | if (mem.at(i) == head) // 如果找到相等的页面 83 | { 84 | equal = true; 85 | this->addInfo(); // 显示内存块 86 | 87 | timer.at(i) = -1; // 相等的时钟清零,其他的时钟加1 88 | for (int j = 0; j < timer.size(); ++j) 89 | { 90 | ++timer[j]; 91 | } 92 | 93 | break; 94 | } 95 | 96 | else if (mem.at(i) == -1 && vacant == -1) // 如果找到空闲位 97 | { 98 | vacant = i; 99 | } 100 | } 101 | 102 | if (equal) // 如果找到相等的页面,则进行下一个查找 103 | { 104 | continue; 105 | } 106 | 107 | ++nLack; 108 | 109 | if (vacant != -1) 110 | { 111 | mem[vacant] = head; // 把队头的放入到空闲位中 112 | this->addInfo(); 113 | 114 | timer[vacant] = -1; // 空闲位时钟清零,其他时钟加1 115 | for (int j = 0; j < timer.size(); ++j) 116 | { 117 | ++timer[j]; 118 | } 119 | 120 | continue; 121 | } 122 | 123 | else 124 | { 125 | int max = timer[0]; 126 | int subIndex = 0; 127 | for (int p = 0; p < timer.size(); ++p) 128 | { 129 | if (timer.at(p) > max) 130 | { 131 | max = timer.at(p); // 找到最近最久没有被使用的内存块 132 | subIndex = p; 133 | } 134 | } 135 | 136 | mem[subIndex] = head; // 把队头的放入到最近最久未被使用的内存块中 137 | this->addInfo(); 138 | 139 | timer[subIndex] = -1; 140 | for (int j = 0; j < timer.size(); ++j) 141 | { 142 | ++timer[j]; 143 | } 144 | 145 | } 146 | 147 | } 148 | 149 | std::cout << "缺页率: " << (double)nLack/nTotal * 100 << "%" << std::endl; 150 | } 151 | 152 | void PageReplacement::addInfo() const 153 | { 154 | std::cout << mem.at(0) << " " << mem.at(1) << " " << mem.at(2) << std::endl; 155 | } 156 | 157 | 158 | int main() 159 | { 160 | PageReplacement pageReplacement; 161 | 162 | pageReplacement.LRU(); 163 | 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /OperatingSystem/Exp04/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OperatingSystem/Exp04/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinyue123/CourseExperiment/adbd1cb6d3e42324da45657452de403bdf01677a/OperatingSystem/Exp04/a.out -------------------------------------------------------------------------------- /OperatingSystem/Exp04/lib4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define FALSE 0 4 | #define TRUE 1 5 | #define W 10 6 | #define R 20 7 | int ProNum; 8 | int ResKind; 9 | int AllResource[W]; 10 | int MAX[W][R]; 11 | int Available[R]; 12 | int Allocation[W][R]; 13 | int NEED[W][R]; 14 | int Request[R]; 15 | 16 | void showdata() 17 | { 18 | int i,j; 19 | printf("\nResourse available:\n"); 20 | for(j=0;j=ProNum) 115 | { 116 | printf("Input the allocation process number(P0-P%d) :",ProNum-1); 117 | printf("p"); 118 | scanf("%d",&i); 119 | if(i<0||i>=ProNum) 120 | printf("Invalid pid\n"); 121 | } 122 | printf("Input process P%d alloc resouce:\n",i); 123 | for(j=0;jNEED[i][j]) 128 | { 129 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 130 | printf(" The alloc is not reasonable. Fail to alloc."); 131 | flag='N'; 132 | break; 133 | } 134 | else 135 | { 136 | if(Request[j]>Available[j]) 137 | { 138 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 139 | printf(" The alloc is not reasonable. Fail to alloc."); 140 | flag='N'; 141 | break; 142 | } 143 | } 144 | } 145 | if(flag=='Y'||flag=='y') 146 | { 147 | changdata(i); 148 | if(check(i)) 149 | { 150 | rstordata(i); 151 | showdata(); 152 | } 153 | else 154 | showdata(); 155 | } 156 | else 157 | showdata(); 158 | getchar(); 159 | printf("Continue(Y/N)?"); 160 | scanf("%c",&flag); 161 | } 162 | } 163 | 164 | int main()//主函数 165 | { 166 | int i=0,j=0,p; 167 | printf("Process number:"); 168 | scanf("%d",&ProNum); 169 | printf("Resouce kind:"); 170 | scanf("%d",&ResKind); 171 | printf("Input all resource:\n"); 172 | for(i=0;iAllResource[j]) 184 | printf("Error:The process needs is bigger than annonced mount.\n"); 185 | }while(MAX[i][j]>AllResource[j]); 186 | } 187 | } 188 | printf("Input the resouce allocation:\n"); 189 | for(i=0;iMAX[i][j]) 198 | printf("Error:Occupied resouce is bigger than annonced mount.\n"); 199 | }while(Allocation[i][j]>MAX[i][j]); 200 | } 201 | } 202 | for(j=0;j 2 | #include 3 | #define FALSE 0 4 | #define TRUE 1 5 | #define W 10 6 | #define R 20 7 | int M; 8 | int N; 9 | int ALL_RESOURCE[W]; 10 | int MAX[W][R]; 11 | int AVAILABLE[R]; 12 | int ALLOCATION[W][R]; 13 | int NEED[W][R]; 14 | int Request[R]; 15 | 16 | void showdata() 17 | { 18 | int i,j; 19 | printf("\nResourse available:\n"); 20 | for(j=0;j=M) 115 | { 116 | printf("Input the allocation process number(P0-P%d) :",M-1); 117 | printf("p"); 118 | scanf("%d",&i); 119 | if(i<0||i>=M) 120 | printf("Invalid pid\n"); 121 | } 122 | printf("Input process P%d alloc resouce:\n",i); 123 | for(j=0;jNEED[i][j]) 128 | { 129 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 130 | printf(" The alloc is not reasonable. Fail to alloc."); 131 | flag='N'; 132 | break; 133 | } 134 | else 135 | { 136 | if(Request[j]>AVAILABLE[j]) 137 | { 138 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 139 | printf(" The alloc is not reasonable. Fail to alloc."); 140 | flag='N'; 141 | break; 142 | } 143 | } 144 | } 145 | if(flag=='Y'||flag=='y') 146 | { 147 | changdata(i); 148 | if(check(i)) 149 | { 150 | rstordata(i); 151 | showdata(); 152 | } 153 | else 154 | showdata(); 155 | } 156 | else 157 | showdata(); 158 | getchar(); 159 | printf("Continue(Y/N)?"); 160 | scanf("%c",&flag); 161 | } 162 | } 163 | 164 | int main()//主函数 165 | { 166 | int i=0,j=0,p; 167 | printf("Process number:"); 168 | scanf("%d",&M); 169 | printf("Resouce kind:"); 170 | scanf("%d",&N); 171 | printf("Input all resource:\n"); 172 | for(i=0;iALL_RESOURCE[j]) 184 | printf("Error:The process needs is bigger than annonced mount.\n"); 185 | }while(MAX[i][j]>ALL_RESOURCE[j]); 186 | } 187 | } 188 | printf("Input the resouce allocation:\n"); 189 | for(i=0;iMAX[i][j]) 198 | printf("Error:Occupied resouce is bigger than annonced mount.\n"); 199 | }while(ALLOCATION[i][j]>MAX[i][j]); 200 | } 201 | } 202 | for(j=0;j 2 | #include 3 | #define FALSE 0 4 | #define TRUE 1 5 | #define W 10 6 | #define R 20 7 | int M; 8 | int N; 9 | int ALL_RESOURCE[W]; 10 | int MAX[W][R]; 11 | int AVAILABLE[R]; 12 | int ALLOCATION[W][R]; 13 | int NEED[W][R]; 14 | int Request[R]; 15 | 16 | void showdata() 17 | { 18 | int i,j; 19 | printf("\nResourse available:\n"); 20 | for(j=0;j=M) 115 | { 116 | printf("Input the allocation process number(P0-P%d) :",M-1); 117 | printf("p"); 118 | scanf("%d",&i); 119 | if(i<0||i>=M) 120 | printf("Invalid pid\n"); 121 | } 122 | printf("Input process P%d alloc resouce:\n",i); 123 | for(j=0;jNEED[i][j]) 128 | { 129 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 130 | printf(" The alloc is not reasonable. Fail to alloc."); 131 | flag='N'; 132 | break; 133 | } 134 | else 135 | { 136 | if(Request[j]>AVAILABLE[j]) 137 | { 138 | printf("Process P%d alloc resouce amount is bigger than the process also need R%d.",i,j); 139 | printf(" The alloc is not reasonable. Fail to alloc."); 140 | flag='N'; 141 | break; 142 | } 143 | } 144 | } 145 | if(flag=='Y'||flag=='y') 146 | { 147 | changdata(i); 148 | if(check(i)) 149 | { 150 | rstordata(i); 151 | showdata(); 152 | } 153 | else 154 | showdata(); 155 | } 156 | else 157 | showdata(); 158 | getchar(); 159 | printf("Continue(Y/N)?"); 160 | scanf("%c",&flag); 161 | } 162 | } 163 | 164 | int main()//主函数 165 | { 166 | int i=0,j=0,p; 167 | printf("Process number:"); 168 | scanf("%d",&M); 169 | printf("Resouce kind:"); 170 | scanf("%d",&N); 171 | printf("Input all resource:\n"); 172 | for(i=0;iALL_RESOURCE[j]) 184 | printf("Error:The process needs is bigger than annonced mount.\n"); 185 | }while(MAX[i][j]>ALL_RESOURCE[j]); 186 | } 187 | } 188 | printf("Input the resouce allocation:\n"); 189 | for(i=0;iMAX[i][j]) 198 | printf("Error:Occupied resouce is bigger than annonced mount.\n"); 199 | }while(ALLOCATION[i][j]>MAX[i][j]); 200 | } 201 | } 202 | for(j=0;j=M) 129 | { 130 | cout<<" 请输入需申请资源的进程号(从P0到P"<>i; 132 | if(i<0||i>=M)cout<<" 输入的进程号不存在,重新输入!"<>Request[j]; 139 | if(Request[j]>NEED[i][j]) //若请求的资源数大于进程还需要i类资源的资源量j 140 | { 141 | cout<<" 进程P"<AVAILABLE[j]) //若请求的资源数大于可用资源数 149 | { 150 | cout<<" 进程P"<>flag; 173 | } 174 | } 175 | 176 | ////////////////////////////////////////////////////////////////////////////////////////////// 177 | 178 | //主函数 179 | int main() //主函数 180 | { 181 | int i=0,j=0,p; 182 | cout<<"请输入总进程数:"<>M; 184 | cout<<"请输入总资源种类:"<>N; 186 | cout<<"请输入总资源数(all_resource):"<>ALL_RESOURCE[i]; 189 | cout<<"依次输入各进程所需要的最大资源数量(max):"<>MAX[i][j]; 197 | if (MAX[i][j]>ALL_RESOURCE[j]) 198 | cout<ALL_RESOURCE[j]); 200 | } 201 | } 202 | cout<<"依次输入各进程已经占据的资源数量(allocation):"<>ALLOCATION[i][j]; 210 | if (ALLOCATION[i][j]>MAX[i][j]) 211 | cout<MAX[i][j]); 213 | } 214 | } 215 | //初始化资源数量, 216 | for (j=0;j