Q&A

  • 델파이 자료실에 있는 암호화 소스관련 질문입니다.
델파이 자료실에 있는 암호화 소스중 Black}{ole  님께서 제작하신 암호화소스2의 소스를 보고 있는데요.

암호화하는 부분에...

procedure Crypt( cString : PChar );
var
  nStringLen   : Integer;
  nCharCount : Integer;
  nInterim       : Byte;
  nChar           : Byte;
  cChar            : Char;
begin
  nStringLen := length( cString );
  if nStringLen = 0 then begin
    nKey       := 0;
    nSalt       := 0;
    end
  else begin
    for nCharCount := 0 to nStringLen - 1 do begin
      cChar := cString[ nCharCount ];
      { only encipher printable characters }
      if (( cChar >= ' ' ) and ( cChar <= '~' )) then begin
        nkey     := ( nkey and $1FFFFFFF ) xor (( nkey shr 29 ) and $00000031 );
        nChar    := Byte( cChar );
        nInterim := Mod95(( nKey div 95 ) - ( nChar - 32 )) + 32;
        nSalt    := nSalt + 1;
        if ( nSalt >= 20857 ) then begin
          nSalt := 0;
        end;
        nKey := nKey + nKey + ( nInterim xor nChar ) + nSalt;
        cString[ nCharCount ] := Char( nInterim );
      end;
    end;
  end;
end;

{------------------------------------------------------------------------------}
function Mod95( nVal : Integer ): Integer;
begin
  Result := nVal;

  while ( Result >= 9500 ) do begin
    Result := Result - 9500;
  end;

  while ( Result >= 950 ) do begin
    Result := Result - 950;
  end;

  while ( Result >= 95 ) do begin
    Result := Result - 95;
  end;

  while ( Result < 0 ) do begin
    Result := Result + 95;
  end;
end;

Crypt 프로시저에서      { only encipher printable characters } 라는 주석 밑에 있는
if 문 구절에 대한 이해를 잘 하지 못하겠고.. 또 mod95라는 펑션이 왜 사용되어야 하는지
전혀 감을 못잡고 있습니다. 이부분 알고리즘에 대해 알고계시는 분은 답변을 주시면
정말 도움이 될것 같은데요. 도움좀 부탁드리겠습니다.
0  COMMENTS