WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: oradba4u on February 20, 2021, 08:23:08 AM

Title: Binary files anyone?
Post by: oradba4u on February 20, 2021, 08:23:08 AM
ALL:
I currently have an ASCII text file that I am using a WinBatch program to read/write. It contains sensitive information, and I'd like to know if there is a file format (like, binary?) that I can read/write that will replace the ASCII text file. I'm really not looking for encrypted top-secret kind of stuff, just something to keep looky-loo's from easily opening notepad to view it.

As always, thanks in advance
Title: Re: Binary files anyone?
Post by: stanl on February 20, 2021, 08:33:02 AM
Wow, more homework. Don't know if there is any 'top secret' stuff, but there are multiple ways to encrypt/decrypt in WB... think the Tech DB has a few. But, if you post the structure and some sample data you want encrypted, I'm sure you will get positive responses.


[EDIT]: probably base 64 will suit your needs


[EDIT 2]: actually I want Tony to come up with CLR code for : RijndaelManaged Class
Title: Re: Binary files anyone?
Post by: oradba4u on February 20, 2021, 08:42:25 AM
Data file is the same as the comma-delimited problem I was having a few days ago...

Here's a sample of what I've got:

Data file looks something like this:

Line 1 - Data File
1,2,3,4,5,6,7,8,9,10
2,3,4,,5,,6,7,,8,9,10,1
3,4,5,6,7,8,9,10,1,2
4,5,6,7,8,9,10,1,2,3
5,6,7,8,9,10,1,2,3,4
6,7,8,9,10,1,2,3,4,5
Title: Re: Binary files anyone?
Post by: ChuckC on February 21, 2021, 05:17:18 AM
Use a technique such as ROT13 for basic obfuscation of text where you need to read & process the text on a per-character basis without having to convert the entire file to plaintext before working with it.  ROT13 has been around for a long time, with historical origins of the technique going back as far the Roman army using to protect written messages.
Title: Re: Binary files anyone?
Post by: stanl on February 21, 2021, 07:30:49 AM
thanks Chuck... pretty simple but can be made more complex
Code (WINBATCH) Select


text = "This is Test 5"
offset = 13
rot=""
;encrypt
For i = 1 To Strlen(text)
   char= StrSub(text,i,1)
   rot= rot:num2char(char2num(char)+13)
Next


Message(text,rot)


;decrypt
text=""
For i = 1 To Strlen(rot)
   char= StrSub(rot,i,1)
   text= text:num2char(char2num(char)-13)
Next


Message(rot,text)


Title: Re: Binary files anyone?
Post by: ChuckC on February 21, 2021, 11:52:51 AM
Don't forget the modulo arithmetic for either unsigned 8 bit code points [ASCII/ANSI] or unsigned 16 bit code points.  Rollover above 255 or 65535 and underflow below zero must be accounted for if the rotated value is to be stored in the same byte or word in the file.
Title: Re: Binary files anyone?
Post by: stanl on February 21, 2021, 12:57:46 PM
Quote from: ChuckC on February 21, 2021, 11:52:51 AM
Don't forget the modulo arithmetic for either unsigned 8 bit code points [ASCII/ANSI] or unsigned 16 bit code points.  Rollover above 255 or 65535 and underflow below zero must be accounted for if the rotated value is to be stored in the same byte or word in the file.


I won't forget, but then it's not my thread :D
Title: Re: Binary files anyone?
Post by: JTaylor on February 21, 2021, 01:46:06 PM
That goes without saying...how could anyone forget that?   ;)
Title: Re: Binary files anyone?
Post by: ChuckC on February 21, 2021, 01:56:41 PM
That should be easy enough to remember.... it's the two imaginary irrational cube roots of -1 that are more often not thought about...

Title: Re: Binary files anyone?
Post by: stanl on February 22, 2021, 02:36:20 AM
Quote from: ChuckC on February 21, 2021, 01:56:41 PM
That should be easy enough to remember.... it's the two imaginary irrational cube roots of -1 that are more often not thought about...


which goes down easy after a 6-pack of Occam's Razor
Title: Re: Binary files anyone?
Post by: stanl on February 22, 2021, 07:59:04 AM
makes it a little trickier, if you remember the offset... [run several times for different results]
Code (WINBATCH) Select


text = "This is Test 5"
offset = Random((255 -122)/2)
rot=""
;encrypt
For i = 1 To Strlen(text)
   char= StrSub(text,i,1)
   rot= rot:num2char(char2num(char)+offset)
Next


Message(text,rot)


;decrypt
text=""
For i = 1 To Strlen(rot)
   char= StrSub(rot,i,1)
   text= text:num2char(char2num(char)-offset)
Next


Message(rot,text)





Title: Re: Binary files anyone?
Post by: cssyphus on May 18, 2021, 09:18:14 AM
This message late to the party, but don't forget about Alan Kreutzer's RC4 encryption extender - makes the job quite easy:

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/_Third~Party~Extenders/RC4


rc4encrypt(PlainText, Key)
rc4decrypt(EncryptedText, Key)
rc4binary(Pointer, Key)