Thread overview | |||||
---|---|---|---|---|---|
|
December 15, 2008 plain C to D2 const etc: | ||||
---|---|---|---|---|
| ||||
Hi, what is the correct way to translate this snippet into _D2_ ? //const and cast() void rc2_decrypt( const unsigned short xkey[64], unsigned char *plain, const unsigned char *cipher ) { unsigned x76, x54, x32, x10, i; x76 = (cipher[7] << 8) + cipher[6]; ......... many TIA, Bjoern |
December 15, 2008 Re: plain C to D2 const etc: | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | On Mon, 15 Dec 2008 20:11:44 +0300, BLS <nanali@nospam.wanadoo.fr> wrote:
> Hi, what is the correct way to translate this snippet into _D2_ ?
> //const and cast()
>
> void rc2_decrypt( const unsigned short xkey[64],
> unsigned char *plain,
> const unsigned char *cipher )
> {
> unsigned x76, x54, x32, x10, i;
>
> x76 = (cipher[7] << 8) + cipher[6];
> .........
>
> many TIA, Bjoern
Here you go:
void rc2_decrypt( const(ushort)[64] xkey, ubyte* plain, const(ubyte)* cipher )
{
uint x76, x54, x32, x10, i;
x76 = (cipher[7] << 8) + cipher[6];
// .....
}
You'd better pass cipher and plain as arrays rather than pointers if their sizes are known:
void rc2_decrypt( const(ushort)[64] xkey, const(ubyte)[] plain, const(ubyte)[] cipher )
{
uint x76, x54, x32, x10, i;
x76 = (cipher[7] << 8) + cipher[6];
// .....
}
|
December 15, 2008 Re: plain C to D2 const etc: | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin schrieb:
> On Mon, 15 Dec 2008 20:11:44 +0300, BLS <nanali@nospam.wanadoo.fr> wrote:
>
>> Hi, what is the correct way to translate this snippet into _D2_ ?
>> //const and cast()
>>
>> void rc2_decrypt( const unsigned short xkey[64],
>> unsigned char *plain,
>> const unsigned char *cipher )
>> {
>> unsigned x76, x54, x32, x10, i;
>>
>> x76 = (cipher[7] << 8) + cipher[6];
>> .........
>>
>> many TIA, Bjoern
>
> Here you go:
>
> void rc2_decrypt( const(ushort)[64] xkey, ubyte* plain, const(ubyte)* cipher )
> {
> uint x76, x54, x32, x10, i;
> x76 = (cipher[7] << 8) + cipher[6];
> // .....
> }
>
> You'd better pass cipher and plain as arrays rather than pointers if their sizes are known:
>
> void rc2_decrypt( const(ushort)[64] xkey, const(ubyte)[] plain, const(ubyte)[] cipher )
> {
> uint x76, x54, x32, x10, i;
> x76 = (cipher[7] << 8) + cipher[6];
> // .....
> }
Thanks a lot Denis,
I am afraid I am not able to use arrays 'cause I've to use the function as follows :
export extern(Windows) void rc2_decrypt() in order to use it from my 4GL development-system.
beside, any reason for const(ubyte)[] plain instead of ubyte[] plain ?
Bjoern
|
Copyright © 1999-2021 by the D Language Foundation