Einzelnen Beitrag anzeigen

hhcm

Registriert seit: 12. Feb 2006
Ort: Wegberg
309 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Base32 Implementation

  Alt 9. Feb 2017, 10:42
Delphi-Quellcode:
tmp := 'DngfhpghKu8=';
aBytes := TBytes(TIdDECoderMime.DecodeBytes(tmp));

result := Base32Encode(aBytes, Length(aBytes));
// Result = '2DS5GALYRLGAC==='
Kommt noch verwirrenderes Zeug bei raus.

Die Byte Implementation ist

Delphi-Quellcode:
function Base32Encode(const buf; len: integer): string;
var
  i: integer;
  nr: int64;
  arr: array of byte;
begin
  result := '';
  SetLength(arr, len);
  Move(buf, arr[0], len);
  while length(arr) > 0 do
  begin
    nr := 0;
    for i := 1 to 5 do
    begin
      nr := (nr shl 8);
      if length(arr)>=i then
        nr := nr + byte(arr[i-1]);
    end;
    for i := 7 downto 0 do
      if ((length(arr)<2) and (i<6)) or
         ((length(arr)<3) and (i<4)) or
         ((length(arr)<4) and (i<3)) or
         ((length(arr)<5) and (i<1)) then
      result := result + '='
    else
      result := result + base32chars[((nr shr (i*5)) and $1F)+1];
    if length(arr)>5 then
    begin
      move(arr[5], arr[0], length(arr)-5);
      setlength(arr, length(arr)-5);
    end
    else
      setlength(arr, 0);
  end;
end;
Zitat:
... und base64decode("DngfhpghKu8=") zeigt das gleiche Ergebnis wie TIdDecoderMIME.DecodeString("Dngfhpgh Ku8=")?
Wie Uwe schon sagte, das ist nicht vernünftig darstellbar.
Chris
  Mit Zitat antworten Zitat