第八周專案4 字串加密

2021-07-24 03:02:20 字數 2461 閱讀 1187

/*

*檔名稱:zifuchuanjiami.cpp

*完成日期:2023年10月27日

*版本號:vc++6.0

**問題描述:字串加密

*輸入描述:一組字元

*程式輸出:加密後的字元*/

[cpp]view plain

copy

#ifndef head_h_included

#define head_h_included

#include 

#include 

#define maxsize 100

typedef

struct

sqstring;  

void

strassign(sqstring &s,

char

cstr);    

//字串常量cstr賦給串s

void

strcopy(sqstring &s,sqstring t);   

//串t複製給串s

bool

strequal(sqstring s,sqstring t); 

//判串相等

intstrlength(sqstring s);  

//求串長

sqstring concat(sqstring s,sqstring t);  //串連線

sqstring substr(sqstring s,int

i,int

j); 

//求子串

sqstring insstr(sqstring s1,int

i,sqstring s2); 

//串插入

sqstring delstr(sqstring s,int

i,int

j) ;   

//串刪去

sqstring repstr(sqstring s,int

i,int

j,sqstring t);     

//串替換

void

dispstr(sqstring s);   

//輸出串

sqstring unencrypt(sqstring q);  

sqstring encrypt(sqstring p);  

#endif // head_h_included

[cpp]view plain

copy

#include "head.h"

intmain()    

[cpp]view plain

copy

#include "head.h"

#include

void

strassign(sqstring &s,

char

cstr)  

//´®->´®

void

strcopy(sqstring &s,sqstring t)  

bool

strequal(sqstring s,sqstring t)  

return

true

;  }  

intstrlength(sqstring s)  

//串的連線

sqstring concat(sqstring s,sqstring t)  

//求子串

sqstring substr(sqstring s,int

i,int

j)  

str.length=j;  

return

str;  

}  //串的插入

sqstring insstr(sqstring s1,int

i,sqstring s2)  

//刪除子串

sqstring delstr(sqstring s,int

i,int

j)  

//串的替換

sqstring repstr(sqstring s,int

i,int

j,sqstring t)  

void

dispstr(sqstring s)  

}  sqstring encrypt(sqstring p)  

q.length=p.length;  

return

q;  

}  sqstring unencrypt(sqstring q)  

p.length=q.length;  

return

p;  

}  

執行結果:

知識點總結:

解密的思路也與加密的思路相同。

第八周 專案4 字串加密

檔名稱 main.cpp 作者 王超 完成日期 2015年10月23日 問題描述 字串加密 include include sqstring.h sqstring a,b 用於儲存字元對映表 sqstring encrypt sqstring p q.length p.length return q...

第八周專案4 字串加密

檔名稱 h1.cpp 完成日期 2015年10月26日 版本號 vc6.0 問題描述 設計乙個程式,實現加密 解密演算法,將輸入的文字進行加密後輸出,然後進行解密並輸出。輸入描述 加密檔案 程式輸出 加密 解密的結果 include include define maxsize 100 最多的字元個...

第八周 專案4 字串加密

問題描述 乙個文字串可用事先編制好的字元對映表進行加密。例如,設字元對映表為 abcdefghijklmnopqrstuvwxyz ngzqtcobmuhelkpdawxfyivrsj 則字串 lao he jiao shu ju jie gou 被加密為 enp bt umnp xby uy um...