Page 1 of 1

text msg encrypter

Posted: 02 Dec 2013 13:27
by dwngrt
Hello dear people :D

So i was washing dishes and suddenly i thought of this "msg encrypter"...
i though it would be doable but i seem to fail at getting my idea to work, and it makes me very upset XD
so here is the code and yeah the idea is just to output a different alphabet.

The problem is not that it outputs every character on a new line, i has an idea how to get this maybe to work, but not sure about that either... the problem is it only outputs ECHO is off. to the txt file :o

here ya go

Code: Select all

@echo off && cls && title MSG Encrypter V1.0
:root
set i=
cls
if exist encrypted_msg.txt type encrypted_msg.txt
echo.
CHOICE /C abcdefghijklmnopqrstuvwxyz1234567890>nul
    IF %errorlevel%==1 set i=7&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==2 set i=x&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==3 set i=h&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==4 set i=4&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==5 set i=a&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==6 set i=z&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==7 set i=b&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==8 set i=i&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==9 set i=j&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==10 set i=8&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==11 set i=2&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==12 set i=l & echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==13 set i=p&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==14 set i=q&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==15 set i=w&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==16 set i=c&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==17 set i=f&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==18 set i=y&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==19 set i=9&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==20 set i=0&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==21 set i=y&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==21 set i=k&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==22 set i=v&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==23 set i=o&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==24 set i=e&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==25 set i=5&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==26 set i=1&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==27 set i=n&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==28 set i=s&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==29 set i=m&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==30 set i=u&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==31 set i=t&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==32 set i=r&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==33 set i=6&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==34 set i=3&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==35 set i=d&& echo %i%>>encrypted_msg.txt && goto root
   IF %errorlevel%==36 set i=g&& echo %i%>>encrypted_msg.txt && goto root
goto root


hope anyone has a good idea on how to get this to work, thanks in advanced ^_^!

Re: text msg encrypter

Posted: 02 Dec 2013 15:35
by penpen
You may use a technique, described here to do what you want: http://www.dostips.com/forum/viewtopic.php?f=3&t=5050:

Code: Select all

@echo off
setlocal enableDelayedExpansion

set "code[a]=7"
set "code[b]=x"
set "code[c]=h"
set "code[d]=4"
set "code[e]=a"
set "code[f]=z"
set "code[g]=b"
set "code[h]=i"
set "code[i]=j"
set "code[j]=8"
set "code[k]=2"
set "code[l]=l"
set "code[m]=p"
set "code[n]=q"
set "code[o]=w"
set "code[p]=c"
set "code[q]=f"
set "code[r]=y"
set "code[s]=9"
set "code[t]=0"
set "code[u]=k"
set "code[v]=v"
set "code[w]=o"
set "code[x]=e"
set "code[y]=5"
set "code[z]=1"
set "code[1]=n"
set "code[2]=s"
set "code[3]=m"
set "code[4]=u"
set "code[5]=t"
set "code[6]=r"
set "code[7]=6"
set "code[8]=3"
set "code[9]=d"
set "code[0]=g"

set "coded="
for /F %%a in ('cmd /d /u /c type "encrypted_msg.txt" ^| find /v "" ^| findstr "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0"') do (
   set "coded=!coded!!code[%%a]!"
)
for /F %%a in ('type encrypted_msg.txt') do echo code["%%a"]="!coded!"
endlocal

Re: text msg encrypter

Posted: 02 Dec 2013 16:26
by Batch Artist
penpen wrote:You may use a technique, described here to do what you want: http://www.dostips.com/forum/viewtopic.php?f=3&t=5050:

Code: Select all

@echo off
setlocal enableDelayedExpansion

set "code[a]=7"
set "code[b]=x"
set "code[c]=h"
set "code[d]=4"
set "code[e]=a"
set "code[f]=z"
set "code[g]=b"
set "code[h]=i"
set "code[i]=j"
set "code[j]=8"
set "code[k]=2"
set "code[l]=l"
set "code[m]=p"
set "code[n]=q"
set "code[o]=w"
set "code[p]=c"
set "code[q]=f"
set "code[r]=y"
set "code[s]=9"
set "code[t]=0"
set "code[u]=k"
set "code[v]=v"
set "code[w]=o"
set "code[x]=e"
set "code[y]=5"
set "code[z]=1"
set "code[1]=n"
set "code[2]=s"
set "code[3]=m"
set "code[4]=u"
set "code[5]=t"
set "code[6]=r"
set "code[7]=6"
set "code[8]=3"
set "code[9]=d"
set "code[0]=g"

set "coded="
for /F %%a in ('cmd /d /u /c type "encrypted_msg.txt" ^| find /v "" ^| findstr "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0"') do (
   set "coded=!coded!!code[%%a]!"
)
for /F %%a in ('type encrypted_msg.txt') do echo code["%%a"]="!coded!"
endlocal

Your code did not work for me.

"This file type is unspecified" it says.

Re: text msg encrypter

Posted: 02 Dec 2013 17:27
by Magialisk
There's an existing (incomplete) thread on encoding strings here: viewtopic.php?f=3&t=4579.

The first several posts on that thread are essentially the same technique as penpen suggested. Obviously that technique is not secure (not sure if you care?) as anyone can right click -> edit your batch and see that 7=a, x=b, etc.

I posted a number of more secure techniques to the above thread including:
1) A simple substitution, just like the above technique except it uses a different random substitution for each letter. So for example 7 might be an "a" in one word, but a "p" in the next.
2) A Vigenere cipher, that acts like a set of simple Ceasar ciphers on each letter of the input text (ie: rotate "A" by 3 to get "D", then change the 3 to something else for the next letter), and doesn't require a random number generator.

While these techniques themselves are not "that" secure, cryptographically speaking, at least the source code does not give the attacker a Rosetta stone to work with. They both require a password/key to retrieve the encrypted text, which is not contained in the batch file for an attacker to find.

If you really want to get serious about encoding your text, at the end of the above thread I posted a WWII Enigma machine simulator, that provides reasonably strong security, even by modern cryptographic standards. I also created (and the DOStips community has helped to evolve/improve) a 256-bit AES cipher that uses the same encryption used by world militaries, NSA, etc.. That thread is here: viewtopic.php?f=3&t=5048. As should be expected, the latter two functions are much more complicated, but the Vigenere and random substitution are very simple and provide more than adequate security for simple batch encoding.

I'd be happy to help if this is a topic that you'd like to experiment with further. If it was just a thought experiment gone awry over dirty dishes, then I apologize for this deluge of unwanted information :D

Re: text msg encrypter

Posted: 02 Dec 2013 18:56
by penpen
Batch Artist wrote:
penpen wrote:...

Your code did not work for me.

"This file type is unspecified" it says.
I assume you haven't created a file named "encrypted_msg.txt" (without double quotes).
I have used this file, as dwngrt has used it in the opening post.
Try the following:
1) Save may above batch script as "encrypt.bat" (without double quotes).
2) Open a cmd shell (use the path where encrypt.bat can be found; in this case Z:\) and type as follows:

Code: Select all

Z:\>echo cleartext>"encrypted_msg.txt"

Z:\>encrypt
code["cleartext"]="hla7y0ae0"
The result should be the same.

penpen

Edit: To make it a little bit more complicated for attackers, you may encrypt the batch script like dbenham has done it here:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4876

Re: text msg encrypter

Posted: 02 Dec 2013 20:49
by Magialisk
I can't believe I forgot about dbenham's adventure game! When I first saw the way he self-encrypted his code and did on-the-fly decryption at run-time I thought it was no kidding one of the most clever batch ideas I'd seen. :D

Just for fun I thought I'd poke at it and see if I could decipher it, and unfortunately I got lucky on the first try and completely ruined my own fun. Looking at the code I saw a lot of repeated sequences, which basically guaranteed it to be a monoalphabetic cipher. In other words, the same letter is always used to replace the same letter. If A = B, A will always = B, etc. In particular the word "bow" stood out quite a bit at the top of the script.

On a hunch, suspecting the most simple of encodings since this was really meant more to obscure than protect, I thought I'd try to decode "bow" using ROT13, then if that didn't work I'd try a Caesar cipher (3 position shift), and if that didn't work I'd think about what to do next. Needless to say, the ROT13 of "bow" decoded to "obj" which seemed like plausible English, so I tried "bowrpg", "bowrpgf" and the first encrypted word in the script "Inevnoyr". These gave "object", "objects", and "Variable", so clearly I'd guessed the right cipher. Oh well.

In any case, ever since that little experiment I always wanted to do a full decryption of dbenham's code using the secret keyword from his post, so I could look at the algorithms he uses for on-the-fly [en/de]cryption. My intent would be to replace the ROT13 with one of my polyalphabetic ciphers, for example the Vigenere cipher. The basic encoding function would be unchanged that way, except that the number of positions to shift would be changed after every letter. It's completely unnecessary for this use case of game text obfuscation, but I had other uses in mind where just a tad more security without going crazy would be nice. I've never gotten around to actually doing this, but now that you reminded me about it maybe I'll give it a look sooner rather than later. :lol: