Skip navigation.

Linux夜航船

Everything should be easy.

Posts tagged with "Software"

封装SHA1库,顺便更新一下MD5库

, , , ...

MD5库类似,今天封装了个SHA1的库。
/*
* 编译方法
*
* gcc -o sha1test sha1test.c libleosha1.so
* 此方法需要将libleomd5.so复制到系统路径下,例如/usr/lib
*
* gcc -o sha1test sha1test.c ./libleosha1.so
* 此方法需要将libleosha1.so复制到test所在路径下
*
* bayern.leo@gmail.com
*/
int main( int argc, char *argv[] )
{
int i;
for(i=1;i<argc;i++) {
if(i+1<argc) {
if (strcmp(argv,"-s")==0) {
printf("SHA1 for string %s: %s\n",argv[i+1],LeoSHA1(argv[i+1]));
} else if (strcmp(argv,"-f")==0) {
printf("SHA1 for file %s: %s\n",argv[i+1],LeoFileSHA1(argv[i+1]));
}
}
}

return( 0 );
}
MD5-SHA1.tar.bz2

封装一个C语言的MD5共享库

, , , ...

算法的源码用的还是国外前辈的,封装为一个共享库,便于在不同的程序中使用。
测试程序test.c的全部代码如下。
#include <stdio.h>
/*
* 编译方法
*
* gcc -o test test.c libleomd5.so
* 此方法需要将libleomd5.so复制到系统路径下,例如/usr/lib
*
* gcc -o test test.c ./libleomd5.so
* 此方法需要将libleomd5.so复制到test所在路径下
*
* bayern.leo@gmail.com
*/
int main(int argc,char* argv[]) {
int i;
for(i=1;i<argc;i++) {
if(i+1<argc) {
if (strcmp(argv,"-s")==0)
printf("For string %s: %s\n",argv[i+1],MD5(argv[i+1]));
else if (strcmp(argv,"-f")==0)
printf("For file %s: %s\n",argv[i+1],MDFile(argv[i+1]));
}
}

return 0;
}
(2007-4-28有更新)
MD5-SHA1.tar.bz2

两个小程序,带回办公室用

,


这个程序可以对指定窗口切换显示/隐藏状态,可以解决在办公室里一些不好发作的事。

这个程序可以防止有人冒失关机,帮助保证要长时间运行的程序保持运行,针对Window$2000写的,没有作太多测试,丢在办公室里也有一段时间了。
打包下载->Daemon.rar

LeoBase.dll v1.0.2.0 release

, , ,

2LeoBase.rar
本计划四月份告一段落的,还是推迟到今天。这个版本如无大的BUG,就暂且放一边了。
摘要信息如下。

1.0.2.0版新增LStrToFile、LCDROM、LDrIsCDROM,优化了通用串的使用。

//--==1.0.2.0版增加以下函数==--
function LStrToFile(const Str, FileName: PChar; iNum: integer): integer; stdcall;
//字符串存为文件,iNum指定保存的字节数,设为-1时为保存全部,返回值为实际保存的字节数。

function LCDROM(const Dr: PChar; const toOpen: boolean): boolean; stdcall;
//当toOpen为true时,弹出光驱盒,toOpen为false时,关闭光驱盒,Dr为指定光驱盘符。

function LDrIsCDROM(const Dr: PChar): boolean; stdcall;
//检测Dr是否光驱

LeoBase.dll更新

, , ,

2LeoBase.rar

摘要信息如下。

[版本说明]
1.0.0.0版提供了初始26个函数。
1.0.1.0版新增LGBToBig5、LBig5ToGB、LSetWins,优化了LSetReg、LReReplace。

[DEMO程序]
LeoBaseDemoCs.exe (使用C#开发,2006年4月29日更新)

//--==1.0.1.0版增加以下函数==--
function LGBToBig5(const s: PChar): PChar; stdcall;
//简体转换为繁体,须自行判断、处理CHARSET

function LBig5ToGB(const s: PChar): PChar; stdcall;
//繁体转换为简体,须自行判断、处理CHARSET

function LSetWins(const s, newTitle: PChar; const iMod: integer): boolean; stdcall;
//遍历窗口,执行iMod对定的模式对标题包含s的窗口操作:1-窗口标题替换为newTitle,2-关闭窗口,3-隐藏窗口,4-使隐藏的窗口显示

温习DELPHI,封装26个函数

, , ,

LeoBase.dll:此番整理、简化了一些操作字符串、文件等的函数,可能会对某些朋友有handy的方便作用吧,分享出来。
2LeoBase.rar
[函数说明]
function LAuthor: pchar; stdcall;
//返回作者姓名和联系邮箱 :D

function LMD5(const s: pChar): pChar; stdcall;
//返回字符串的MD5值

function LFileMD5(const s: pChar): pChar; stdcall;
//返回文件的MD5值

function LEncrypt(const s, keyStr: pChar): pChar; stdcall;
//对字符串s作可逆加密,keyStr为密钥,调用第二次为解密,使用不同的密钥连续调用可多重加/解密。

function LStrIsMulti(const s: PChar): bool; stdcall;
//判断字符串是否包含多字节字符

function LStrIsIp(const S: pchar): boolean; stdcall;
//判断字符串是否有效的IP地址(格式)

function LDelPort(const S: pchar): pchar; stdcall;
//如果字符串是“domain:port”的形式且port在[0,65536)之间,则返回“domain”,否则原样返回。

function LStrIsEm(const S: pchar): boolean; stdcall;
//判断字符串是否有效的EMAIL地址(格式,宽松匹配)

function LStrIsUrl(const S: pchar): boolean; stdcall;
//判断字符串是否有效的网址(格式,宽松匹配),限定正确格式是以“http://”或“ftp://”开头。

function LAddLink(const s: pChar): pChar; stdcall;
//为字符串中的网址和EMAIL地址加上链接

function LBlockIn(const ps1, ps2: pChar): pchar; stdcall;
//返回ps2中有多少个字符包含于ps1中,并被分为多少个连续的块(字符数+','+块数),块之间不考虑顺序

function LTxtCom(const s1, s2: pChar): real; stdcall;
//返回文本相似度

function LSplit(const sub, s: pChar): tstrings; stdcall;
//返回用sub作为分隔符,对s分割的tstrings(数组)

function LReSplit(const sReSep, s: pChar): tstrings; stdcall;
//LSplit的正则表达式版

function LOccurs(const sub, s: pChar): integer; stdcall;
//返回sub在s中出现的次数

function LReOccurs(const sub, s: PChar): integer; stdcall;
//LOccurs的正则表达式版

function LSeekFile(const sPath, sFile: pChar; const seekSubDir: boolean): tstrings; stdcall;
//返回在目录sPath查找文件名特征为sFile的结果集tstrings,由seekSubDir决定是否深入子目录。

function LReReplace(const FindFor, FindIn, ReplaceWith: pChar): pChar; stdcall;
//正则表达式替换

function LReTest(const re, Str: PChar): bool; stdcall;
//用正则表达式re测试字符串Str,匹配时返回真值

function LEnAlpha(const s: pChar): boolean; stdcall;
//测试字符串是否全为英语字母

function LVersion(const exeFile: PChar): PChar; stdcall;
//返回文件版本号,不能获取版本号时返回“0.0.0.0”

function LExecute(const Target: PChar; const iMod: integer): bool; stdcall;
//执行、打开一个文件(夹),iMod可选1~4:1-正常打开,2-隐藏,3-最大化,4-最小化

function LFileToStr(const F: PChar): PChar; stdcall;
//把文件读入一个串

function LSetReg(const ext, exeFile: PChar): bool; stdcall;
//设置文件关联

function LRanName(const sPath, sPrefix, sExt: PChar; const iLen: integer): PChar; stdcall;
//返回随机且唯一的目录名或文件名,sPath-传入基准目录,sPrefix-前缀,sExt-扩展名,iLen-随机产生部分的长度,不超过32

[示例代码]
1、用C#(.net 2.0)取指定文件版本号->调用LVersion
//代码开始-->
public class LeoBase
{
[DllImport("LeoBase.dll",
EntryPoint = "LVersion",
CallingConvention = CallingConvention.StdCall)]
public static extern String LVersion(String exeFile);
}
private void button1_Click(object sender, EventArgs e)
{
openf.ShowDialog();//选择文件
button1.Text = LeoBase.LVersion(openf.FileName);
}
//<--代码结束

2、用VC++6.0 计算指定文件的MD5值->调用LFileMD5
//代码开始-->
HINSTANCE hDll;
hDll = LoadLibrary("LeoBase.dll");
if (hDll != NULL)
{
CString str;
typedef char *(_stdcall * fromLeoBase)(char *);
fromLeoBase leoFun;
leoFun=(fromLeoBase)GetProcAddress(hDll, "LFileMD5");
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
GetDlgItem(IDC_EDIT2)->SetWindowText(leoFun((LPSTR)(LPCTSTR)str));
FreeLibrary(hDll);
}
//<--代码结束

3、用Delphi搜索目录->调用LSeekFile
//代码开始-->
implementation
{$R *.dfm}
function LSeekFile(const sPath, sFile: pchar; const seekSubDir: Boolean): Tstrings; stdcall;
external 'LeoBase.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Lines.AddStrings(LSeekFile(pchar(Edit1.Text), pchar(Edit2.Text), true));
end;
//<--代码结束
December 2009
S M T W T F S
November 2009January 2010
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 26
27 28 29 30 31