IDEA數據加密算法介紹之續篇,代碼實現:http://blog.csdn.net/CXXSoft/archive/2006/08/23/110927" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

IDEA數據加密算法實現

系統 2182 0
<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog01.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>

IDEA數據加密算法介紹之續篇,代碼實現:
http://blog.csdn.net/CXXSoft/archive/2006/08/23/1109279.aspx

5、 源碼:

// *******************************************************************************
* IDEA數據加密算法1.0版本
* 開發作者:成曉旭
* 項目簡述:IDEA數據加密算法1.0版本
* 啟動時間:2000年05月08日
* 完成時間:2000年01月14日 20 : 09 : 00 1個晚上 >
*
* 開發環境:Windows98
* 開發工具:BorlandDelphi5
*
* 文件名稱:IDEA.pas
* 簡介:IDEA數據加密算法1.0版本
*
* 備注:任何人使用此文件時,請保留此段自述文件,謝謝 !
*
******************************************************************************/
unitIDEA;

interface

uses
Windows,Messages,SysUtils,Classes,Dialogs;
functionBinToHex(strBin:string):string;
functionHexToTen(strHex:string):int64;
functionLeftMove(S:string;P:integer):String;
functionModAdd(intAdd1,intAdd2:int64):int64;
functionModMul(intMul1,intMul2:int64;intFlag:integer):int64;
functionModXor(intXor1,intXor2:int64):int64;
procedureCreatePassword(strPassword:string;VARarrPassword:arrayofint64;VARarrOpenPassword:arrayofint64);
// 產生加密子密鑰函數
procedureGetOpenPassword(intSource:int64;VARintResult:int64;Flag:integer); // 求取解密子密鑰函數
procedureCreateKeyTable(); // 產生加、解密子密鑰之間的對應關系表
procedureRiddle(arrPassword:arrayofint64;arrRiddleKey:arrayofint64;VARarrOpenPassword:arrayofint64);StdCall;export; // IDEA數據解密函數
procedureCreateOpenPassword(VARarrOpenPassKey:arrayofint64); // 產生解密子密鑰函數
procedureCreateKey(VARarrKey:arrayofint64;VARarrOpenKey:arrayofint64;VARstrOutKey:string);StdCall;export; // 產生加密密鑰函數


implementation

ConststrNum:array[
1 .. 16 ]ofstring[ 4 ] = ( ' 0000 ' , ' 0001 ' , ' 0010 ' , ' 0011 ' , ' 0100 ' , ' 0101 ' , ' 0110 ' , ' 0111 ' , ' 1000 ' , ' 1001 ' , ' 1010 ' , ' 1011 ' , ' 1100 ' , ' 1101 ' , ' 1110 ' , ' 1111 ' );
ConstchrHex:array[
1 .. 16 ]of char = ( ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' );
var
g_arr_Ten_Password:array[
1 .. 52 ]ofint64;
g_arr_Flag:array[
1 .. 52 ]ofinteger;
g_arr_Table:array[
1 .. 52 ]ofinteger;
... { -------------------------------------------------------------------- }

procedureCreateKey(VARarrKey:arrayofint64;VARarrOpenKey:arrayofint64;VARstrOutKey:string);StdCall;export;
var
intKey,intLoop1,intLoop2,intLoop3:integer;
hexKey,ch,strTemp:string;
strKey:string[
128 ];
begin
strKey:
= '' ;
Randomize;
for intLoop1: = 1 to 8 do
begin
intKey:
= Random( 65536 );
hexKey:
= IntToHex(intKey, 4 );
strTemp:
= '' ;
for intLoop2: = 1 to 4 do
begin
ch:
= Copy(hexKey,intLoop2, 1 );
for intLoop3: = 1 to 16 do
begin
if ch = chrHex[intLoop3]then
begin
ch:
= strNum[intLoop3];
break ;
end;
end;
strTemp:
= strTemp + ch;
end;
strKey:
= strKey + strTemp;
end;
strOutKey:
= strKey;
CreatePassword(strKey,arrKey,arrOpenKey);
// 調用產生加密子密鑰過程
end;
... { -------------------------------------------------------------------- }

functionBinToHex(strBin:string):string;
var
intLoop1,intLoop2:integer;
strTemp,strResult:string;
begin
intLoop1:
= 1 ;
strResult:
= '' ;
if Length(strBin) 16 thenShowMessage( ' 二進制數據長度有錯! ' );
while (intLoop1 16 ) do
begin
strTemp:
= Copy(strBin,intLoop1, 4 );
for intLoop2: = 1 to 16 do
if strTemp = strNum[intLoop2]then
begin
strTemp:
= chrHex[intLoop2];
break ;
end;
strResult:
= strResult + strTemp;
intLoop1:
= intLoop1 + 4 ;
end;
BinToHex:
= strResult;
end;
... { -------------------------------------------------------------------- }

functionHexToTen(strHex:string):int64;
// 十六進制轉十進制
var
intLoop1,intLoop2,intTemp:integer;
intResult:int64;
strTemp:string;
begin
intResult:
= 0 ;
intTemp:
= 0 ;
if Length(strHex) 4 thenShowMessage( ' 十六進制數據長度有錯! ' );
for intLoop1: = 1 to 4 do
begin
CaseintLoop1of
1 :intTemp: = 4096 ;
2 :intTemp: = 256 ;
3 :intTemp: = 16 ;
4 :intTemp: = 1
end;
strTemp:
= Copy(strHex,intLoop1, 1 );
for intLoop2: = 1 to 16 do
if UpperCase(strTemp) = chrHex[intLoop2]then
begin
intResult:
= intResult + (Int64(intLoop2) - 1 ) * Int64(intTemp);
break ;
end;
end;
HexToTen:
= intResult;
end;
... { -------------------------------------------------------------------- }

functionLeftMove(S:string;P:integer):String;
var
int_Len,i:integer;
str_Result,str_Num:string;
begin
int_Len:
= length(s);
str_Num:
= S;
str_Result:
= '' ;
if int_Len Pthen
str_Result:
= S
else
begin
for i: = P + 1 toint_Len do
str_Result:
= str_Result + copy(str_Num,i, 1 );
str_Result:
= str_Result + copy(str_Num, 1 ,p);
end;
LeftMove:
= Trim(str_Result);
end;
... { -------------------------------------------------------------------- }

functionModAdd(intAdd1,intAdd2:int64):int64;
begin
ModAdd:
= (intAdd1 + intAdd2)mod 65536 ; // 模65536求和
end;

functionModMul(intMul1,intMul2:int64;intFlag:integer):int64;
varintTemp:int64;
begin
intTemp:
= (intMul1 * intMul2)mod 65537 ;
if intFlag = 0 then
begin
if intMul1 = 0 thenintTemp: = 65537 - intMul2;
if intMul2 = 0 thenintTemp: = 65537 - intMul1;
if intTemp = 65536 thenintTemp: = 0 ;
if intTemp = 65537 thenintTemp: = 1 ;
end
else
begin
if intMul1 = 0 thenintTemp: = 65537 - intMul2;
if intMul2 = 0 thenintTemp: = 65537 - intMul1;
if intTemp = 0 thenintTemp: = 65536 ;
if intTemp = 65537 thenintTemp: = 1 ;
if intTemp = 65536 thenintTemp: = 0 ;
end;
ModMul:
= intTemp;
end;

functionModXor(intXor1,intXor2:int64):int64;
begin
ModXor:
= intXor1xorintXor2;
end;
... { -------------------------------------------------------------------- }

procedureCreatePassword(strPassword:string;VARarrPassword:arrayofint64;VARarrOpenPassword:arrayofint64);
var
strKey:string;
strTemp:array[
1 .. 52 ]ofstring[ 4 ];
intStart,intCount:integer;
begin
strKey:
= strPassword; //
intCount: = 1 ;
intStart:
= 1 ;
... { -------------------- 產生52個16bit的加密子密鑰部分 ------------------- }
while (intCount 52 ) do
begin
strTemp[intCount]:
= BinToHex(Copy(strKey,intStart, 16 ));
intStart:
= intStart + 16 ;
intCount:
= intCount + 1 ;
if ((intCountmod 8 ) = 1 )then
begin
strKey:
= LeftMove(strKey, 25 );
intStart:
= 1 ;
end;
end;
intCount:
= 1 ;
while (intCount 52 ) do
begin
arrPassword[intCount
- 1 ]: = HexToTen(strTemp[intCount]);
g_arr_Ten_Password[intCount]:
= arrPassword[intCount - 1 ];
intCount:
= intCount + 1 ;
end;
CreateOpenPassword(arrOpenPassword);
... { -------------------- 產生52個16bit的加密子密鑰部分 ------------------- }
end;
... { -------------------------------------------------------------------- }

procedureGetOpenPassword(intSource:int64;VARintResult:int64;Flag:integer);
var
int_Source,int_Result,int_Mod_Value:int64;
int_Loop:integer;
begin
int_Source:
= intSource;
... { -------------------- 求取每個加密子密鑰相應的解密子密鑰部分 ------------------- }
CaseFlagof
0 :intResult: = int_Source;
1 :intResult: = 65536 - int_Source;
2 :
begin
if int_Source = 0 then
intResult:
= int_Source
else
for int_Loop: = 1 to 65536 do
begin
int_Result:
= Int64(int_Loop) * 65537 + 1 ;
int_Mod_Value:
= int_Resultmodint_Source;
if int_Mod_Value = 0 then
begin
int_Result:
= int_Resultdivint_Source;
intResult:
= int_Result;
break ;
en
分享到:
評論
happmaoo
  • 瀏覽: 1292487 次
  • 性別: Icon_minigender_1
  • 來自: 杭州
最新評論

IDEA數據加密算法實現


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色婷婷在线播放 | 日韩a在线看免费观看视频 五月天激情视频在线观看 成人97在线观看免费高清 | 日本黄色大片免费 | 日本欧美一区二区三区不卡视频 | 97超级碰碰碰视频在线视频观看 | 国产99久久精品一区二区永久免费 | 日韩乱轮| 亚洲精品一区在线观看 | 性XXXX18精品A片一区二区 | 国精品一区 | 好看的中文字幕在线 | 2021国产成人综合亚洲精品 | 99自拍视频在线观看 | 亚洲福利片 | 免费看h网站 | 亚洲欧洲精品成人久久曰影片 | 91精品啪在线观看国产91九色 | 欧美日韩成人一区二区 | 婷五月综合 | 成年视频网站免费观看 | 成人午夜视频网站 | 99久草| 小明成人永久视频在线观看 | 亚洲成人综合视频 | 亚洲欧美中文日韩在线v日本 | 国产亚洲一区二区三区在线观看 | 亚洲a网| 99re视频 | 日韩精品在线一区 | 亚洲精品无码国产爽快A片百度 | 欧美大黑bbb| 亚洲精品国产一区 | 国产亚洲欧美日韩v在线 | 99久久免费费视频在线观看 | 99热这里只有精品8 免费看搡女人的视频 | 国产成人激情视频 | 另类视频综合 | 成人精品视频在线观看 | 99av.com | 黄色免费av | 日韩视频在线精品视频免费观看 |