OSDN Git Service

・スレタイの特定ワードを非表示にする機能に「©bbspink.com」も追加
[gikonavigoeson/gikonavi.git] / Trip.pas
index 8ed2577..262268f 100644 (file)
--- a/Trip.pas
+++ b/Trip.pas
@@ -9,6 +9,9 @@ unit Trip;
 }
 interface
 
+uses
+    SHA1Unit, UBase64, SysUtils, MojuUtils;
+
 type
        CryptBlock = record
                b_data : array [0..63] of char;
@@ -417,25 +420,100 @@ begin
 
 end;
 
+procedure get_pw_salt(
+    const pw : PChar;
+    var convpw : String;
+    const salt : PChar
+) ;
+var
+    i : integer;
+begin
+    // ^([0-9A-Fa-f]{16})([./0-9A-Za-z]{0,2})$
+    if (Length(pw) >= 17) and (Length(pw) <= 19) then begin
+        // \83L\81[\95\94\95ª
+        for  i := 0 to 7 do begin
+            if (Pos(pw[2*i + 0 + 1], '0123456789abcdefABCDEF') > 0) and
+                (Pos(pw[2*i + 1 + 1], '0123456789abcdefABCDEF') > 0) then begin
+                convpw := convpw +
+                    Char(StrToInt( 'x' + pw[2*i + 0 + 1] ) shl 4 + StrToInt( 'x'  + pw[2*i + 1 + 1] ));
+            end else begin
+                convpw := '';
+                Break;
+            end;
+        end;
+
+        if (Length(convpw) = 8) then begin
+            if (Length(pw) = 19) then begin
+                if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) and
+                    (Pos(pw[18], './0123456789abcdefABCDEF') > 0) then begin
+                    salt[ 0 ] := pw[17];
+                    salt[ 1 ] := pw[18];
+                    salt[ 2 ] := #0;
+                end else begin
+                    convpw := '';
+                end;
+            end else if (Length(pw) = 18) then begin
+                if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) then begin
+                    salt[ 0 ] := pw[17];
+                    salt[ 1 ] := '.';
+                    salt[ 2 ] := #0;
+                end else begin
+                    convpw := '';
+                end;
+            end else begin
+                salt[ 0 ] := '.';
+                salt[ 1 ] := '.';
+                salt[ 2 ] := #0;
+            end;
+        end;
+    end;
+end;
+
 function get_2ch_trip(
        const pw : PChar
 ) : string;
 var
        s : CryptData;
        salt : array [0..2] of char;
+    digest : TSHA1Digest;
+    convpw : String;
 begin
-
+    Result := '';
        if pw[ 0 ] = #0 then
        begin
-               Result := '';
                Exit;
        end;
-
-    get_salt( pw, salt );
-
-
-       Result := Copy( crypt_r( pw, salt, s ), 4, 100 );
-
+    // 11\8c\85\82Ü\82Å\82Í\8b\8c\95û\8e®
+    if (Length(pw) <= 11) then begin
+        get_salt( pw, salt );
+       Result := Copy( crypt_r( pw, salt, s ), 4, 100 );
+    end else begin
+        // \90V\95û\8e®\83g\83\8a\83b\83v
+        if pw[ 0 ] = '$' then begin
+            // \8f«\97\88\82Ì\8ag\92£\97p
+            Result := '???';
+        end else begin
+            convpw := '';
+            if (pw[ 0 ] = '#') and (Length(pw) >= 20) then begin
+                // \8f«\97\88\82Ì\8ag\92£\97p
+                Result := '???';
+            end else if pw[ 0 ] = '#' then begin
+                // \90\83L\81[\95û\8e®
+                get_pw_salt(pw, convpw, salt);
+                if Length(convpw) = 0 then begin
+                    // \90\83L\81[\95û\8e®\83G\83\89\81[
+                    Result := '???';
+                end else if Length(convpw) = 8 then begin
+                    Result := Copy( crypt_r( PChar(convpw), salt, s ), 4, 100 );
+                end
+            end else begin
+                // \90V\95û\8e®
+                StringHashSHA1(digest, pw);
+                Result := Copy(HogeBase64Encode(digest), 0, 12);
+                Result := MojuUtils.CustomStringReplace(Result, '+', '.');
+            end;
+        end;
+    end;
 end;
 
 procedure get_salt(