I have a working script in Powershell:
function md5($text){
$md5 = New-Object System.Security.Cryptography.MD5CryptoServiceProvider
$md5.ComputeHash([Text.Encoding]::utf8.getbytes($text))|%{$HC=''}{$HC+=$_.tostring("x2")}{$HC}
}
$Password="D e o t 2 3 3 S w i t c h"
$Challenge="6 1 7 e 3 d 3 f"
$Code1=$Challenge+"-"+$Password
echo $Code1
# gives "617e3d3f-Deot233Switch"
$Code2=[char[]]$Code1|%{$Code2=""}{$Code2+=$_+[Char]0}{$Code2}
echo $Code2
# gives "6 1 7 e 3 d 3 f - D e o t 2 3 3 S w i t c h"
# I dont know how to do that in Shell
$Response= $(md5($Code2))
echo $Response
# gives "7a856cb4a061ec00ffdf9bca23caffa2"
# I this is the correct calculated Value!!!!!
Now I have to "translate" this script in shell ( to work on a synology diskstation) But the calculated results do not match, I need help.
I tried this:
#!/bin/sh
Password = "D e o t 2 3 3 S w i t c h"
Challenge = "6 1 7 e 3 d 3 f"
hash3=$(echo -n "$Challenge-$Password" |sed -e 's,.,&\n,g' | tr '\n' '\0' | md5sum | grep -o "[0-9a-z]\{32\}")
echo "[hash32]$hash3" #[hash32]494e6cec7483a4ee0938895519a84bc7
hash4=$(echo -n "$Challenge-$Password" | md5sum )
echo "[hash4]$hash4" #[hash4]336d5ebc5436534e61d16e63ddfca327 -
hash5=$(echo -n "$Challenge-$Password" | md5sum | grep -o "[0-9a-z]\{32\}")
echo "[hash5]$hash5" #[hash5]336d5ebc5436534e61d16e63ddfca327
hash6=$(echo -n "$Challenge-$Password" |sed -e 's,.,&\n,g'| md5sum | grep -o "[0-9a-z]\{32\}")
echo "[hash6]$hash6" # [hash6]0a1f21a3417389e0c0a13392c79a7a89
# the "sed -e 's,.,&\n,g'" maybe the key?
I don't really understand the options, just know that the md5 produced dont match.
Maybe someone sees the error, thank you