- 117
- 0
- 约8.73千字
- 约 8页
- 2021-01-20 发布于黑龙江
- 举报
DES加密算法源码
unit DESUnit;
interface
uses SysUtils;
type
TKeyByte = array[0..5] of Byte;
TDesMode = (dmEncry, dmDecry);
function DESEncrypt(Input, Key: String): String;
function DESDecrypt(Input, Key: String): String;
var
subKey: array[0..15] of TKeyByte;
implementation
{$I SBox.inc}
procedure initPermutation(var inData: array of Byte);
var
newData: array[0..7] of Byte;
i: Integer;
begin
FillChar(newData, 8, 0);
for i := 0 to 63 do
if (inData[BitIP[i] shr 3] and (1 shl (7- (BitIP[i] and $07)))) 0 then
newData[i shr 3] := newData[i shr 3] or (1 shl (7-(i and $07)));
for i := 0 to 7 do inData[i] := newData[i];
end;
procedure conversePermutation(var inData: array of Byte);
var
newData: array[0..7] of Byte;
i: Integer;
begin
FillChar(newData, 8, 0);
for i := 0 to 63 do
if (inData[BitCP[i] shr 3] and (1 shl (7-(BitCP[i] and $07)))) 0 then
newData[i shr 3] := newData[i shr 3] or (1 shl (7-(i and $07)));
for i := 0 to 7 do inData[i] := newData[i];
end;
procedure expand(inData: array of Byte; var outData: array of Byte);
var
i: Integer;
begin
FillChar(outData, 6, 0);
for i := 0 to 47 do
if (inData[BitExp[i] shr 3] and (1 shl (7-(BitExp[i] and $07)))) 0 then
outData[i shr 3] := outData[i shr 3] or (1 shl (7-(i and $07)));
end;
procedure permutation(var inData: array of Byte);
var
newData: array[0..3] of Byte;
i: Integer;
begin
FillChar(newData, 4, 0);
for i := 0 to 31 do
if (inData[BitPM[i] shr 3] and (1 shl (7-(BitPM[i] and $07)))) 0 then
newData[i shr 3] := newData[i shr 3] or (1 shl (7-(i and $07)));
for i := 0 to 3 do inData[i] := newData[i];
end;
function si(s,inByte: Byte): Byte;
var
c: Byte;
begin
c := (inByte and $20) or ((inByte and $1e) shr 1) or
((inByte and $01) shl 4);
Result := (sBox[s][c] and $0f);
end;
procedure permutationChoose1(inData: array of Byte;
var outData: array of Byte);
var
i: Integer;
begin
FillChar(outData, 7, 0);
for i := 0 to 55 do
您可能关注的文档
最近下载
- 2025年上海立达学院单招笔试英语试题库含答案解析.docx VIP
- Revit结构BIM正向设计专题讲座.ppt
- (部编版)道德与法治必背八年级上册 思维导图+核心知识点 .pdf VIP
- 2025年上海杉达学院单招笔试英语试题库含答案解析.docx VIP
- 2025年辽宁省大连市中考数学模拟试卷(三).pdf VIP
- 2025年专题生活会对照检查发言材料【四个带头】.docx VIP
- 2026年辽宁省中考数学模拟试卷.doc VIP
- 2025年上海立达学院单招笔试英语试题库含答案解析.docx VIP
- 2025年上海杉达学院单招笔试英语试题库含答案解析.docx VIP
- 雅马哈RXV590/RV901/RXV590RDS功放原理图.pdf VIP
原创力文档

文档评论(0)