酷狗.Krc加密歌词解析

 1 function KrcToLrc(filename: string): string;

 2   function ZDecompressStr2(const S: TBytes): UTF8String;

 3   var

 4     BIn, BOut: TBytes;

 5   begin

 6     BIn := S;

 7     ZDecompress(BIn, BOut);

 8     Result := TEncoding.UTF8.GetString(BOut);

 9   end;

10 

11 const

12     miarry: array [0 .. 15] of Char = ('@', 'G', 'a', 'w', '^', '2', 't', 'G',

13     'Q', '6', '1', '-', 'Î', 'Ò', 'n', 'i');

14 var

15   Stream: TFileStream;

16   Top: array [0 .. 3] of byte;

17   k, j, l: Integer;

18   zip_byte: TBytes;

19   FileNameBuff: string;

20 begin

21   FileNameBuff := ExtractFileExt(LowerCase(filename));

22   if FileNameBuff <> '.krc' then begin

23     result:='';

24     Exit;

25   end;

26 

27   Stream := TFileStream.Create(filename, fmOpenReadWrite);

28   try

29     j := Stream.SIZE;

30     SetLength(zip_byte, j - 4);

31     Stream.read(Top, 4);

32     Stream.read(zip_byte, j - 4);

33   finally

34     Stream.Free;

35   end;

36 

37   for k := Low(zip_byte) to High(zip_byte) do begin

38     l := k mod 16;

39     zip_byte[k] := zip_byte[k] xor byte(miarry[l]);

40   end;

41 

42   result:= ZDecompressStr2(zip_byte);

43 

44  end;

对应的Delphi版本为Unicode版本  D7的Ansi版本不使用,添加System.Zlib即可使用

酷狗的异或加密串是从一位JAVA那边得到的

Top4字符是加密文件头,用于校验

Zip_byte是正文

你可能感兴趣的:(加密)