Simple batch Cryptography: howto crypt / decrypt ROT13:

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
jeb
Expert
Posts: 1042
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Simple batch Cryptography: howto crypt / decrypt ROT13:

#31 Post by jeb » 26 Apr 2011 15:35

Nice improvements, :)

but I tried to convert my 25GB of pictures, but it fails at the <NUL> bytes :wink:

But I remember that I wrote a simple solution to read binary data with batch files.\[url=http://example.com\]my Example\[/url\]

Code: Select all

@echo off
SETLOCAL EnableDelayedExpansion
set filesize=%~z1
set "hexVal=41"
set "x10=AAAAAAAAAA"

set /a chunks=1+filesize / 10

del dummy.txt 2>nul > nul
for /L %%n in (0,1,%chunks%) DO (
  <nul >> dummy.txt set /p ".=%x10%"
)

set /a expectedNum=0
for /F "eol=F usebackq tokens=1,2 skip=1 delims=:[] " %%A in (`fc /b "%~dpf1" dummy.txt`) DO (
    set /a num=0x%%A && (
            set /a numDec=num-1
        set "hex=%%B"

        for /L %%n in (!expectedNum!=,=1 !numDec!) DO (
            echo %hexVal%
        )
        set /a expectedNum=num+1
        echo !hex!
    )
)


The idea is to use the hex-output of FC (file compare).
First I create a file with (nearly) the same length, and then I compare them with FC in binary mode (/B), the output is scanned and if a line missings are detected, they are filled with the hexVal of the x10 string (in this case 0x41='A').

Perhaps you can enhance your rot13 encoder a bit :D

jeb@texel

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Simple batch Cryptography: howto crypt / decrypt ROT13:

#32 Post by aGerman » 26 Apr 2011 17:28

You guys have really fantastic ideas. I'm impressed again.

Regards
aGerman

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Simple batch Cryptography: howto crypt / decrypt ROT13:

#33 Post by dbenham » 27 Apr 2011 23:37

Thanks for the feedback aGerman :D

Jeb - I don't see the point in making further modifications to ROT13. It is not really appropriate for binary files. As far as I'm concerned the final version at the end of page 2 is "production ready".

That being said, your binary file reader is very interesting.

Obviously the performance of the temp file creation can be dramatically improved. I was pleasantly surprised that the following works, and it is very efficient:

Code: Select all

<nul >%dummy% set /p ".=A"
set dummySize=1
for /l %%n in (1,1,32) do (if !dummySize! lss %filesize% set /a "dummySize*=2" & type %dummy% >>%dummy%)


I also found a bug - the end of the file is truncated if it ends with the dummy file character (0x41 in your case). This is easily fixed by appending the following after the loop:

Code: Select all

set /a expectedNum+=1
for /l %%n in (%expectedNum%,1,%filesize%) do echo %hexVal%

At least I think the above works - I was using a variant of your code so the above is untested, but the concept is there.

If only someone (Jeb :?: ) could figure out how to write a NULL character using batch, we would then have all the tools necessary to fully explore our masochistic tendencies by editing binary files with batch! :wink:

I think I have found a good use for your binary file technique. I've posted a hexDump utility based on the FC technique.


Dave Benham

Post Reply