zoukankan      html  css  js  c++  java
  • rc4加密

    function RC4(Expression, Password: string): string;
    var
    RB : array[0..255of Integer;
    X, Y, Z: longint;
    Key : array of byte;
    ByteArray : array of Word;//原来delphi 7下面 是 byte;
    Temp: byte;
    Counter: integer;
    begin
      If (Length(Expression) = 0then Exit;
      If (Length(Password) = 0then Exit;
      If (Length(Password) > 256then begin
        Password := Copy(Password, 1256);
      end;
      SetLength(Key, Length(Password));
      for Counter := 0 to Length(Password) - 1 do
      begin
        Key[Counter] := ord(Password[Counter + 1]);
      end;
      for X := 0 to 255 do
      begin
        RB[X] := X;
      end;
      X := 0;
      Y := 0;
      Z := 0;
      for X := 0 to 255 do
      begin
        Y := (Y + RB[X] + Key[X mod Length(Password)]) mod 256;
        Temp := RB[X];
        RB[X] := RB[Y];
        RB[Y] := Temp;
      end;
      X := 0;
      Y := 0;
      Z := 0;
      SetLength(ByteArray, Length(Expression));
      for Counter := 0 to Length(Expression) - 1 do
      begin
        ByteArray[Counter] := ord(Expression[Counter + 1]);
      end;
      for X := 0 to Length(Expression) do
      begin
        Y := (Y + 1mod 256;
        Z := (Z + RB[Y]) mod 256;
        Temp := RB[Y];
        RB[Y] := RB[Z];
        RB[Z] := Temp;
        ByteArray[X] := ByteArray[X] xor (RB[(RB[Y] + RB[Z]) mod 256]);
      end;
      for Counter := 0 to Length(Expression) - 1 do
      begin
        Result := Result + chr(ord(ByteArray[Counter]));
      end;
    end;
  • 相关阅读:
    P1443 马的遍历
    P1747 好奇怪的游戏
    蜀绣
    Five hundred miles
    如果没有你
    Yellow
    流星

    深入理解计算机中的 csapp,h和csapp.c
    可迭代的集合类型使用foreach语句
  • 原文地址:https://www.cnblogs.com/onionhacker/p/3533641.html
Copyright © 2011-2022 走看看