Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #55975 > unrolled thread

MD4 in Forth?

Started byHowerd <howerdo@yahoo.co.uk>
First post2017-03-20 14:11 -0700
Last post2017-05-13 09:44 -0500
Articles 19 — 8 participants

Back to article view | Back to comp.lang.forth


Contents

  MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-03-20 14:11 -0700
    Re: MD4 in Forth? Paul Rubin <no.email@nospam.invalid> - 2017-03-20 21:41 -0700
      Re: MD4 in Forth? mhx@iae.nl - 2017-03-20 23:02 -0700
        Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-03-21 12:48 -0700
    Re: MD4 in Forth? minforth@arcor.de - 2017-03-21 07:09 -0700
      Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-03-21 12:46 -0700
      Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-03-21 12:47 -0700
        Re: MD4 in Forth? Paul Rubin <no.email@nospam.invalid> - 2017-03-21 20:13 -0700
    Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-05-10 13:21 -0700
      Re: MD4 in Forth? Alex <alex@rivadpm.com> - 2017-05-10 23:27 +0100
      Re: MD4 in Forth? pahihu <pahihu@gmail.com> - 2017-05-11 05:10 -0700
        Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-05-11 22:07 -0700
          Re: MD4 in Forth? pahihu <pahihu@gmail.com> - 2017-05-12 04:58 -0700
            Re: MD4 in Forth? Howerd <howerdo@yahoo.co.uk> - 2017-05-12 08:17 -0700
              Re: Endian-swapping word ( was MD4 in Forth? ) Howerd <howerdo@yahoo.co.uk> - 2017-05-12 08:36 -0700
                Re: Endian-swapping word ( was MD4 in Forth? ) Raimond Dragomir <raimond.dragomir@gmail.com> - 2017-05-12 23:09 -0700
                  Re: Endian-swapping word ( was MD4 in Forth? ) Howerd <howerdo@yahoo.co.uk> - 2017-05-13 07:04 -0700
                    Re: Endian-swapping word ( was MD4 in Forth? ) Raimond Dragomir <raimond.dragomir@gmail.com> - 2017-05-13 10:05 -0700
                Re: Endian-swapping word ( was MD4 in Forth? ) David Schultz <abuse@127.0.0.1> - 2017-05-13 09:44 -0500

#55975 — MD4 in Forth?

FromHowerd <howerdo@yahoo.co.uk>
Date2017-03-20 14:11 -0700
SubjectMD4 in Forth?
Message-ID<d500ffec-0d35-4043-9e8f-0144ed8f035b@googlegroups.com>
Hi All,

Does anyone have a Forth implementation of MD4?
I may have a legacy app to debug soon...

Best regards,
Howerd

[toc] | [next] | [standalone]


#55990

FromPaul Rubin <no.email@nospam.invalid>
Date2017-03-20 21:41 -0700
Message-ID<87k27ji6lu.fsf@nightsong.com>
In reply to#55975
Howerd <howerdo@yahoo.co.uk> writes:
> Does anyone have a Forth implementation of MD4?  I may have a legacy
> app to debug soon...

Need a particular cell size?  I have a half-done SHA1 implementation
around here using 16-bit cells, which was a bit messy to do.  With 32
bit cells it's much easier.  MD4 and SHA1 are fairly similar so you can
probably hack one into the other.

[toc] | [prev] | [next] | [standalone]


#55993

Frommhx@iae.nl
Date2017-03-20 23:02 -0700
Message-ID<4e9bfc64-c1aa-4c1d-833a-547098364f10@googlegroups.com>
In reply to#55990
On Tuesday, March 21, 2017 at 5:41:58 AM UTC+1, Paul Rubin wrote:
> Howerd <howerdo@yahoo.co.uk> writes:
> > Does anyone have a Forth implementation of MD4?  I may have a legacy
> > app to debug soon...
> 
> Need a particular cell size?  I have a half-done SHA1 implementation
> around here using 16-bit cells, which was a bit messy to do.  With 32
> bit cells it's much easier.  MD4 and SHA1 are fairly similar so you can
> probably hack one into the other.

SHA1 has been extensively treated on CLF.
I think there are at least 3 separate
implementations that can be found using
Google Groups alone. Therefore it would 
be useful if someone explains the 
exact difference with MD4.

-marcel

[toc] | [prev] | [next] | [standalone]


#56046

FromHowerd <howerdo@yahoo.co.uk>
Date2017-03-21 12:48 -0700
Message-ID<1aa4eb43-855a-4b8a-9fc8-6da752fdd5a9@googlegroups.com>
In reply to#55993
On Tuesday, 21 March 2017 07:02:28 UTC+1, m...@iae.nl  wrote:
> On Tuesday, March 21, 2017 at 5:41:58 AM UTC+1, Paul Rubin wrote:
> > Howerd <hxxxxxahoo.co.uk> writes:
> > > Does anyone have a Forth implementation of MD4?  I may have a legacy
> > > app to debug soon...
> > 
> > Need a particular cell size?  I have a half-done SHA1 implementation
> > around here using 16-bit cells, which was a bit messy to do.  With 32
> > bit cells it's much easier.  MD4 and SHA1 are fairly similar so you can
> > probably hack one into the other.
> 
> SHA1 has been extensively treated on CLF.
> I think there are at least 3 separate
> implementations that can be found using
> Google Groups alone. Therefore it would 
> be useful if someone explains the 
> exact difference with MD4.
> 
> -marcel

Hi Marcel,

Yes I would like to know that too :-)

Best regards,
Howerd

[toc] | [prev] | [next] | [standalone]


#56006

Fromminforth@arcor.de
Date2017-03-21 07:09 -0700
Message-ID<f05312c1-31a1-4bbf-8711-1a7c437c6ed3@googlegroups.com>
In reply to#55975
Am Montag, 20. März 2017 22:11:08 UTC+1 schrieb Howerd:
> Hi All,
> 
> Does anyone have a Forth implementation of MD4?
> I may have a legacy app to debug soon...
> 
> Best regards,
> Howerd

If you just wanna compare results, pick from lots of other implementations
https://rosettacode.org/wiki/MD4

As usual, no Forth, but MD4 is compromised anyhow for cryptography.

[toc] | [prev] | [next] | [standalone]


#56044

FromHowerd <howerdo@yahoo.co.uk>
Date2017-03-21 12:46 -0700
Message-ID<2e617947-db1e-43e3-8b84-33505c9cea70@googlegroups.com>
In reply to#56006
On Tuesday, 21 March 2017 15:10:00 UTC+1, minf...@arcor.de  wrote:
> Am Montag, 20. März 2017 22:11:08 UTC+1 schrieb Howerd:
> > Hi All,
> > 
> > Does anyone have a Forth implementation of MD4?
> > I may have a legacy app to debug soon...
> > 
> > Best regards,
> > Howerd
> 
> If you just wanna compare results, pick from lots of other implementations
> https://rosettacode.org/wiki/MD4
> 
> As usual, no Forth, but MD4 is compromised anyhow for cryptography.

Yes, not really worth converting from language X to Forth for something that is not going to be used for new projects...

I was hoping that someone would have a Forth implementation fully working and tested...

Maybe I will take a C version, make a DLL and call it from Forth.

Thanks everyone,
Howerd 

[toc] | [prev] | [next] | [standalone]


#56045

FromHowerd <howerdo@yahoo.co.uk>
Date2017-03-21 12:47 -0700
Message-ID<94a1641f-34d4-4c03-93ff-f3b4f229827f@googlegroups.com>
In reply to#56006
On Tuesday, 21 March 2017 15:10:00 UTC+1, minf...@arcor.de  wrote:
> Am Montag, 20. März 2017 22:11:08 UTC+1 schrieb Howerd:
> > Hi All,
> > 
> > Does anyone have a Forth implementation of MD4?
> > I may have a legacy app to debug soon...
> > 
> > Best regards,
> > Howerd
> 
> If you just wanna compare results, pick from lots of other implementations
> https://rosettacode.org/wiki/MD4
> 
> As usual, no Forth, but MD4 is compromised anyhow for cryptography.

Hi Paul,

Just 80x86 32 bit. I didn't know that MD4 and SHA-1 are related...

Best regards,
Howerd

[toc] | [prev] | [next] | [standalone]


#56074

FromPaul Rubin <no.email@nospam.invalid>
Date2017-03-21 20:13 -0700
Message-ID<87a88e57i9.fsf@nightsong.com>
In reply to#56045
Howerd <howerdo@yahoo.co.uk> writes:
> Just 80x86 32 bit. I didn't know that MD4 and SHA-1 are related...

They resemble each other.  The details are different in multiple ways
but the high-level structures are somewhat similar.  So code for one of
them would be a reasonable starting point for the other.

[toc] | [prev] | [next] | [standalone]


#59009

FromHowerd <howerdo@yahoo.co.uk>
Date2017-05-10 13:21 -0700
Message-ID<ae6e6ebd-e605-4958-a549-dd877f216b50@googlegroups.com>
In reply to#55975
On Monday, 20 March 2017 22:11:08 UTC+1, Howerd  wrote:
> Hi All,
> 
> Does anyone have a Forth implementation of MD4?
> I may have a legacy app to debug soon...
> 
> Best regards,
> Howerd

Hi All,

I've just uploaded a 32 bit ANS Forth Little Endian version of the MD4 hash here :

www.inventio.co.uk/md4.f

Just in case anyone else ever needs it...

Interestingly it works under SwiftForth, but fails under both VFX and Win32Forth.

Maybe someone could debug why... (life is too short to do this for an obsolete hash ).
Presumably I am doing something not quite ANS compliant ;-)

Cheers,
Howerd

[toc] | [prev] | [next] | [standalone]


#59014

FromAlex <alex@rivadpm.com>
Date2017-05-10 23:27 +0100
Message-ID<of03ua$536$1@dont-email.me>
In reply to#59009
On 5/10/2017 21:21, Howerd wrote:
> On Monday, 20 March 2017 22:11:08 UTC+1, Howerd  wrote:
>> Hi All,
>>
>> Does anyone have a Forth implementation of MD4?
>> I may have a legacy app to debug soon...
>>
>> Best regards,
>> Howerd
> 
> Hi All,
> 
> I've just uploaded a 32 bit ANS Forth Little Endian version of the MD4 hash here :
> 
> www.inventio.co.uk/md4.f
> 
> Just in case anyone else ever needs it...
> 
> Interestingly it works under SwiftForth, but fails under both VFX and Win32Forth.
> 
> Maybe someone could debug why... (life is too short to do this for an obsolete hash ).
> Presumably I am doing something not quite ANS compliant ;-)
> 
> Cheers,
> Howerd
> 

Works fine on WF32.

md4tests
MD4 Known Answer Tests
 
          -> 31D6CFE0D16AE931B73C59D7E0C089C0 passed
a 
         -> BDE52CB31DE33E46245E05FBDBD6FB24 passed
abc 
         -> A448017AAF21D8525FC10AE87AA6729D passed
message digest 
         -> D9130A8164549FE818874806E1C7014B passed
abcdefghijklmnopqrstuvwxyz 
         -> D79E1C308AA5BBCDEEA8ED63DF412DA9 passed
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 
         -> 043F8582F241DB351CE627E153E7F0E4 passed
12345678901234567890123456789012345678901234567890123456789012345678901234567890 
-> E33B4DDC9C38F2199C3E7B164FCC0536 passed
A 
         -> D5EF20EEB3F75679F86CF57F93ED0FFE passed
AA 
         -> 14B4403751AD952DC0E8A0C627C2EDDB passed
AAA 
         -> 17C3B38C112AC61C1F0D46555F379F14 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 183325E88214BB9694A7969FC22CE222 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 1D7BB1528414BDCAB709D5107F766D88 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 2EAE267BE1BD32FF073B50F7B654AED2 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 95E060C139FBD884C156222546EFECA0 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> EB3199C1C0EA80A27030B54B73CF0A8F passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 865E9455F770EB97A0EE247F2EA1B1AC passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 2A7849AD155EBAE2BF40625C6BB654A3 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 3DFA8742C223879B407B380F8FA6DC97 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 47D2EB439D2BC5224E13B0904AB5CE5C passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 86B140DFF315216AA98645F89FEAC00F passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 21CACEB3A62C434222CDF4913991D761 passed
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
         -> 330EFB3CA926EBF810C33F4D56090E10 passed
http://www.md5calc.com/:MD4 
         -> A957B313A7B452E84F3D39D3488EC118 passed
All tests passed
  ok

-- 
Alex

[toc] | [prev] | [next] | [standalone]


#59078

Frompahihu <pahihu@gmail.com>
Date2017-05-11 05:10 -0700
Message-ID<f0ed859a-e4fd-4a24-b0ef-d560708293e3@googlegroups.com>
In reply to#59009
Hi,


Missing words on various Forths: "BUFFER:" "3DUP" "NOT"
If get-xy undefined ToColumn needs to be drop.

[UNDEFINED] get-xy [IF]
: ToColumn ( u -- )  drop ;
[ELSE]
...


pahihu

[toc] | [prev] | [next] | [standalone]


#59104

FromHowerd <howerdo@yahoo.co.uk>
Date2017-05-11 22:07 -0700
Message-ID<b2afbd94-5eb5-4aa6-8c90-f0af2d800c7a@googlegroups.com>
In reply to#59078
On Thursday, 11 May 2017 14:10:35 UTC+2, pahihu  wrote:
> Hi,
> 
> 
> Missing words on various Forths: "BUFFER:" "3DUP" "NOT"
> If get-xy undefined ToColumn needs to be drop.
> 
> [UNDEFINED] get-xy [IF]
> : ToColumn ( u -- )  drop ;
> [ELSE]
> ...
> 
> 
> pahihu

Hi pahihu,

Thanks for the feedback :-)
I've replaced :
n buffer: XXX  by  create XXX  n allot 
3dup           by  dup 2over rot
not            by  0=

The new code is here : http://www.inventio.co.uk/md4.f

I think that this is now pure ANS, plus it now works under VFX and Win32Forth!
It was the ToColumn that broke MD4test on systems that don't have get-xy .

I have also updated md5.f here : http://www.inventio.co.uk/md5.f

Best regards & thanks again,
Howerd

[toc] | [prev] | [next] | [standalone]


#59114

Frompahihu <pahihu@gmail.com>
Date2017-05-12 04:58 -0700
Message-ID<dfc78f18-eb56-4db7-ae22-11a1026b47b7@googlegroups.com>
In reply to#59104
Hi,

One more remark: md4_padding[] should contain 64 bytes, not words.

create md4_padding[]
    $80 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
      0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
      0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
      0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,

Regards,
pahihu

PS: I modifed your md4.f to run on big-endian CPUs.

[toc] | [prev] | [next] | [standalone]


#59125

FromHowerd <howerdo@yahoo.co.uk>
Date2017-05-12 08:17 -0700
Message-ID<ce2c2acb-b2b6-44ef-818a-b8da89beb61a@googlegroups.com>
In reply to#59114
On Friday, 12 May 2017 13:58:24 UTC+2, pahihu  wrote:
> Hi,
> 
> One more remark: md4_padding[] should contain 64 bytes, not words.
> 
> create md4_padding[]
>     $80 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
>       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
>       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
>       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
> 
> Regards,
> pahihu
> 
> PS: I modifed your md4.f to run on big-endian CPUs.

Hi pahihu,

Also corrected - thanks again :-)
Updated to the same location : http://www.inventio.co.uk/md4.f
Now labeled "md4.f V1.0  Howerd Oakford 2017 May 12b"

> PS: I modifed your md4.f to run on big-endian CPUs.
Great! I removed some code that swaps endianness because I am working on x86 and ARM M4, both of which are little endian.

I really appreciate the support - it's something that shows that comp.lang.forth is not just about bizarre rants ...;-)

Cheers,
Howerd

[toc] | [prev] | [next] | [standalone]


#59126 — Re: Endian-swapping word ( was MD4 in Forth? )

FromHowerd <howerdo@yahoo.co.uk>
Date2017-05-12 08:36 -0700
SubjectRe: Endian-swapping word ( was MD4 in Forth? )
Message-ID<f4b5a220-9bba-4877-a261-621665224af7@googlegroups.com>
In reply to#59125
On Friday, 12 May 2017 17:17:49 UTC+2, Howerd  wrote:
> On Friday, 12 May 2017 13:58:24 UTC+2, pahihu  wrote:
> > Hi,
> > 
> > One more remark: md4_padding[] should contain 64 bytes, not words.
> > 
> > create md4_padding[]
> >     $80 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
> >       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
> >       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
> >       0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
> > 
> > Regards,
> > pahihu
> > 
> > PS: I modifed your md4.f to run on big-endian CPUs.
> 
> Hi pahihu,
> 
> Also corrected - thanks again :-)
> Updated to the same location : http://www.inventio.co.uk/md4.f
> Now labeled "md4.f V1.0  Howerd Oakford 2017 May 12b"
> 
> > PS: I modifed your md4.f to run on big-endian CPUs.
> Great! I removed some code that swaps endianness because I am working on x86 and ARM M4, both of which are little endian.
> 
> I really appreciate the support - it's something that shows that comp.lang.forth is not just about bizarre rants ...;-)
> 
> Cheers,
> Howerd

Hi All,

Something that came out of writing the MD4 code : I think Forth should have an Endian-swapping word as standard ( as an extension ).
: >32<  ( u -- u )   ... ; \ converts $11223344 to $44332211

This would avoid the _system_ having to know which Endianness it is, and place the responsibility on the application programmer. I know that this is the opposite direction compared to conventional wisdom.

i.e. BE@ has to know that if the system is Little Endian, it must reverse the byte order. If BE@ is standard, the application programmer has to know that the system is Little Endian and so use BE@ instead of @ ( or LE@).  

There is the 16 bit version in SwiftForth  >< , known by other names in other systems.

Suggestions for suitable names, anyone? 

BTW Joel ( Rees ) : I read in one of your blogs why you favour Big Endian, to be compatible with the written convention that 1234 has the 1000's first.
I agree with your reasoning, except that I think that the written convention is wrong - it should be 4321 ( one thousand, 2 hundred and thirty four ).
Therefore I favour Little Endian...
This would avoid the silliness of having to put the units on the left, e.g. £1234. Just my tuppence worth :-)

Cheers,
Howerd

[toc] | [prev] | [next] | [standalone]


#59150 — Re: Endian-swapping word ( was MD4 in Forth? )

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2017-05-12 23:09 -0700
SubjectRe: Endian-swapping word ( was MD4 in Forth? )
Message-ID<07c7f161-b8fe-4a9f-a432-070da09961a3@googlegroups.com>
In reply to#59126
BYTESWAP16
BYTESWAP32
BYTESWAP64
BYTESWAP - an alias to any of the above, depending on the CELL size

BITSWAP.... etc...

Yes, long names, but not so long.

And if you want to write real portable code regarding endianness, you must 
use some words like BE@ and LE@ (and store), one of them being just an
alias to @ and the other one being @ BYTESWAP

Just my thought

[toc] | [prev] | [next] | [standalone]


#59168 — Re: Endian-swapping word ( was MD4 in Forth? )

FromHowerd <howerdo@yahoo.co.uk>
Date2017-05-13 07:04 -0700
SubjectRe: Endian-swapping word ( was MD4 in Forth? )
Message-ID<212497ca-804b-4a34-9379-2ee968810be1@googlegroups.com>
In reply to#59150
On Saturday, 13 May 2017 08:09:44 UTC+2, Raimond Dragomir  wrote:
> BYTESWAP16
> BYTESWAP32
> BYTESWAP64
> BYTESWAP - an alias to any of the above, depending on the CELL size
> 
> BITSWAP.... etc...
> 
> Yes, long names, but not so long.
> 
> And if you want to write real portable code regarding endianness, you must 
> use some words like BE@ and LE@ (and store), one of them being just an
> alias to @ and the other one being @ BYTESWAP
> 
> Just my thought

Hi Raymond,

Wouldn't BYTEREVERSE32 be better, since swap usually has just two items?

Also, maybe we should have a word that tells you your ENDIANNESS?

Cheers,
Howerd

[toc] | [prev] | [next] | [standalone]


#59181 — Re: Endian-swapping word ( was MD4 in Forth? )

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2017-05-13 10:05 -0700
SubjectRe: Endian-swapping word ( was MD4 in Forth? )
Message-ID<ccc7f5b5-b47d-4fce-bd0c-c9c6c957103a@googlegroups.com>
In reply to#59168
sâmbătă, 13 mai 2017, 17:05:00 UTC+3, Howerd a scris:
> On Saturday, 13 May 2017 08:09:44 UTC+2, Raimond Dragomir  wrote:
> > BYTESWAP16
> > BYTESWAP32
> > BYTESWAP64
> > BYTESWAP - an alias to any of the above, depending on the CELL size
> > 
> > BITSWAP.... etc...
> > 
> > Yes, long names, but not so long.
> > 
> > And if you want to write real portable code regarding endianness, you must 
> > use some words like BE@ and LE@ (and store), one of them being just an
> > alias to @ and the other one being @ BYTESWAP
> > 
> > Just my thought
> 
> Hi Raymond,
> 
> Wouldn't BYTEREVERSE32 be better, since swap usually has just two items?
> 
> Also, maybe we should have a word that tells you your ENDIANNESS?
> 
> Cheers,
> Howerd

Good point.
The name seems a bit long. Just a bit.
Maybe:
BYTEREV32 etc.?

ENDIANNESS? seems a compile time switch to me. I won't write such code...
BE@ LE@ etc. will be just ok as long as they are correctly set for
the system. The idea is to avoid compile time switches (like in 
many C files #ifdef's nightmare). They should be used of course only
at the critical points where the program interfaces with the external
world streams.

Best regards,

[toc] | [prev] | [next] | [standalone]


#59175 — Re: Endian-swapping word ( was MD4 in Forth? )

FromDavid Schultz <abuse@127.0.0.1>
Date2017-05-13 09:44 -0500
SubjectRe: Endian-swapping word ( was MD4 in Forth? )
Message-ID<Wq-dnRxRiqpDhorEnZ2dnUU7-RPNnZ2d@earthlink.com>
In reply to#59126
On 05/12/2017 10:36 AM, Howerd wrote:
> Something that came out of writing the MD4 code : I think Forth should have an Endian-swapping word as standard ( as an extension ).
> : >32<  ( u -- u )   ... ; \ converts $11223344 to $44332211
> 
> This would avoid the _system_ having to know which Endianness it is, and place the responsibility on the application programmer. I know that this is the opposite direction compared to conventional wisdom.
> 
> i.e. BE@ has to know that if the system is Little Endian, it must reverse the byte order. If BE@ is standard, the application programmer has to know that the system is Little Endian and so use BE@ instead of @ ( or LE@).  
> 
> There is the 16 bit version in SwiftForth  >< , known by other names in other systems.
> 
> Suggestions for suitable names, anyone? 
> 

I used ><  to switch the order of a 32 bit word and ><H for a half word
on a 32 bit ARM eForth.

This brings up the problem of word size and portability. Should ><
always swap the order of just a 16 bit value or should it operate on the
natural size of an item on the stack?

I like the functions available in C via endian.h because they are
portable. Move the code between different systems and it still works.
But it does require a large set of functions.

-- 
David W. Schultz
http://home.earthlink.net/~david.schultz
"Life without stock is barely worth living..." - Anthony Bourdain

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web