1. 程式人生 > >72.挖掘CSDN密碼到鏈表並統計密碼出現次數生成密碼庫

72.挖掘CSDN密碼到鏈表並統計密碼出現次數生成密碼庫

sca ret open word pac 要求 i++ 密碼 tsp

  • list.h
     1 #define  _CRT_SECURE_NO_WARNINGS
     2 #include <stdio.h>
     3 #include <stdlib.h>
     4 #include <string.h>
     5 
     6 //創建密碼結點
     7 typedef struct passinfo
     8 {
     9     //密碼
    10     char password[20];
    11     //出現次數
    12     int ci;
    13     //下一個節點
    14     struct passinfo *pNext;
    15 }INFO, *PINFO;
    
    16 17 //頭部插入 18 PINFO addback(PINFO phead, char password[20]); 19 //按照次數排序 20 PINFO sortbyci(PINFO phead); 21 //按照密碼排序 22 PINFO sortbypass(PINFO phead); 23 //顯示數據 24 PINFO show(PINFO phead); 25 //判斷存在與否 26 int isin(PINFO phead, char password[20]); 27 //寫入到文件 28 void writetofile(PINFO phead, char path[100]);

  • list.c
      1
    #include "list.h" 2 3 //頭部插入 4 PINFO addback(PINFO phead, char password[20]) 5 { 6 //開辟內存 7 PINFO pnew = calloc(1, sizeof(INFO)); 8 //拷貝密碼 9 strcpy(pnew->password, password); 10 //初始化 11 pnew->ci = 1; 12 pnew->pNext = NULL; 13 //如果頭結點為空直接插入 14 if
    (phead ==NULL) 15 { 16 phead = pnew; 17 } 18 //否則頭部插入 19 else 20 { 21 pnew->pNext = phead; 22 phead = pnew; 23 } 24 return phead; 25 } 26 27 //按照密碼次數排序 28 PINFO sortbyci(PINFO phead) 29 { 30 //冒泡排序法,一共冒泡這麽多次 31 for (PINFO p1 = phead; p1 != NULL;p1=p1->pNext) 32 { 33 for (PINFO p2 = phead; p2 != NULL; p2 = p2->pNext) 34 { 35 if (p2->pNext!=NULL) 36 { 37 //如果次數小則進行交換 38 if (p2->ci < p2->pNext->ci) 39 { 40 //交換數據 41 int citemp = p2->ci; 42 p2->ci = p2->pNext->ci; 43 p2->pNext->ci = citemp; 44 45 char passtemp[100]; 46 strcpy(passtemp, p2->password); 47 strcpy(p2->password, p2->pNext->password); 48 strcpy(p2->pNext->password, passtemp); 49 } 50 } 51 } 52 } 53 } 54 55 //按照密碼排序 56 PINFO sortbypass(PINFO phead) 57 { 58 //冒泡排序 59 for (PINFO p1 = phead; p1 != NULL; p1 = p1->pNext) 60 { 61 for (PINFO p2 = phead; p2 != NULL; p2 = p2->pNext) 62 { 63 if (p2->pNext != NULL) 64 { 65 if (strcmp(p2->password, p2->pNext->password) < 0) 66 { 67 //交換數據 68 int citemp = p2->ci; 69 p2->ci = p2->pNext->ci; 70 p2->pNext->ci = citemp; 71 72 char passtemp[100]; 73 strcpy(passtemp, p2->password); 74 strcpy(p2->password, p2->pNext->password); 75 strcpy(p2->pNext->password, passtemp); 76 77 } 78 } 79 } 80 } 81 } 82 83 //顯示數據 84 PINFO show(PINFO phead) 85 { 86 if (phead==NULL) 87 { 88 return; 89 } 90 else 91 { 92 printf("%s,%d\n", phead->password, phead->ci); 93 show(phead->pNext); 94 } 95 return phead; 96 } 97 98 //判斷密碼是否存在 99 int isin(PINFO phead, char password[20]) 100 { 101 PINFO p = phead; 102 while (p!=NULL) 103 { 104 if (strcmp(p->password,password)==0) 105 { 106 p->ci += 1; 107 return 1; 108 } 109 p = p->pNext; 110 } 111 112 return 0;//不在鏈表內部 113 } 114 115 //寫入到文件 116 void writetofile(PINFO phead, char path[100]) 117 { 118 FILE *pf = fopen(path, "w"); 119 PINFO p = phead; 120 while (p != NULL) 121 { 122 //格式化打印到文件 123 fprintf(pf, "%s %d\n", p->password, p->ci); 124 p = p->pNext; 125 } 126 fclose(pf); 127 }

  • main.c
     1 #include "list.h"
     2 #include <Windows.h>
     3 PINFO phead = NULL;
     4 
     5 //是否滿足格式要求   賬號 # 密碼 # 郵箱
     6 int isoktosscanf(char *str)
     7 {
     8     //判斷是否存在#
     9     char *p = strstr(str, "#");
    10     if (p!=NULL)
    11     {
    12         //繼續判斷是否存在第二個#
    13         if (strstr(p+1,"#")!=NULL)
    14         {
    15             return 1;
    16         } 
    17         else
    18         {
    19             return 0;
    20         }
    21     }
    22     else
    23     {
    24         return 0;
    25     }
    26 }
    27 
    28 //消除空格
    29 void eatspace(char *str)
    30 {
    31     //當前位置
    32     int i = 0;
    33     //遊標
    34     int j = 0;
    35     //雙指針錯位
    36     while ((str[i]=str[j++])!=\0)
    37     {
    38         if (str[i]!= )
    39         {
    40             i++;
    41         }
    42     }
    43 }
    44 
    45 //文件載入
    46 void fileload()
    47 {
    48     //打開文件
    49     FILE *pf = fopen("csdn.txt", "r");
    50 
    51     //如果沒有到文件末尾
    52     while (!feof(pf))
    53     {
    54         char str[100] = { 0 };
    55         char password[100] = { 0 };
    56         //從文件中獲取一行
    57         fgets(str, 100, pf);
    58         //找到第一個#的位置
    59         char*p1 = strstr(str, "#");
    60         //找到第二個#的位置
    61         char*p2 = strstr(p1+1, "#");
    62         //分別設置成‘\0‘
    63         *p1 = \0;
    64         *p2 = \0;
    65         //拷貝字符串
    66         strcpy(password, p1 + 1);
    67         //消除空格
    68         eatspace(password);
    69         //判斷是否在鏈表中
    70         if (isin(phead, password) == 0)
    71         {
    72             //添加到頭結點
    73             phead = addback(phead, password);
    74         }
    75     }
    76     fclose(pf);
    77 
    78     //按密碼次數排序
    79     sortbyci(phead);
    80     //寫入到文件
    81     writetofile(phead, "C:\\ci.txt");
    82     //按照密碼相似度排序
    83     sortbypass(phead);
    84     //寫入到文件
    85     writetofile(phead, "C:\\pass.txt");
    86 }
    87 
    88 //main函數
    89 void main4()
    90 {
    91     fileload();
    92     system("pause");
    93 }

72.挖掘CSDN密碼到鏈表並統計密碼出現次數生成密碼庫