DES加密算法(Delphi源码).docVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档