Chinaunix首页 | 论坛 | 博客
  • 博客访问: 176533
  • 博文数量: 89
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 828
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-08 10:44
文章分类
文章存档

2014年(9)

2013年(80)

我的朋友

分类: C/C++

2014-01-07 14:35:33

仍在编辑,预计后天完成

选择补选:

  1.预选:不算选中,不从这里下手。

2.正选:还要抽签,不能保证成功率。

3.补选:先到先得,从这里下手。

pcDuino:

1.不接屏幕,耗电很低

2.适合用来做耗时的事,比如下载,比如这个,接上移动电源,大概能用40个小时。



淘宝爆款电源,充电怕爆炸,都放厕所冲,瓷砖应该不容易烧起来。大哭

预计后天完成


Acknowledge:

 win及linux的md5加密和发包代码均复制修改于CSDN坛友。



Windows下


  1. #include   
  2. #include  
  3. #include  
  4. #include  
  5. #include  
  6. #include  
  7. #include  
  8. #define TEN 600.0  
  9. #include "md5.h"  
  10. #define S11 7  
  11. #define S12 12  
  12. #define S13 17  
  13. #define S14 22  
  14. #define S21 5  
  15. #define S22 9  
  16. #define S23 14  
  17. #define S24 20  
  18. #define S31 4  
  19. #define S32 11  
  20. #define S33 16  
  21. #define S34 23  
  22. #define S41 6  
  23. #define S42 10  
  24. #define S43 15  
  25. #define S44 21  
  26. #pragma comment(lib, "ws2_32.lib")  
  27. char info[1115]="";  
  28. char md5[35];  
  29.   
  30.   
  31. static void MD5Transform (UINT32 a[4], unsigned char b[64]);  
  32. static void Encode (unsigned char *, UINT32 *, unsigned int);  
  33. static void Decode (UINT32 *, unsigned char *, unsigned int);  
  34.   
  35. static unsigned char PADDING[64] = {  
  36.     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  
  37.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  
  38.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  
  39. };  
  40.   
  41. #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))  
  42. #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))  
  43. #define H(x, y, z) ((x) ^ (y) ^ (z))  
  44. #define I(x, y, z) ((y) ^ ((x) | (~z)))  
  45.   
  46.   
  47. #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))  
  48.   
  49. #define FF(a, b, c, d, x, s, ac) { \  
  50.     (a) += F ((b), (c), (d)) + (x) + (UINT32)(ac); \  
  51.     (a) = ROTATE_LEFT ((a), (s)); \  
  52.     (a) += (b); \  
  53.     }  
  54. #define GG(a, b, c, d, x, s, ac) { \  
  55.     (a) += G ((b), (c), (d)) + (x) + (UINT32)(ac); \  
  56.     (a) = ROTATE_LEFT ((a), (s)); \  
  57.     (a) += (b); \  
  58.     }  
  59. #define HH(a, b, c, d, x, s, ac) { \  
  60.     (a) += H ((b), (c), (d)) + (x) + (UINT32)(ac); \  
  61.     (a) = ROTATE_LEFT ((a), (s)); \  
  62.     (a) += (b); \  
  63.     }  
  64. #define II(a, b, c, d, x, s, ac) { \  
  65.     (a) += I ((b), (c), (d)) + (x) + (UINT32)(ac); \  
  66.     (a) = ROTATE_LEFT ((a), (s)); \  
  67.     (a) += (b); \  
  68.     }  
  69.   
  70.   
  71. void MD5Init (MD5_CTX *context)  
  72. {  
  73.     context->count[0] = context->count[1] = 0;  
  74.       
  75.     context->state[0] = 0x67452301;  
  76.     context->state[1] = 0xefcdab89;  
  77.     context->state[2] = 0x98badcfe;  
  78.     context->state[3] = 0x10325476;  
  79. }  
  80.   
  81.   
  82. void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)  
  83. {  
  84.     unsigned int i, index, partLen;  
  85.       
  86.     index = (unsigned int)((context->count[0] >> 3) & 0x3F);  
  87.       
  88.     if ((context->count[0] += ((UINT32)inputLen << 3))  
  89.         < ((UINT32)inputLen << 3))  
  90.         context->count[1]++;  
  91.     context->count[1] += ((UINT32)inputLen >> 29);  
  92.       
  93.     partLen = 64 - index;  
  94.       
  95.       
  96.     if (inputLen >= partLen) {  
  97.         memcpy((unsigned char *)&context->buffer[index], (unsigned char *)input, partLen);  
  98.         MD5Transform (context->state, context->buffer);  
  99.           
  100.         for (i = partLen; i + 63 < inputLen; i += 64)  
  101.             MD5Transform (context->state, &input[i]);  
  102.           
  103.         index = 0;  
  104.     }  
  105.     else  
  106.         i = 0;  
  107.       
  108.     memcpy((unsigned char *)&context->buffer[index], (unsigned char *)&input[i],  
  109.         inputLen-i);  
  110. }  
  111.   
  112. void MD5Final (unsigned char digest[16], MD5_CTX * context)  
  113. {  
  114.     unsigned char bits[8];  
  115.     unsigned int index, padLen;  
  116.       
  117.     Encode (bits, context->count, 8);  
  118.       
  119.     index = (unsigned int)((context->count[0] >> 3) & 0x3f);  
  120.     padLen = (index < 56) ? (56 - index) : (120 - index);  
  121.     MD5Update (context, PADDING, padLen);  
  122.       
  123.     MD5Update (context, bits, 8);  
  124.       
  125.     Encode (digest, context->state, 16);  
  126.       
  127.     memset ((unsigned char *)context, 0, sizeof (*context));  
  128. }  
  129.   
  130.   
  131.   
  132.   
  133. static void MD5Transform (UINT32 state[4], unsigned char block[64])  
  134. {  
  135.     UINT32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];  
  136.       
  137.     Decode (x, block, 64);  
  138.       
  139.     /* Round 1 www.dwhao.com */  
  140.     FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */  
  141.     FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */  
  142.     FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */  
  143.     FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */  
  144.     FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */  
  145.     FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */  
  146.     FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */  
  147.     FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */  
  148.     FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */  
  149.     FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */  
  150.     FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */  
  151.     FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */  
  152.     FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */  
  153.     FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */  
  154.     FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */  
  155.     FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */  
  156.       
  157.     /* Round 2 */  
  158.     GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */  
  159.     GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */  
  160.     GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */  
  161.     GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */  
  162.     GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */  
  163.     GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */  
  164.     GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */  
  165.     GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */  
  166.     GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */  
  167.     GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */  
  168.     GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */  
  169.     GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */  
  170.     GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */  
  171.     GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */  
  172.     GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */  
  173.     GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */  
  174.       
  175.     /* Round 3 */  
  176.     HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */  
  177.     HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */  
  178.     HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */  
  179.     HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */  
  180.     HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */  
  181.     HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */  
  182.     HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */  
  183.     HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */  
  184.     HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */  
  185.     HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */  
  186.     HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */  
  187.     HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */  
  188.     HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */  
  189.     HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */  
  190.     HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */  
  191.     HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */  
  192.       
  193.     /* Round 4 */  
  194.     II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */  
  195.     II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */  
  196.     II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */  
  197.     II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */  
  198.     II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */  
  199.     II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */  
  200.     II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */  
  201.     II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */  
  202.     II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */  
  203.     II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */  
  204.     II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */  
  205.     II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */  
  206.     II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */  
  207.     II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */  
  208.     II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */  
  209.     II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */  
  210.       
  211.     state[0] += a;  
  212.     state[1] += b;  
  213.     state[2] += c;  
  214.     state[3] += d;  
  215.       
  216.     memset ((unsigned char *)x, 0, sizeof (x));  
  217. }  
  218.   
  219. static void Encode (unsigned char *output, UINT32 *input, unsigned int len)  
  220. {  
  221.     unsigned int i, j;  
  222.       
  223.     for (i = 0, j = 0; j < len; i++, j += 4) {  
  224.         output[j] = (unsigned char)(input[i] & 0xff);  
  225.         output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);  
  226.         output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);  
  227.         output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);  
  228.     }  
  229. }  
  230.   
  231.   
  232. static void Decode (UINT32 *output, unsigned char *input, unsigned int len)  
  233. {  
  234.     unsigned int i, j;  
  235.       
  236.     for (i = 0, j = 0; j < len; i++, j += 4)  
  237.         output[i] = ((UINT32)input[j]) | (((UINT32)input[j+1]) << 8) |  
  238.         (((UINT32)input[j+2]) << 16) | (((UINT32)input[j+3]) << 24);  
  239. }  
  240.   
  241.   
  242.   
  243.   
  244.   
  245.   
  246.   
  247.   
  248. #include "md5.h"  
  249.   
  250. int Bemd5(char *tmp)  
  251. {  
  252.       
  253.     unsigned char digest[16];  
  254.       
  255.     MD5_CTX context;  
  256.       
  257.       
  258.       
  259.     MD5Init (&context);  
  260.     MD5Update (&context, (unsigned char*)tmp, strlen(tmp));  
  261.     MD5Final (digest,&context);  
  262.       
  263.     for(int i=0; i<16; ++i)  
  264.     {  
  265.         sprintf(md5+2*i,"%02X",digest[i]);  
  266.     }  
  267.     printf("\n");  
  268.       
  269.     return 0;  
  270. }  
  271.   
  272.   
  273.   
  274.   
  275.   
  276. int pock(char *sendbuf,int port,int flag) {  
  277.     WSADATA wsaData;  
  278.     int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );  
  279.     if ( iResult != NO_ERROR ){  
  280.         printf("Error at WSAStartup()\n");  
  281.     }  
  282.       
  283.     // Create a socket.  
  284.     SOCKET m_socket;  
  285.     m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );  
  286.     if ( m_socket == INVALID_SOCKET ) {  
  287.         printf( "Error at socket(): %ld\n", WSAGetLastError() );  
  288.         WSACleanup();  
  289.         return 1;  
  290.     }  
  291.     // Connect to a server.  
  292.     struct sockaddr_in clientService;  
  293.     clientService.sin_family = AF_INET;  
  294.     clientService.sin_addr.s_addr = inet_addr("58.192.142.134");  
  295.     clientService.sin_port = htons( port );  
  296.     if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(SOCKADDR)) == SOCKET_ERROR){  
  297.         printf( "Failed to connect.\n" );  
  298.         WSACleanup();  
  299.         return 0;  
  300.     }  
  301.       
  302.     // Send and receive data.  
  303.     int bytesSent;  
  304.     int bytesRecv = strlen(sendbuf);  
  305.     char recvbuf[1025]="";  
  306.       
  307.     bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );  
  308.       
  309.     //printf( "Bytes Sent: %ld\n", bytesSent );  
  310.       
  311.       
  312.     bytesRecv = recv(m_socket, recvbuf,1024 , 0);  
  313.       
  314.     recvbuf[bytesRecv+1] = 0;  
  315.     if(flag)  
  316.         strcpy(info,recvbuf);  
  317.       
  318.       
  319.       
  320.     closesocket(m_socket);  
  321.       
  322.     return 0;  
  323. }  
  324.   
  325.   
  326. void gotoxy(int x,int y)  
  327. {  
  328.     int xx=0x0b;  
  329.     HANDLE hOutput;  
  330.     COORD loc;  
  331.     loc.X=x;  
  332.     loc.Y=y;  
  333.     hOutput=GetStdHandle(STD_OUTPUT_HANDLE);  
  334.     SetConsoleCursorPosition(hOutput,loc);  
  335.     return;  
  336. }  
  337.   
  338.   
  339. int paus(float time)  
  340. {  
  341.     long zt1=clock();  
  342.     long zt2;  
  343.     while(1)  
  344.     {zt2=clock();  
  345.     if(((float)(zt2-zt1)/CLOCKS_PER_SEC)>time)  
  346.         return 0;  
  347.     else  
  348.     {gotoxy(23,1);  
  349.     printf("%-9.2f",((float)(zt2-zt1)/CLOCKS_PER_SEC));}  
  350.     }  
  351. }  
  352.   
  353.   
  354. int main()  
  355. {  
  356.     int loop;  
  357.     float tpause;  
  358.     printf("Input time(seconds):");  
  359.     scanf("%f",&tpause);  
  360.     puts("Waiting...,Now passed            seconds");  
  361.     paus(tpause);  
  362.     long zt1=clock();  
  363.     long zt2;  
  364.       
  365.     system("title=扬大学生系统bu xuan(third choice) Almost Powered by c");  
  366.     char acc[20];  
  367.     printf("扬   大 CoiLeson\n");  
  368.     printf("2014年1月2号\n");  
  369.       
  370.       
  371.     char *pg0;  
  372.         gotoxy(10,12);  
  373.     printf("RunTime is          seconds\n");  
  374. again:  
  375.     pg0=(char *)malloc(1025);  
  376.       
  377.       
  378.     char name[12]="110",pwd[18]="110";//here write id and passwd  
  379.     int i=0,j;  
  380.     Bemd5(pwd);  
  381.     sprintf(pg0,"GET /pls/wwwbks/bks_login2.uniteLogin?stuid=%s&pwd=%s HTTP/1.1\r\n"  
  382.         "Host:\r\n"  
  383.         "Proxy-Connection: keep-alive\r\n"  
  384.         "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"  
  385.         "User-Agent: \r\n"  
  386.         "Referer:\r\n"  
  387.         "Accept-Encoding: gzip,deflate,sdch\r\n"  
  388.         "Accept-Language: zh-CN,zh;q=0.8\r\n"  
  389.         "Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3\r\n"  
  390.         "Cookie: \r\n\r\n",name,md5);  
  391.       
  392.     pock(pg0,7777,1);  
  393.       
  394.     //here wrong!!!!!  
  395.       
  396.     i=j=0;  
  397.       
  398.     while(1){  
  399.         while(info[i]!='C')i++;  
  400.         if(info[i+3]==info[i+6])break;  
  401.         else i++;  
  402.     }  
  403.       
  404.       
  405.     if(info[i+16]!='1'){printf("密码错误,重新输入");}  
  406.     else  
  407.     {  
  408.           
  409.         while(1){  
  410.             while(info[i]!='S')i++;  
  411.             if(info[i+4]=='C')break;  
  412.             else i++;  
  413.         }  
  414.         j=i;  
  415.         while(info[j]!=';')j++;  
  416.         info[j]=0;  
  417.         strcpy(acc,info+20+i);  
  418.     }  
  419.       
  420.     system("title=登陆成功,成功得到ACCOUNT");  
  421.       
  422.     free(pg0);  
  423.       
  424.     pg0=(char *)malloc(1025);  
  425.       
  426.       
  427.       
  428.       
  429.   
  430.     for(loop=0;loop<3;loop++)  
  431.     {  
  432.         sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  433.             "Host: \r\n"  
  434.             "Proxy-Connection: keep-alive\r\n"  
  435.             "Content-Length: 29\r\n"  
  436.             "Cache-Control: \r\n"  
  437.             "Origin: \r\n"  
  438.             "User-Agent: \r\n"  
  439.             "Content-Type: \r\n"  
  440.             "Accept: \r\n"  
  441.             "Referer: \r\n"  
  442.             "Accept-Encoding: \r\n"  
  443.             "Accept-Language: \r\n"  
  444.             "Accept-Charset: \r\n"  
  445.             "Cookie: ACCOUNT=%s;\r\n\r\n"  
  446.             "p_qxrxk=0329001&p_qxrxk_kxh=1",acc);  
  447.           
  448.         pock(pg0,7777,0);  
  449.           
  450.         sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  451.             "Host: \r\n"  
  452.             "Proxy-Connection: keep-alive\r\n"  
  453.             "Content-Length: 29\r\n"  
  454.             "Cache-Control: \r\n"  
  455.             "Origin: \r\n"  
  456.             "User-Agent: \r\n"  
  457.             "Content-Type: \r\n"  
  458.             "Accept: \r\n"  
  459.             "Referer: \r\n"  
  460.             "Accept-Encoding: \r\n"  
  461.             "Accept-Language: \r\n"  
  462.             "Accept-Charset: \r\n"  
  463.             "Cookie: ACCOUNT=%s;\r\n\r\n"  
  464.             "p_qxrxk=0229039&p_qxrxk_kxh=0",acc);  
  465.           
  466.         pock(pg0,7777,0);  
  467.           
  468.         sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  469.             "Host: \r\n"  
  470.             "Proxy-Connection: keep-alive\r\n"  
  471.             "Content-Length: 29\r\n"  
  472.             "Cache-Control: \r\n"  
  473.             "Origin: \r\n"  
  474.             "User-Agent: \r\n"  
  475.             "Content-Type: \r\n"  
  476.             "Accept: \r\n"  
  477.             "Referer: \r\n"  
  478.             "Accept-Encoding: \r\n"  
  479.             "Accept-Language: \r\n"  
  480.             "Accept-Charset: \r\n"  
  481.             "Cookie: ACCOUNT=%s;\r\n\r\n"  
  482.             "p_qxrxk=0329001&p_qxrxk_kxh=3",acc);  
  483.           
  484.         pock(pg0,7777,0);  
  485.         //puts(info);  
  486.         zt2=clock();  
  487.         gotoxy(10,12);  
  488.         printf("%9.2f",((float)(zt2-zt1)/CLOCKS_PER_SEC));  
  489.         paus(TEN);  
  490.           
  491.     }  
  492.       
  493.     free(pg0);  
  494.       
  495.     goto again;  
  496.       
  497.     system("pause");  
  498.     return 0;  
  499. }  
  1. #pragma once  
  2.   
  3. //This is :md5.h  
  4. typedef unsigned short int UINT16;  
  5.   
  6.   
  7. /* MD5 context. */  
  8. typedef struct {  
  9. "white-space:pre">  UINT32 state[4];                                   /* state (ABCD) */  
  10. "white-space:pre">  UINT32 count[2];        /* number of bits, modulo 2^64 (lsb first) */  
  11. "white-space:pre">  unsigned char buffer[64];                         /* input buffer */  
  12. } MD5_CTX;  
  13.   
  14.   
  15. void MD5Init   (MD5_CTX *);  
  16. void MD5Update (MD5_CTX *, unsigned char *, unsigned int);  
  17. void MD5Final  (unsigned char [16], MD5_CTX *);  

花了一天时间,移植到Linux下

  1.   
  1. /*************************************  
  2. //  Powered by c 
  3. //  Written by chen*** 
  4. //  Date:2014.1.4 
  5. //  Run :Linux 
  6. // clear&& gcc -o md5 md5.c -lcrypto&&./md5 
  7. */    
  8. #include     
  9. #include     
  10. #include  
  11. #include  
  12. #include     
  13. #include     
  14. #include     
  15. #include     
  16. #define IP "58.192.142.134"  
  17. #define PORT 7777  
  18.   
  19.   
  20. #define ID "12080310*"  
  21. #define PASSWD "12080310*"  
  22.   
  23.   
  24. #define TEN 1.0  
  25. char info[1115]="";  
  26. char md5[35]="\0";  
  27. void gotoxy(int x,int y)   //Fantasy  
  28. {  
  29.    printf("%c[%d;%df",0x1B,y,x);  
  30. }  
  31. int post(char *sendbuf)    
  32. {    
  33. int cfd;      
  34. int recbytes;    
  35. int sin_size;    
  36. struct sockaddr_in s_add,c_add;   
  37. unsigned short portnum=PORT;  
  38. cfd = socket(AF_INET, SOCK_STREAM, 0);    
  39. if(-1 == cfd)    
  40. {    
  41.     printf("socket fail ! \r\n");    
  42.     return -1;    
  43. }    
  44. bzero(&s_add,sizeof(struct sockaddr_in));    
  45. s_add.sin_family=AF_INET;    
  46. s_add.sin_addr.s_addr= inet_addr(IP);   
  47. s_add.sin_port=htons(portnum);   
  48. if(-1 == connect(cfd,(struct sockaddr *)(&s_add), sizeof(struct sockaddr)))    
  49. {    
  50.     printf("connect fail !\r\n");    
  51.     return -1;    
  52. }    
  53. if(-1 == (recbytes =send(cfd,sendbuf,strlen(sendbuf),0)))   
  54. {    
  55.     printf("read data fail !\r\n");    
  56.     return -1;    
  57. }    
  58. strcpy(info,"");  
  59. recv(cfd, info,1024,0);  
  60. info[recbytes]='\0';    
  61. close(cfd);   
  62. return 0;    
  63. }    
  64. int paus(float time)  
  65. {  
  66. long zt1=clock();  
  67. long zt2;  
  68. while(1)  
  69. {  
  70. zt2=clock();  
  71. if(((float)(zt2-zt1)/CLOCKS_PER_SEC)>time)  
  72. return 0;  
  73. else  
  74. {  
  75. gotoxy(23,2);  
  76. printf("%-9.2f",((float)(zt2-zt1)/CLOCKS_PER_SEC));}  
  77. }  
  78. }  
  79. void information()//Line 3 to 11  
  80. {  
  81. gotoxy(1,3);printf("This is used in a special election for course selection");  
  82. gotoxy(1,4);printf("Running under Linux,compiled by gcc");  
  83. gotoxy(1,5);printf("Yangzhou University");  
  84. gotoxy(1,6);printf("Ten minutes after logging in,try every time interval,a total of three times");  
  85. gotoxy(1,7);printf("Log back in thirty minutes");  
  86. gotoxy(1,8);printf("Run without a screen in card PC");  
  87. gotoxy(1,9);printf("Wake up,the course is completed,the final number is mine");  
  88. gotoxy(1,10);printf("This proof,C language can do anything");  
  89. gotoxy(1,11);printf("I wish the electromagnetic field will not fail");  
  90. }  
  91. int main()  
  92. {  
  93.     int loop;  
  94.     char acc[20];  
  95.     MD5_CTX ctx;  
  96.     unsigned char *data=PASSWD;  
  97.     unsigned char md[16];  
  98.     char tmp[3]={'\0'};  
  99.     int i,j;  
  100. char *pg0;  
  101. float tpause;  
  102. printf("Input time(seconds):");  
  103. scanf("%f",&tpause);  
  104. puts("Waiting...,Now passed            seconds");  
  105. paus(tpause);  
  106. information();  
  107. gotoxy(1,12);  
  108. printf("RunTime is                               seconds\n");  
  109. long zt1=clock();  
  110. long zt2;  
  111.     MD5_Init(&ctx);     
  112.     MD5_Update(&ctx,data,strlen(data));    
  113.     MD5_Final(md,&ctx);   
  114.     for( i=0; i<16; i++ ){  
  115.         sprintf(tmp,"%02X",md[i]);  
  116.         strcat(md5,tmp);  
  117.     }  
  118.     again:  
  119.     pg0=(char *)malloc(1025);  
  120. sprintf(pg0,"GET /pls/wwwbks/bks_login2.uniteLogin?stuid=%s&pwd=%s HTTP/1.1\r\n"  
  121. "Host:\r\n"  
  122. "Proxy-Connection: keep-alive\r\n"  
  123. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"  
  124. "User-Agent: \r\n"  
  125. "Referer:\r\n"  
  126. "Accept-Encoding: deflate\r\n"  
  127. "Accept-Language: zh-CN,zh;q=0.8\r\n"  
  128. "Accept-Charset: gb2312;q=0.7,*;q=0.3\r\n"  
  129. "Cookie: \r\n\r\n",ID,md5);  
  130. post(pg0);  
  131. free(pg0);  
  132. i=j=0;  
  133. while(1){  
  134. while(info[i]!='C')i++;  
  135. if(info[i+3]==info[i+6])break;  
  136. else i++;  
  137. }  
  138. if(info[i+16]!='1'){printf("Wrong and wrong");}  
  139. else  
  140. {  
  141. while(1){  
  142. while(info[i]!='S')i++;  
  143. if(info[i+4]=='C')break;  
  144. else i++;  
  145. }  
  146. j=i;  
  147. while(info[j]!=';')j++;  
  148. info[j]=0;  
  149. strcpy(acc,info+20+i);  
  150. }  
  151. pg0=(char *)malloc(1025);  
  152. for(loop=0;loop<3;loop++)  
  153. {  
  154. sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  155. "Host: \r\n"  
  156. "Proxy-Connection: keep-alive\r\n"  
  157. "Content-Length: 29\r\n"  
  158. "Cache-Control: \r\n"  
  159. "Origin: \r\n"  
  160. "User-Agent: \r\n"  
  161. "Content-Type: \r\n"  
  162. "Accept: \r\n"  
  163. "Referer: \r\n"  
  164. "Accept-Encoding: \r\n"  
  165. "Accept-Language: \r\n"  
  166. "Accept-Charset: \r\n"  
  167. "Cookie: ACCOUNT=%s;\r\n\r\n"  
  168. "p_qxrxk=0329016&p_qxrxk_kxh=6",acc);  
  169. post(pg0);  
  170. sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  171. "Host: \r\n"  
  172. "Proxy-Connection: keep-alive\r\n"  
  173. "Content-Length: 29\r\n"  
  174. "Cache-Control: \r\n"  
  175. "Origin: \r\n"  
  176. "User-Agent: \r\n"  
  177. "Content-Type: \r\n"  
  178. "Accept: \r\n"  
  179. "Referer: \r\n"  
  180. "Accept-Encoding: \r\n"  
  181. "Accept-Language: \r\n"  
  182. "Accept-Charset: \r\n"  
  183. "Cookie: ACCOUNT=%s;\r\n\r\n"  
  184. "p_qxrxk=1029012&p_qxrxk_kxh=0",acc);  
  185. post(pg0);  
  186. sprintf(pg0,"POST /pls/wwwbks/xk.CourseInput HTTP/1.1\r\n"  
  187. "Host: \r\n"  
  188. "Proxy-Connection: keep-alive\r\n"  
  189. "Content-Length: 29\r\n"  
  190. "Cache-Control: \r\n"  
  191. "Origin: \r\n"  
  192. "User-Agent: \r\n"  
  193. "Content-Type: \r\n"  
  194. "Accept: \r\n"  
  195. "Referer: \r\n"  
  196. "Accept-Encoding: \r\n"  
  197. "Accept-Language: \r\n"  
  198. "Accept-Charset: \r\n"  
  199. "Cookie: ACCOUNT=%s;\r\n\r\n"  
  200. "p_qxrxk=1029013&p_qxrxk_kxh=0",acc);  
  201. post(pg0);  
  202. zt2=clock();  
  203. gotoxy(12,12);  
  204. printf("%9.2f",((float)(zt2-zt1)/CLOCKS_PER_SEC));  
  205. paus(TEN);  
  206. }  
  207. free(pg0);  
  208. goto again;  
  209. return 0;  
  210. }  
阅读(907) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~