Page 1 of 1

simply script ascii to hex

Posted: 24 Jun 2022 09:42
by swan_x
hi there, i need a simply script to rename a selected file to hex value and viceversa
any tips?

Re: simply script ascii to hex

Posted: 25 Jun 2022 09:31
by swan_x
my request it's really hard?
i see 31 views to my thread but 0 replies

and it's really strange for me: from web resource there are many sites that allow this, such as:
https://online-toolz.com/tools/text-hex-convertor.php
https://onlinehextools.com/convert-text-to-hex
https://www.calculators.tech/text-to-hex

and also on np++ have a good plug-in Converter ascii to hex and viceversa, but i would like a script to use directly in xy for the renaming of any file, without going through np++ or browser

but perhaps it is more the will that does not want to answer than the problem itself.
and even if don't understand the reason, ok i accept this and i will look for other solutions

Re: simply script ascii to hex

Posted: 25 Jun 2022 09:53
by admin
Look up asc() and hex().

Re: simply script ascii to hex

Posted: 25 Jun 2022 12:59
by Norn

Code: Select all

"Text to Hex (Rename base)"
 $items = get("selecteditemspathnames");
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    renameitem($hexdump, $item);
}

"Hex to Text (Rename base)"
 $items = get("selecteditemspathnames");
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $hexdump = hexdump($itemName, 1, "ri"); 
    renameitem($hexdump, $item);
}

-

"Text to Hex (Rename all)"
 $items = get("selecteditemspathnames");
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    renameitem($hexdump, $item, 3);
}

"Hex to Text (Rename all)"
 $items = get("selecteditemspathnames");
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, "ri"); 
    renameitem($hexdump, $item, 3);
}
Rename selected items at once:

Code: Select all

"Text to Hex (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, "ri");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

-

"Text to Hex (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, "ri"); 
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

Re: simply script ascii to hex

Posted: 25 Jun 2022 14:42
by swan_x
@Norn a big thank you for your code

just a note: for my intent, i need only the second part, 'Rename selected items at once'

Code: Select all

"Text to Hex (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, "ri");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;
but with this code, all space is converted in hex on 00
example: if i have to rename New Text File.txt with your code i have 4E0065007700200054006500780074002000460069006C006500.txt
with this link (only to example) https://online-toolz.com/tools/text-hex-convertor.php i have:
New Text File.txt -----> 4e657720546578742046696c65
without 00 and all letter lowercase

Re: simply script ascii to hex

Posted: 25 Jun 2022 14:58
by RalphM
swan_x wrote: 25 Jun 2022 09:31 my request it's really hard?
i see 31 views to my thread but 0 replies
Really, this was after one day - maybe you should increase your patience and decrease the neediness! :whistle:

Re: simply script ascii to hex

Posted: 25 Jun 2022 15:32
by admin
Decreasing laziness might also be a way.

Re: simply script ascii to hex

Posted: 25 Jun 2022 19:12
by Norn

Code: Select all

"Without 00 (English only):"

-

"Text to Hex (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, r);
	$hexdump = replace($hexdump, " 00 ", "");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
	    $case = "1";
        $pos = "";
		$newBase = "";
	    while ($pos++ < strlen($itemName)) {
          $word = gettoken($itemName, $pos, "");
          $next = gettoken($itemName, $pos + 1, "");
		  if $case == "2" {$case = "1"}
		  if $case == "0" {$case = "2"}
          if($case == "1") {$newBase .= "$word$next" . " 00 "; $case = "0";}
        }
    $hexdump = hexdump($newBase, 1, "ri");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

-

"Text to Hex (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, r); 
	$hexdump = replace($hexdump, " 00 ", "");
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
	    $case = "1";
		$pos = "";
		$newBase = "";
	    while ($pos++ < strlen($itemName)) {
          $word = gettoken($itemName, $pos, "");
          $next = gettoken($itemName, $pos + 1, "");
		  if $case == "2" {$case = "1"}
		  if $case == "0" {$case = "2"}
          if($case == "1") {$newBase .= "$word$next" . "00"; $case = "0";}
        }
    $hexdump = hexdump($newBase, 1, "ri"); 
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

-

"Support non-English:"

-

"Text to Hex (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename base)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2");
    $itemEXT = regexreplace($item, "(.*\\)(.*)(....)", "$3");
    $hexdump = hexdump($itemName, 1, "ri");
    $newNames .= "$hexdump$itemEXT<crlf>";
}
 rename l, $newNames, , $items;

-

"Text to Hex (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, r); 
    $hexdump = replace($hexdump, " ", "");
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

"Hex to Text (Rename all)"
 $items = get("selecteditemspathnames");
 $newNames = "";
 foreach($item, $items, "<crlf>", e) {
    $itemName = regexreplace($item, "(.*\\)(.*)(....)", "$2$3");
    $hexdump = hexdump($itemName, 1, "ri"); 
    $newNames .= "$hexdump<crlf>";
}
 rename l, $newNames, , $items;

Re: simply script ascii to hex

Posted: 25 Jun 2022 19:30
by swan_x
simply wonderful

Thank you so much Norn