Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2006.07.09;
Скачать: [xml.tar.bz2];

Вниз

Как сконвертить строку в base64?   Найти похожие ветки 

 
serg128   (2006-05-28 11:16) [0]

Как сконвертить строку в base64, но желательно без использования заумных бибилиотек? Приведите код, плиз! :)

Заранее спасибо!


 
_n0p   (2006-05-28 13:58) [1]

http://www.fourmilab.ch/webtools/base64/rfc1341.html
http://www.fourmilab.ch/webtools/base64/
http://www.google.ru/search?sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGGL:2005-09,GGGL:ru&q=base64


 
atruhin ©   (2006-05-28 14:33) [2]

Function EncodeBase64( Data: PChar; Len: Integer ): String;
const B64 : array [0..63] of Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                                  "abcdefghijklmnopqrstuvwxyz" +
                                  "0123456789+/";
var Ic    : Integer;
  Pi, Po: TPAByte;
  C1    : DWord;
Begin
  if Len > 0 then
  Begin
     SetLength( Result, ( ( Len + 2 ) div 3 ) * 4 );
     Pi := Pointer( Data );
     Po := Pointer( Result );
     for Ic := 1 to Len div 3 do
     Begin
        C1 := Pi^[0] shl 16 + Pi^[1] shl 8 + Pi^[2];
        Po^[0] := Byte( B64[( C1 shr 18 ) and $3f] );
        Po^[1] := Byte( B64[( C1 shr 12 ) and $3f] );
        Po^[2] := Byte( B64[( C1 shr  6 ) and $3f] );
        Po^[3] := Byte( b64[( c1        ) and $3f] );
        Inc( DWord( Po ), 4 );
        Inc( DWord( Pi ), 3 );
     end;
     Case Len mod 3 of
          1: Begin
                C1 := Pi^[0] shl 16;
                Po^[0] := Byte( B64[( C1 shr 18 ) and $3f] );
                Po^[1] := Byte( B64[( C1 shr 12 ) and $3f] );
                Po^[2] := Byte( "=" );
                Po^[3] := Byte("=");
             end;
          2: Begin
                C1 := Pi^[0] shl 16 + Pi^[1] shl 8;
                Po^[0] := Byte( B64[( C1 shr 18 ) and $3f] );
                Po^[1] := Byte( B64[( C1 shr 12 ) and $3f] );
                Po^[2] := Byte( B64[( C1 shr  6 ) and $3f] );
                Po^[3] := Byte("=");
             end;
     end;
  end else Result := "";
end;


 
atruhin ©   (2006-05-28 14:33) [3]

Function DecodeBase64( Data: PChar; Len: Integer ): String;
var I1, I2: Integer;
  Pi, Po: TPAByte;
  ch1   : Char;
  c1    : DWord;
Begin
  if ( Len > 0 ) and ( Len mod 4 = 0 ) then
  Begin
     Len := Len shr 2;
     SetLength( Result, Len * 3 );
     Pi := Pointer( Data );
     Po := Pointer( Result );
     for I1 := 1 to Len do
     Begin
        C1 := 0;
        I2 := 0;
        While True do
        Begin
           Ch1 := Char( Pi^[I2] );
           Case Ch1 of
                "A".."Z": C1 := C1 or ( DWord( Ch1 ) - Byte( "A" )      );
                "a".."z": C1 := C1 or ( DWord( Ch1 ) - Byte( "a" ) + 26 );
                "0".."9": C1 := C1 or ( DWord( Ch1 ) - Byte( "0" ) + 52 );
                "+"     : C1 := C1 or 62;
                "/"     : C1 := C1 or 63;
           else
            Begin
               if I2 = 3 then
               Begin
                  Po^[0] := C1 shr 16;
                  Po^[1] := Byte( C1 shr 8 );
                  SetLength( Result, Length( Result ) - 1 );
               end else
               Begin
                   Po^[0] := C1 shr 10;
                   SetLength( Result, Length( Result ) - 2 );
               end;
               Exit;
            end;
           end;
           if I2 = 3 then break;
           Inc( I2 );
           C1 := C1 shl 6;
        end;
        Po^[0] := C1 shr 16;
        Po^[1] := Byte( C1 shr 8 );
        Po^[2] := Byte( C1 );
        Inc( DWord( Pi ), 4 );
        Inc( DWord( Po ), 3 );
     end;
  end else Result := "";
end;


 
Жуков Олег   (2006-05-28 19:49) [4]


> Как сконвертить строку в base64, но желательно без использования
> заумных бибилиотек? Приведите код, плиз! :)

не знаю, есть ли в D6, а в D7 и выше есть EncdDecd.pas
uses EncdDecd;
функции EncodeString, DecodeString, EncodeStream, DecodeStream;



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2006.07.09;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.012 c
2-1150426765
Pagoo-man
2006-06-16 06:59
2006.07.09
Проблема с экспортом в Excel


15-1149509339
Nic
2006-06-05 16:08
2006.07.09
Открыть своё дело?


8-1138479991
GLText
2006-01-28 23:26
2006.07.09
Текст в OpenGL


15-1149849028
iamdanil
2006-06-09 14:30
2006.07.09
RS Stereo Image 2006


3-1147263291
SHD
2006-05-10 16:14
2006.07.09
И снова значения по умолчанию.





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский