4

Is there a program or CMD command with which I can simply reverse or flip all the bytes of a file? For example if I have a text file (as a simple example) that says "Hello, world!", the program/command would flip it to say "!dlrow ,olleH".

So yeah, is there any way to do this? I'm a programmer and know that it would be trivial to write my own program for this, but I'd rather not go through the trouble if there's already something that can do it. A batch script would also be OK.

puggsoy
  • 407

2 Answers2

7
powershell $s='Hello, world!';$s[-1..-($s.length)]-join''

file:

way 1:

powershell $f=[IO.File]::ReadAllBytes('.\file.txt');$t=[Text.Encoding]::ASCII.GetString($f);$t[-1..-($t.length)]-join''

way 2:

powershell [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic');$s=gc .\file.txt;[Microsoft.VisualBasic.Strings]::StrReverse($s)

byte reverse:

slow:

powershell [byte[]]$b=gc '.\file.bin' -En byte;[array]::Reverse($b);[IO.File]::WriteAllBytes('.\Reverse.bin',$b)

fast:

powershell [byte[]]$b=[IO.File]::ReadAllBytes('.\file.bin');[array]::Reverse($b);[IO.File]::WriteAllBytes('.\Reverse.bin',$b)
STTR
  • 6,891
0

"CMD command with which I can simply reverse or flip all the bytes of a file":

REM set content to file
set /p="Hello, world!"> test
certutil -encodehex -f test temp 4

REM reverse file contents set rev= (for /f "delims=" %i in (temp) do for %j in (%i) do set rev=%j !rev!) set /p="%rev:~0,-6%">temp certutil -decodehex temp out.txt

Tested on Win 10 CMD

Zimba
  • 1,291