simply script ascii to hex

Discuss and share scripts and script files...
Post Reply
swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

simply script ascii to hex

Post by swan_x »

hi there, i need a simply script to rename a selected file to hex value and viceversa
any tips?

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: simply script ascii to hex

Post 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

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: simply script ascii to hex

Post by admin »

Look up asc() and hex().

Norn
Posts: 416
Joined: 24 Oct 2021 16:10

Re: simply script ascii to hex

Post 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;
Win10, Win11 @100% 2560x1440 22H2

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: simply script ascii to hex

Post 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

Online
RalphM
Posts: 1932
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: simply script ascii to hex

Post 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:
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: simply script ascii to hex

Post by admin »

Decreasing laziness might also be a way.

Norn
Posts: 416
Joined: 24 Oct 2021 16:10

Re: simply script ascii to hex

Post 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;
Win10, Win11 @100% 2560x1440 22H2

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: simply script ascii to hex

Post by swan_x »

simply wonderful

Thank you so much Norn

Post Reply