用Delphi制作文本文档程序,在文本中内容加密,我的思路是把文本内容打成乱码,在点击“解密”变回原来的

用Delphi制作文本文档程序,在文本中内容加密,我的思路是把文本内容打成乱码,在点击“解密”变回原来的,第1张

我以前也做过这种小程序。这个算法你可以自己设计,也可以用像什么MD5之类的加解密算法咯。

但因为不能粘贴附件,所以就贴点代码。

procedure TForm1N2Click(Sender: TObject);//打开文件

var

tl:string;

begin

if OpenDialog1Execute then

begin

ListBox1Clear;

Caption:='文件加密解密器'+OpenDialog1FileName;

AssignFile(ATextFile,OpenDialog1FileName);

Reset(ATextFile);

while not eof(ATextFile) do

begin

Readln(ATextFile,tl);

ListBox1ItemsAdd(tl);

end;

CloseFile(ATextFile);

end;

end;

function Encode(s:string):string;//加密的核心部分

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(ord(s[i])+10);

end;

Encode:=str;

end;

function Decode(s:string):string;//解密的核心部分

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(ord(s[i])-10);

end;

Decode:=str;

end;

procedure TForm1N3Click(Sender: TObject);//加密

var

ln:integer;

tl,nl:string;

begin

if SaveDialog1Execute then

begin

AssignFile(ATextFile,SaveDialog1FileName);

Rewrite(ATextFile);

for ln:=0 to ListBox1ItemsCount-1 do

begin

tl:=ListBox1Items[ln];

nl:=Encode(tl);//加密

Writeln(ATextFile,nl);

end;

CloseFile(ATextFile);

end;

end;

procedure TForm1N4Click(Sender: TObject);//解密

var

ln:integer;

tl,nl:string;

begin

if SaveDialog1Execute then

begin

AssignFile(AtextFile,SaveDialog1FileName);

Rewrite(ATextFile);

for ln:=0 to ListBox1ItemsCount-1 do

begin

tl:=ListBox1Items[ln];

nl:=Decode(tl);//解密

Writeln(ATextFile,nl);

end;

CloseFile(ATextFile);

end;

end;

微信小程序内嵌webview,部分安卓机型无法打开h5界面,h5地址格式为:>

std::string base64Decode(const char Data, int DataByte)

{

//解码表

const char DecodeTable[] =

{

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

62, // '+'

0, 0, 0,

63, // '/'

52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // '0'-'9'

0, 0, 0, 0, 0, 0, 0,

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,

13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // 'A'-'Z'

0, 0, 0, 0, 0, 0,

26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,

39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // 'a'-'z'

};

//返回值

std::string strDecode;

int nValue;

int i = 0;

while (i < DataByte)

{

if (Data != '\r' && Data != '\n')

{

nValue = DecodeTable[Data++] << 18;

nValue += DecodeTable[Data++] << 12;

strDecode += (nValue & 0x00FF0000) >> 16;

if (Data != '=')

{

nValue += DecodeTable[Data++] << 6;

strDecode += (nValue & 0x0000FF00) >> 8;

if (Data != '=')

{

nValue += DecodeTable[Data++];

strDecode += nValue & 0x000000FF;

}

}

i += 4;

}

else// 回车换行,跳过

{

Data++;

i++;

}

}

return strDecode;

}

std::string base64Encode(const unsigned char Data, int DataByte)

{

//编码表I have received

const char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

//返回值

std::string strEncode;

unsigned char Tmp[4] = { 0 };

int LineLength = 0;

for (int i = 0; i < (int)(DataByte / 3); i++)

{

Tmp[1] = Data++;

Tmp[2] = Data++;

Tmp[3] = Data++;

strEncode += EncodeTable[Tmp[1] >> 2];

strEncode += EncodeTable[((Tmp[1] << 4) | (Tmp[2] >> 4)) & 0x3F];

strEncode += EncodeTable[((Tmp[2] << 2) | (Tmp[3] >> 6)) & 0x3F];

strEncode += EncodeTable[Tmp[3] & 0x3F];

if (LineLength += 4, LineLength == 76) { strEncode += ""; LineLength = 0; }

}

//对剩余数据进行编码

int Mod = DataByte % 3;

if (Mod == 1)

{

Tmp[1] = Data++;

strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];

strEncode += EncodeTable[((Tmp[1] & 0x03) << 4)];

strEncode += "==";

}

else if (Mod == 2)

{

Tmp[1] = Data++;

Tmp[2] = Data++;

strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];

strEncode += EncodeTable[((Tmp[1] & 0x03) << 4) | ((Tmp[2] & 0xF0) >> 4)];

strEncode += EncodeTable[((Tmp[2] & 0x0F) << 2)];

strEncode += "=";

}

return strEncode;

}

std::string Mat2Base64(const cv::Mat &img, std::string imgType)

{

//Mat转base64

std::string img_data;

std::vector<uchar> vecImg;

std::vector<int> vecCompression_params;

vecCompression_paramspush_back(CV_IMWRITE_JPEG_QUALITY);

vecCompression_paramspush_back(90);

imgType = "" + imgType;

cv::imencode(imgType, img, vecImg, vecCompression_params);

img_data = base64Encode(vecImgdata(), vecImgsize());

return img_data;

}

cv::Mat Base2Mat(std::string &base64_data)

{

cv::Mat img;

std::string s_mat;

s_mat = base64Decode(base64_datadata(), base64_datasize());

std::vector<char> base64_img(s_matbegin(), s_matend());

img = cv::imdecode(base64_img, CV_LOAD_IMAGE_COLOR);

return img;

}

以上就是关于用Delphi制作文本文档程序,在文本中内容加密,我的思路是把文本内容打成乱码,在点击“解密”变回原来的全部的内容,包括:用Delphi制作文本文档程序,在文本中内容加密,我的思路是把文本内容打成乱码,在点击“解密”变回原来的、微信小程序内嵌webview,部分安卓机型无法打开h5界面、mat文件可以包含string类型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9802914.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存