日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

35. 通过实现一个序列加密的功能,熟悉对二维空间与一维空间的操作。

發布時間:2024/1/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 35. 通过实现一个序列加密的功能,熟悉对二维空间与一维空间的操作。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.



按行讀的話,肯定可以讀出數據,如果按列來讀的話,則會出再亂碼的現像。正
是這種現像可作為一種加密手段,稱為序列加密。
hello everyone? 原始序列
可以看成
hello_
everyo
ne****

按列提取
hen
eve
le*
lr*
oy*
_o*

henevele*lr*oy*_o*? ?此時就為加密后的序列


現在實現加密與解密的功能:

1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 char* encode(char* str,int col) 5 { 6 int i,j; 7 int strLen = strlen(str); 8 int bufLen = strLen + col - strLen%col; 9 10 char* strBuf = malloc(bufLen+1);//線性一維空間,存儲完原始數據后之后當成二維空間使用 11 strcpy(strBuf,str); 12 // char* pbuf = buf; 13 for(i = strLen;i < bufLen;i++) 14 { 15 *(strBuf+i) = '*';//strBuf[i] = '*'; 16 } 17 *(strBuf+i) = '\0'; 18 19 20 //將原始字符串行列置反存儲到新空間 21 char* newStrBuf = malloc(bufLen+1); 22 char* pNewStrBuf = newStrBuf; 23 char (*pStrBuf)[col] = strBuf;//二維方式訪問strBuf, 24 for(j = 0;j < col;j++)//按順序訪問原始數據中每列上的所有行 25 { 26 for(i = 0;i<bufLen/col;i++) 27 { 28 *pNewStrBuf++ = pStrBuf[i][j]; 29 } 30 } 31 *pNewStrBuf = '\0'; 32 33 34 free(strBuf); 35 return newStrBuf; 36 } 37 38 char* encode2(char* str,int col) 39 { 40 int i,j; 41 int strLen = strlen(str); 42 int bufLen = strLen + col - strLen%col; 43 44 char* strBuf = malloc(bufLen);//線性一維空間,存儲完原始數據后之后當成二維空間使用 45 strcpy(strBuf,str); 46 // char* pbuf = buf; 47 for(i = strLen;i < bufLen;i++) 48 { 49 *(strBuf+i) = '*';//strBuf[i] = '*'; 50 } 51 // *(strBuf+i) = '\0'; 52 53 54 //將原始字符串行列置反存儲到新空間 55 char* newStrBuf = malloc(bufLen+1); 56 char* pNewStrBuf = newStrBuf; 57 char (*pStrBuf)[col] = strBuf;//二維方式訪問strBuf, 58 for(j = 0;j < col;j++)//按順序訪問原始數據中每列上的所有行 59 { 60 for(i = 0;i<bufLen/col;i++) 61 { 62 *pNewStrBuf++ = pStrBuf[i][j]; 63 } 64 } 65 *pNewStrBuf = '\0'; 66 67 68 free(strBuf); 69 return newStrBuf; 70 } 71 72 73 char* decode(char *str, int row) 74 { 75 int bufLen = strlen(str); 76 char* buf = malloc(bufLen+1); 77 78 79 int i,j; 80 int col = (bufLen)/row;//計算出新的原始數據的列 81 82 char (*pStr)[col] = str; 83 char *pBuf = buf; 84 for(j = 0;j < col ;j++) 85 { 86 for(i = 0;i < row;i++) 87 { 88 *pBuf++ = pStr[i][j]; 89 } 90 } 91 *pBuf = '\0';//這句可有可無 92 93 //去*操作 94 while(*(--pBuf) =='*'); 95 *(++pBuf) = '\0'; 96 97 98 99 return buf; 100 101 } 102 103 int main(void) 104 { 105 // int code = 6; 106 char str[] = "hello everyone"; 107 108 char* pe = encode(str,6); 109 printf("%s\n",pe); 110 char* pd = decode(pe,6); 111 printf("%s\n",pd); 112 113 free(pe); 114 free(pd); 115 116 117 return 0; 118 }

?





?h?e?l?l?o??e?v?e?r?y?o?n?e?0???
?0??1??2??3??4??5??6??7??8??9?1011121314151617




?h??e??l??l??o??e?v?e?r?y?o?n?e?0?*??*?*??0
?0?1?2??3??4?5??6??7??8??9?101112131415161718

?



?h??e??l??l??o?? ?
?e?v?e??r??y?o
?n?e?*?*?*?*



? 0? ? ?

轉載于:https://www.cnblogs.com/ZhuLuoJiGongYuan/p/9494860.html

總結

以上是生活随笔為你收集整理的35. 通过实现一个序列加密的功能,熟悉对二维空间与一维空间的操作。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。