This course will introduce you to C++ 11 and teach you about syntax fundamentals.

I'm trying to port a Y64/Yahoo64 routine to Delphi problem is I'm having difficulty understanding the code I'm porting, I have several sources of this Y64 but none in Pascal/Delphi.

It's apparently similar to Mac64 which produces a similar string but it's 2 bytes longer.

If i can work out

$dest.=$yahoo64[ord($source[$in])>>2];

$dest.=$yahoo64[((ord($source[$in])<<4)&0x30) | (ord($source[$in+1])>>4)];

$dest.=$yahoo64[((ord($source[$in+1])<<2)&0x3C) | (ord($source[$in+2])>>6)];

$dest.=$yahoo64[ord($source[$in+2])&0x3F];

$in += 3;

How to covert that to Pascal I can finish the rest myself . or if anyone knows where y64 exists already in pascal save me a huge headache.

Thanks..

It's apparently similar to Mac64 which produces a similar string but it's 2 bytes longer.

If i can work out

$dest.=$yahoo64[ord($sourc

$dest.=$yahoo64[((ord($sou

$dest.=$yahoo64[((ord($sou

$dest.=$yahoo64[ord($sourc

$in += 3;

How to covert that to Pascal I can finish the rest myself . or if anyone knows where y64 exists already in pascal save me a huge headache.

Thanks..

```
function y64($source)
{ $yahoo64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
// something with 16 bytes not hex
$inlen = 16;
$in=0;
// in este ce primim
for(; $inlen >=3; $inlen -=3)
{
$dest.=$yahoo64[ord($source[$in])>>2];
$dest.=$yahoo64[((ord($source[$in])<<4)&0x30) | (ord($source[$in+1])>>4)];
$dest.=$yahoo64[((ord($source[$in+1])<<2)&0x3C) | (ord($source[$in+2])>>6)];
$dest.=$yahoo64[ord($source[$in+2])&0x3F];
$in += 3;
}
if($inlen>0)
{
// enters here :)
$dest.=$yahoo64[ord($source[$in])>>2];
$fragment = ((ord($source[$in])<<4)&0x30);
if($inlen>1){$fragment |= (ord($source[$in+1])>>4); }
$dest.=$yahoo64[$fragment];
if($inlen<2)
{$dest.="-";}
else
{$dest.=$yahoo64[((ord($source[$in+1])<<2)&0x3c)]; }
$dest.="-";
}
return $dest;
}
or this routine...
function y64($source)
{ $yahoo64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
// something with 16 bytes not hex
$inlen = 16;
$in=0;
// in este ce primim
for(; $inlen >=3; $inlen -=3)
{
$dest.=$yahoo64[ord($source[$in])>>2];
$dest.=$yahoo64[((ord($source[$in])<<4)&0x30) | (ord($source[$in+1])>>4)];
$dest.=$yahoo64[((ord($source[$in+1])<<2)&0x3C) | (ord($source[$in+2])>>6)];
$dest.=$yahoo64[ord($source[$in+2])&0x3F];
$in += 3;
}
if($inlen>0)
{
// enters here :)
$dest.=$yahoo64[ord($source[$in])>>2];
$fragment = ((ord($source[$in])<<4)&0x30);
if($inlen>1){$fragment |= (ord($source[$in+1])>>4); }
$dest.=$yahoo64[$fragment];
if($inlen<2)
{$dest.="-";}
else
{$dest.=$yahoo64[((ord($source[$in+1])<<2)&0x3c)]; }
$dest.="-";
}
```

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

```
static unsigned yahoobase64 (unsigned char *src, unsigned srclen, char *dst) {
static const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789._";
unsigned char *end = src + srclen;
char *pdst = dst;
unsigned x;
for ( ; src < end; pdst += 4)
if (end - src >= 3) {
x = (src [0] << 16) + (src [1] << 8) + src [2];
pdst [3] = enc [x & 0x3f]; x >>= 6;
pdst [2] = enc [x & 0x3f]; x >>= 6;
pdst [1] = enc [x & 0x3f]; x >>= 6;
pdst [0] = enc [x & 0x3f];
src += 3;
continue;
}
else if (end - src == 2) {
x = (src [0] << 16) + (src [1] << 8);
pdst [3] = '-'; x >>= 6;
pdst [2] = enc [x & 0x3f]; x >>= 6;
pdst [1] = enc [x & 0x3f]; x >>= 6;
pdst [0] = enc [x & 0x3f];
src += 2;
continue;
}
else if (end - src == 1) {
x = src [0] << 16;
pdst [3] = '-'; x >>= 6;
pdst [2] = '-'; x >>= 6;
pdst [1] = enc [x & 0x3f]; x >>= 6;
pdst [0] = enc [x & 0x3f];
src += 1;
continue;
}
*pdst = '\0';
return pdst - dst;
}
```

```
function YahooBase64(Source: PChar; SourceLen: DWORD): PChar;
const
Enc : PChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._';
var
pEnd : PChar;
pDst : PChar;
X : DWORD;
begin
pEnd := Source + SourceLen;
Result := AllocMem(24);
pDst := Result;
X := 0;
While Source < pEnd Do
begin
If (pEnd - Source) >= 3 Then
begin
X := (Byte(Source[0]) SHL 16) + (Byte(Source[1]) SHL 8) + Byte(Source[2]);
pDst[3] := Enc[X AND $3F];
X := X SHR 6;
pDst[2] := Enc[X AND $3F];
X := X SHR 6;
pDst[1] := Enc[X AND $3F];
X := X SHR 6;
pDst[0] := Enc[X AND $3F];
Inc(Source,3);
Continue;
end
Else If (pEnd - Source) = 2 Then
begin
X := (Byte(Source[0]) SHL 16) + (Byte(Source[1]) SHL 8);
pDst[3] := '-';
X := X SHR 6;
pDst[2] := Enc[X AND $3F];
X := X SHR 6;
pDst[1] := Enc[X AND $3F];
X := X SHR 6;
pDst[0] := Enc[X AND $3F];
Inc(Source,2);
Continue;
end
Else If (pEnd - Source) = 1 Then
begin
X := Byte(Source[0]) SHL 16;
pDst[3] := '-';
X := X SHR 6;
pDst[2] := '-';
X := X SHR 6;
pDst[1] := Enc[X AND $3F];
X := X SHR 6;
pDst[0] := Enc[X AND $3F];
Inc(Source);
Continue;
end;
Inc(pDst,4);
end;
pDst^ := #0;
Dec(Source,SourceLen);
end;
```

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialpoints are yours just for trying......

Delphi

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

Might be easier to understand.

Open in new window