AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Hex to Base64

Ein Thema von Cubysoft · begonnen am 7. Mai 2015 · letzter Beitrag vom 7. Mai 2015
Antwort Antwort
gammatester

Registriert seit: 6. Dez 2005
999 Beiträge
 
#1

AW: Hex to Base64

  Alt 7. Mai 2015, 13:51
Wenn Du nicht eine der Base64/Mime-Funktionen zur Verfügung hast, kann man auch mit Bordmitteln arbeiten. Das Program unten liefert die Ausgabe AgGqtgAA
Delphi-Quellcode:
program b64;

{$apptype console}

const
  CT64: array[0..63] of ansichar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

{---------------------------------------------------------------------------}
function Base64Str(psrc: pointer; L: integer): ansistring;
  {-Base64 string of memory block of length L pointed by psrc}
var
  q,r: integer;
  b0,b1,b2: byte;
type
  pByte = ^byte;
begin
  result := '';
  if (L>0) and (psrc<>nil) then begin
    q := L div 3;
    r := L mod 3;
    while q>0 do begin
      b0 := pByte(psrc)^; inc(pByte(psrc));
      b1 := pByte(psrc)^; inc(pByte(psrc));
      b2 := pByte(psrc)^; inc(pByte(psrc));
      result := result + CT64[(b0 shr 2) and $3f]
                       + CT64[((b0 shl 4) and $30) or ((b1 shr 4) and $0f)]
                       + CT64[((b1 shl 2) and $3c) or ((b2 shr 6) and $03)]
                       + CT64[b2 and $3f];
      dec(q);
    end;
    if r=2 then begin
      b0 := pByte(psrc)^; inc(pByte(psrc));
      b1 := pByte(psrc)^;
      result := result + CT64[(b0 shr 2) and $3f]
                       + CT64[((b0 shl 4) and $30) or ((b1 shr 4) and $0f)]
                       + CT64[(b1 shl 2) and $3c]
                       + '=';
    end
    else if r=1 then begin
      b0 := pByte(psrc)^;
      result := result + CT64[(b0 shr 2) and $3f]
                       + CT64[(b0 shl 4) and $30]
                       + '==';
    end;
  end;
end;


var
  s: ansistring;
const
  xx: array[0..5] of byte = ($02, $01, $AA, $B6, $00, $00) ;
begin
  s := Base64Str(@xx, sizeof(xx));
  writeln(s);
end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:12 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz