/* NetBIOS name mangler / de-mangler By Casey Halverson www.maokhian.com Feel free to do what you please with this piece of code! */ /* if arg(1)="" then do signal ar end 01000110 if words(arg(1))~=2 then signal ar if word(arg(1),1)~="-decode"&&word(arg(1),1)~="-encode" then do signal ar end */ if word(arg(1),1)="-decode" then do a=0 b=0 str="" text=word(arg(1),2) q=length(text) do i=1 to q by 2 nibble_ascii=substr(text,i,2) /* grab a pair of characters */ u.1=substr(nibble_ascii,1,1) /* break them apart */ u.2=substr(nibble_ascii,2,1) ux.1=c2d(u.1) /* convert them to decimal */ ux.2=c2d(u.2) ux.1=ux.1-65 /* subtract 0x41 from them */ ux.2=ux.2-65 ub.1=x2b(ux.1) /* convert the nibbles to binary */ ub.2=x2b(ux.2) /* this routine fixes the insignificant zero "problem" in the function. REXX strips off left zeros, so this will put them back on so we can properly combined these into bytes again */ if length(ub.1)=1 then ub.1="000"ub.1 if length(ub.1)=2 then ub.1="00"ub.1 if length(ub.1)=3 then ub.1="0"ub.1 if length(ub.2)=1 then ub.2="000"ub.2 if length(ub.2)=2 then ub.2="00"ub.2 if length(ub.2)=3 then ub.2="0"ub.2 binary_byte=ub.1||ub.2 /* merge our nibbles into a byte */ letter=x2c(b2x(binary_byte)) /* convert back to character format */ str=str||letter end say 'NetBIOS Name: "'str'"' exit end if word(arg(1),1)="-encode" then do a=0 b=0 str="" text=subword(arg(1),2) do i=1 to 16 ascii=substr(text,i,1) /* grab a character */ binary=x2b(c2x(ascii)) /* get a binary number out of it */ binaryold = binary if length(binary)=9 then binary="0000000"binary if length(binary)=10 then binary="000000"binary if length(binary)=11 then binary="00000"binary if length(binary)=12 then binary="0000"binary if length(binary)=13 then binary="000"binary if length(binary)=14 then binary="00"binary if length(binary)=15 then binary="0"binary nb.1=substr(binary,1,4) /* get first nibble */ nb.2=substr(binary,5,4) /* get second nibble */ nd.1=x2d(b2x(nb.1)) /* convert nibbles to decimal */ nd.2=x2d(b2x(nb.2)) nd.1=nd.1+65 /* Add it with the $41 value */ nd.2=nd.2+65 str=str||d2c(nd.1)||d2c(nd.2) /* convert back, add it to string */ end say "encoded string: "str exit end ar: say "mangler.rexx [-encode|-decode] source" exit /* do i=1 to q step 2 a=c2d(substr(text,i,1)) b=c2d(substr(text,i+1,1)) a=a-65 b=b-65 nible.1=x2b(d2x(a)) nible.2=x2b(d2x(b)) str = str||x2c(b2x(nible.1||nible.2)) end say str say x2b(d2x(42)) b2x(0010 */