تحويل String to Base64
#1
كيف يتم تحويل String to Base64 و العكس ؟
الرد
#2

اظف هاتين الدالتين في كود برنامجك واستدعهما للتحويل Cool

كود :
const Codes64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'; function Encode64(S: string): string; var i: Integer; a: Integer; x: Integer; b: Integer; begin Result := ''; a := 0; b := 0; for i := 1 to Length(s) do begin x := Ord(s[i]); b := b * 256 + x; a := a + 8; while a >= 6 do begin a := a - 6; x := b div (1 shl a); b := b mod (1 shl a); Result := Result + Codes64[x + 1]; end; end; if a > 0 then begin x := b shl (6 - a); Result := Result + Codes64[x + 1]; end; end; function Decode64(S: string): string; var i: Integer; a: Integer; x: Integer; b: Integer; begin Result := ''; a := 0; b := 0; for i := 1 to Length(s) do begin x := Pos(s[i], codes64) - 1; if x >= 0 then begin b := b * 64 + x; a := a + 6; if a >= 8 then begin a := a - 8; x := b shr a; b := b mod (1 shl a); x := x mod 256; Result := Result + chr(x); end; end else Exit; end; end;
الرد
#3
كيف هو المتغير Base64 ??

وشكرا
شكوت إلى وكيع سوء حفظي ... فأرشدني إلى ترك المعاصي
وأخــبـرنـي بــأن الـعـلـم نـور ... ونـور الله لا يـهدى لـعـاصي
الرد
#4

اي متغير تقصد يا اخي على حسب علمي Base64 هو نظام تشفير

القي نظرة هنا
الرد
#5
Base64 هو نظام تشفير ملفات PHP
الرد
#6
Base64 هو مخطط تشفير يعرض بيانات ثنائية بصيغة ASCII على هيئتها النصية
يستخدم خصيصا لأجل نقل بيانات ثنائية عبر وسائط بصيغة نصية
مما يضمن وصولها إلى المستلم بشكل سليم
Base64 يستخدم عادة مع رسائل البريد الالكتروني (باستخدام المعيار MIME)
كما يستخدم لتخزين بيانات مركبة في صيغة XML
ترجمة عن wikipedia
Daniel Wischnewski قام بتجويد كود Indy للترميز Base64 بكود ASM
PHP كود :
uses SysUtils;

/ / 
A string encoded in base64 representation of the corresponding
Base64Encode 
function (const-Text: AnsiString): AnsiString; overload;
/ / 
Base64-decodes a string representation of the corresponding string
Base64Decode 
function (const-Text: AnsiString): AnsiString; overload;

/ / 
Sets the size of the base-64 representation
CalcEncodedSize 
function (insize: Cardinal): Cardinal;
/ / 
Sets the size of the binary representation
CalcDecodedSize 
function (const InBuffer, insize: Cardinal): Cardinal;

/ / 
A buffer encoded in the corresponding base-64 representation
Base64Encode procedure 
(const InBuffer, insize: Cardinal; OutBuffer var); overload; register;
/ / 
Decode the Base64 representation in a buffer
{$ IFDEF} SpeedDecode
Base64Decode procedure 
(const InBuffer, insize: Cardinal; OutBuffer var); overload; register;
{$ ENDIF}
{$ 
IFDEF} ValidityCheck
Base64Decode 
function (const InBuffer, insize: Cardinal; var OutBuffer): Boolean; overload; register;
{$ ENDIF}

/ / 
A string encoded in base64 representation of the corresponding
Base64Encode procedure 
(const-Text: PAnsiChar var OutText: PAnsiChar); overload;
/ / 
Base64-decodes a string representation of the corresponding string
Base64Decode procedure 
(const-Text: PAnsiChar var OutText: PAnsiChar); overload;

/ / 
A string encoded in base64 representation of the corresponding
Base64Encode procedure 
(const-Text: AnsiString; var OutText: AnsiString); overload;
/ / 
Base64-decodes a string representation of the corresponding string
Base64Decode procedure 
(const-Text: AnsiString; var OutText: AnsiString); overload; 
الكود بأكمله من المصدر:
كود :
http://www.delphipraxis.net/991-base64-mime-en-decoding.html
بالتوفيق.
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...
الرد
#7
kachwahed

أخي ممكن كيفية استدعاء هذه الدوال للتشفير و ما يلزمني في مشروعي؟
لأنني أضفت String و لم تعمل سأرفقت المشروع لتطلع عليه
متأسف على الازعاج لي سنتين متوقف عن البرمجة بالدالفي


الملفات المرفقة
.rar   Base64.rar (الحجم : 26.23 ك ب / التحميلات : 41)
الرد
#8
يبدو أنك نسيت دلفي تماما Smile
PHP كود :
procedure TForm1.sButton1Click(Sender: TObject);
begin
  Edit2
.Text := Base64Encode(Edit1.Text);
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  
S: string;
begin
  Base64Decode
(Edit2.Text, S);
  
Edit1.Text := S;
end; 
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...
الرد
#9
و الله نسيته تماما مع الهكر و البرمجة بالPHP و البيرل كل شيء راح شكرا لك أخي kachwahed
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم