Poster | Thread |
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/subject/icon14.gif) |
ARexx: MD5 algorithm - SOLVED ! Posted on 27-Apr-2008 14:53:50
| | [ #1 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| I'm trying to write a MD5 algorithm in ARexx. The doc from the RFC is a bit too mathematical and C-ish for me, but I found some examples in Rexx on Internet.
Unfortunately, it sounds like the Amiga version of Rexx (ARexx) has trouble handling 32/64 bits values in decimal. Here is the part of the script where I get an error ("Invalid argument to function") :
/*===========================================================================*/ m32add: procedure expose c0 c1 c1111 /* add to "char" numbers, modulo 2**32, return as char */ /*===========================================================================*/ parse arg v1,v2 t1=c2d(v1)+c2d(v2) t2=d2c(t1) t3=right(t2,4,c0) return t3 v1 and v2 are 32 bits values (when converted to decimal, they are negatives). ARexx complain at the line "t2 = d2c(t1)". (I've checked the value of 't1' in its binary format, and it looks way too big to me.)
Can someone help ?
EDIT: SOLVED, thanks to Gazelle (see this post) !
Last edited by AmigaPhil on 29-Apr-2008 at 11:12 PM.
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 19:39:11
| | [ #2 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| Well, I've partly solved the problem by doing a per-byte addition of the 32 bits strings. Now, the script no more crash, but I get a wrong MD5 hash as result. So there is still something wrong with the script. I'm investigating...
(Edit: Here is the part I've changed:
/*===========================================================================*/ m32add: procedure expose c0 c1 c1111 /* add to "char" numbers, modulo 2**32, return as char */ /*===========================================================================*/ parse arg v1,v2,v3,v4 v1=reverse(right(v1,4,c0)); v2=reverse(right(v2,4,c0)) v3=reverse(right(v3,4,c0)); v4=reverse(right(v4,4,c0)) addh=0 t3='' do i=1 to 4 v1b=c2d(substr(v1,i,1)) v2b=c2d(substr(v2,i,1)) v3b=c2d(substr(v3,i,1)) v4b=c2d(substr(v4,i,1)) t1=d2c(v1b + v2b + v3b + v4b + addh) if length(t1) > 1 then addh=c2d(left(t1,1,length(t1)-1)) else addh=0 t1=right(t1,1) t3=t1 || t3 end return t3
Last edited by AmigaPhil on 29-Apr-2008 at 01:53 AM.
|
|
Status: Offline |
|
|
DBAlex
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 20:13:38
| | [ #3 ] |
|
|
![](https://amigaworld.net/images/avatar/users/5685.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 23-Jul-2006 Posts: 756
From: UK | | |
|
| @AmigaPhil
Ok... Btw, where can I learn AREXX? Is it similar to other REXX implementations or are their certain parts which are different?
Is it worth learning AREXX or can I do anything that it does in E.g. Python ? Last edited by DBAlex on 27-Apr-2008 at 09:34 PM.
_________________ A1200, 68060/64MB/1.2GB/WiFi/AGAtoCRT/OS3.9 Pegasos I, G3 600Mhz/512/9200SE/80GB WinUAE, Ryzen 5 2400G/Vega11, 8GB DDR4, 256GB SSD,Win 10 Pro x64 Amiga Forever ! ![](https://amigaworld.net/images/smilies/icon_smile.gif) |
|
Status: Offline |
|
|
nbache
![](https://amigaworld.net/images/supportertags/gold.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 21:06:39
| | [ #4 ] |
|
|
![](https://amigaworld.net/images/avatar/users/741.jpg) |
Super Member ![](https://amigaworld.net/images/ranks/4blocks.gif) |
Joined: 8-Apr-2003 Posts: 1034
From: Copenhagen, Denmark | | |
|
| @AmigaPhil
Just one thought, you may want to have a look at the NUMERIC statement (hope my memory serves me correctly). You should be able to tweak the calculation precision of ARexx with that, which might be what you need.
Best regards,
Niels
|
|
Status: Offline |
|
|
nbache
![](https://amigaworld.net/images/supportertags/gold.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 21:08:59
| | [ #5 ] |
|
|
![](https://amigaworld.net/images/avatar/users/741.jpg) |
Super Member ![](https://amigaworld.net/images/ranks/4blocks.gif) |
Joined: 8-Apr-2003 Posts: 1034
From: Copenhagen, Denmark | | |
|
| @DBAlex
Check out ARexxGuide on Aminet.
Old, but very thorough (and it's not like ARexx has changed recently anyway ).
Best regards,
Niels
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 22:17:17
| | [ #6 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @DBAlex
If you are looking for an easy to use scripting language, then go for Python, it's more powerfull and up-to-date than ARexx. However, ARexx has a long history with the Amiga (Python is only implemented since OS4.0); many programs used or can make use of ARexx. So it's still worth it to know a little bit of ARexx.
You can find documentation and many, many example scripts for ARexx on Aminet.
|
|
Status: Offline |
|
|
jack
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 22:20:01
| | [ #7 ] |
|
|
![](https://amigaworld.net/images/avatar/users/1490.jpg) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 19-Aug-2003 Posts: 650
From: Israel | | |
|
| @AmigaPhil
Is it a "must" for you to have it in rexx? I needed md5 calculation too, and since the script doesn't do it often, I wrote the relevant function that needs it as a python script (python has it "bilt-in", there's python for OS4, and probably for other variants too).
Just a thought. Jack _________________
"the expression, 'atonal music,' is most unfortunate--it is on a par with calling flying 'the art of not falling,' or swimming 'the art of not drowning.'. A. Schoenberg |
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 22:23:59
| | [ #8 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @nbache
Quote:
Just one thought, you may want to have a look at the NUMERIC statement (hope my memory serves me correctly). |
Yes, indeed. I've tried with and without a NUMERIC DIGITS statement. I've tried with 11 to 14 as value for NUMERIC DIGITS (anything above 14 is refused by ARexx). No change in the results.
(One of the Rexx script I found - for OS/2 - is using NUMERIC DIGITS 20, which is unusable on Amiga. The other one is only using NUMERIC DIGITS 11.)
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 27-Apr-2008 22:31:32
| | [ #9 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @jack
Quote:
Is it a "must" for you to have it in rexx? |
No (I know there are binary executable tools for MD5), but I wish to do it in ARexx so that the ARexx script I'm working on (and that will maybe be redistributed) will not require any other program to run. (I need a MD5 hash so that I can negociate authorization with a POP3 server using the APOP command.)
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/subject/icon2.gif) |
Re: ARexx: MD5 algorithm Posted on 28-Apr-2008 4:31:37
| | [ #10 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| I've uploaded the script to Aminet for anyone who can/want to help : ARexxMD5. The 0.1 version is in the alpha stage (not crashing, but not giving the right result).
|
|
Status: Offline |
|
|
olsen
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 28-Apr-2008 7:20:41
| | [ #11 ] |
|
|
![](https://amigaworld.net/images/avatar/blank.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 15-Aug-2004 Posts: 774
From: Germany | | |
|
| @AmigaPhil
If I may ask, why MD5? If you are after a cryptographic hash function, any that works well (for now; the MD5/SHA-1 type cryptographic hash functions are bordering on obsolescence), you might be better off with SHA-1, which tends to be easier to implement than MD5, or so I have found.
Unlike MD5, SHA-1 does not need a large table of transform values in the compression function. The compression function is practically "all code". Also, the result produced by SHA-1 is in big-endian format, which saves you the intermediate step to translate the data into little endian format.
I won't ask why you want to write this in ARexx Cryptographic hash functions are not supposed to run quickly due to the complexity of the respective compression function... |
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 28-Apr-2008 16:56:42
| | [ #12 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @olsen
Quote:
If I may ask, why MD5? [ ... ] |
Because I can't use anything else for what I want to do (see my reply to jack above).
I'm working on a ARexx script which talk to POP servers. I would like to implement APOP (POP3 command) support for it. APOP offers a little more secure transaction by the fact that authorization access to a POP server does not need sending the password in clear (the usual username/password). APOP takes as arguments the username and a MD5 hash of a string made of the session ID given by the server + the user's password. (To my knowledge, and despite MD5 is known to have weakness, the POP protocol does not support any other encryption scheme.)
I would like to have the MD5 thing in ARexx so that I can integrate it to the script I'm working on and that script will not require any other external program to run.
(Edit: Quote:
hash functions are not supposed to run quickly [in ARexx] due to the complexity of the respective compression function... |
Yes, but the string to hash is short enough to make the running time acceptable. )
Last edited by AmigaPhil on 29-Apr-2008 at 01:58 AM.
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/subject/icon2.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 0:25:28
| | [ #13 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| I *think* I have a hint:
EDIT: No, it was wrong. Removed.
Last edited by AmigaPhil on 29-Apr-2008 at 01:58 PM. Last edited by AmigaPhil on 29-Apr-2008 at 02:48 AM. Last edited by AmigaPhil on 29-Apr-2008 at 02:44 AM. Last edited by AmigaPhil on 29-Apr-2008 at 01:18 AM. Last edited by AmigaPhil on 29-Apr-2008 at 01:17 AM. Last edited by AmigaPhil on 29-Apr-2008 at 12:28 AM.
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 13:56:31
| | [ #14 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @AmigaPhil
I delete my previous post as what I thought was a hint was based on a misinterpretation of the algorithm: The message to be MD5 hashed is cut into 64 bytes (512 bits) blocks. Then, each block is processed by 16 pieces of 4 bytes (32 bits). (And that's how it should be.)
The problem lies elsewhere. Still hunting it...
|
|
Status: Offline |
|
|
Gazelle
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 14:29:44
| | [ #15 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4401.jpg) |
Regular Member ![](https://amigaworld.net/images/ranks/2blocks.gif) |
Joined: 4-Apr-2005 Posts: 117
From: Austria | | |
|
| @AmigaPhil
I don't think that there is a problem. How have you calculatet the real md5? If you append a linefeed to your test-text the md5 is correct.
instring = "This is a test string" || '0a'x
w2k with regina: C> rexx arexxmd5 Should be: b584c39f97dfe71ebceea3fdb860ed6c Test gave: b584c39f97dfe71ebceea3fdb860ed6c
And the other way around (on cygwin and w2k with regina): $ echo -n "This is a test string" >x $ md5sum <x c639efc1e98762233743a75e7798dd9c
C> rexx arexxmd5 Should be: c639efc1e98762233743a75e7798dd9c Test gave: c639efc1e98762233743a75e7798dd9c Last edited by Gazelle on 29-Apr-2008 at 02:31 PM.
|
|
Status: Offline |
|
|
Gazelle
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 14:56:18
| | [ #16 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4401.jpg) |
Regular Member ![](https://amigaworld.net/images/ranks/2blocks.gif) |
Joined: 4-Apr-2005 Posts: 117
From: Austria | | |
|
| @AmigaPhil
Another thought: Quote:
v1 and v2 are 32 bits values (when converted to decimal, they are negatives). ARexx complain at the line "t2 = d2c(t1)". |
Have you tried: "t2 = x2c(d2x(t1))" I'm not at my Amiga right now, so I can't test it myself. |
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 15:22:45
| | [ #17 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @Gazelle
Quote:
I don't think that there is a problem. How have you calculatet the real md5? If you append a linefeed to your test-text the md5 is correct. [ ... ] |
This is very interesting !! Thanks a lot for your feedback !
Here (on Amiga), the script gives:
> rx arexxmd5 Should be: b584c39f97dfe71ebceea3fdb860ed6c Test gave: c9df8a61233d2ac33dbc7b7e588bebc3
and if I append a '0a'x to the test string:
> rx arexxmd5 Should be: b584c39f97dfe71ebceea3fdb860ed6c Test gave: af0587cbba1c2ac6095a0cfe8da37066
(Note: I got the "Should be" result by using a binary MD5 program. I haven't realised that that program has appended a LF to the string I gave.)
What is helping (a bit) is to know that my script is working OK on several Rexx version, but NOT on the Amiga.
Last edited by AmigaPhil on 29-Apr-2008 at 11:25 PM. Last edited by AmigaPhil on 29-Apr-2008 at 11:24 PM. Last edited by AmigaPhil on 29-Apr-2008 at 04:47 PM.
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 15:26:01
| | [ #18 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @Gazelle
Quote:
Have you tried: "t2 = x2c(d2x(t1))" |
No, but since, I've changed the m32add() function to do a per-byte addition (see post #2).
(EDIT: I've tried your example on the original (post #1) m32add() function, with the same result: the script crash ("Invalid argument to function") at that line.)
Last edited by AmigaPhil on 29-Apr-2008 at 04:05 PM.
|
|
Status: Offline |
|
|
Gazelle
| ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 15:46:21
| | [ #19 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4401.jpg) |
Regular Member ![](https://amigaworld.net/images/ranks/2blocks.gif) |
Joined: 4-Apr-2005 Posts: 117
From: Austria | | |
|
| @AmigaPhil
Quote:
What is helping (a bit) is to know that my script is working OK on several Rexx version, but NOT on the Amiga. |
Maybe it has something to do with the "c0=d2c(0)" and the "v1=reverse(right(v1,4,c0))..." you are doing in m32add().
Try this: /**/
c0=d2c(0)
test_d = 5898357 test_c = d2c(test_d)
v1=reverse(right(test_c,4,c0))
say c2x(test_c) say c2x(v1)
exit
It should output: 5A0075 75005A00
|
|
Status: Offline |
|
|
AmigaPhil
![](https://amigaworld.net/images/supportertags/silver.gif) | ![](https://amigaworld.net/images/icons/posticon.gif) |
Re: ARexx: MD5 algorithm Posted on 29-Apr-2008 15:54:15
| | [ #20 ] |
|
|
![](https://amigaworld.net/images/avatar/users/4050.gif) |
Cult Member ![](https://amigaworld.net/images/ranks/3blocks.gif) |
Joined: 21-Jan-2005 Posts: 563
From: Earth (Belgium) | | |
|
| @Gazelle
Quote:
Same results here.
|
|
Status: Offline |
|
|