Computer Hope

Microsoft => Microsoft DOS => Topic started by: millergram on February 11, 2011, 04:25:35 AM

Title: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 04:25:35 AM
I would like to know how to make a batch that converts a custom code of numbers like "486739" into letters like "Hello"
can this be done?
Title: Re: .bat that translates custom code to words
Post by: polle123 on February 11, 2011, 08:19:33 AM
yes it can be done, please explain presisly what you want. You want 1=A, 2=B, or something like that?
Title: Re: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 10:19:36 AM
Yes exctaly
Title: Re: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 10:19:56 AM
Yep
yes it can be done, please explain presisly what you want. You want 1=A, 2=B, or something like that?
Title: Re: .bat that translates custom code to words
Post by: mat123 on February 11, 2011, 11:46:21 AM
ah what do you want to use to separate the numbers because Z=26,B=2,and F=6 does 26=Z or 26=BF we dont know unless you separate the numbers.
Title: Re: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 04:26:08 PM
first i have to know how to apply letters to nums and yes i well make it like 1=c 24=z 45=d and so on or with num first idk how it goes
Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 11, 2011, 04:58:40 PM
exctaly

Is that code too?
Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 11, 2011, 05:00:50 PM
Quote
"486739" into letters like "Hello"

Why has 486739 got 6 figures and hello only 5 letters?


Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 11, 2011, 05:02:46 PM
yes it can be done

Interested to see your demo code
Title: Re: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 05:25:38 PM
486739 that was just off the top of my head but i guess if would be somtin like this
48=h
6=e
7=l
3=l
9=o

Even thou that not the right format
Title: Re: .bat that translates custom code to words
Post by: millergram on February 11, 2011, 05:32:10 PM
Im a noob at this but heres what i got
Code: [Select]
@echo off
set man=5
:main
if %man%==0 goto no
cls
echo.you have %man% tries left
set /p Msn=Here:
if "%msn%"=="jdhafj" goto no
echo.Wrong
goto yes

:no
echo.Error Code=Nm17*d
pause

:yes
set /a man=%man%-1
goto main
This first one gives an error code when you guess wrong 5 times

Code: [Select]
@echo off
set a=1
set b=4
set c=7
set d=9
set e=*d
set f=Nm
set g=jl
set h=lj
set i=90
set l=45
set p=89
:main
set /p do=Input code:
if "%do%"=="%f%%a%%c%%e%" goto yes
goto main

:yes
echo.Password=face
pause
cls
goto main

and the one above translates to the word face but i need the whole alphabet to be possible if you know what i mean
Title: Re: .bat that translates custom code to words
Post by: mat123 on February 12, 2011, 02:46:16 AM
are you turning letters into numbers or vica-verca
Title: Re: .bat that translates custom code to words
Post by: millergram on February 12, 2011, 03:39:33 AM
vice versa
Title: Re: .bat that translates custom code to words
Post by: polle123 on February 12, 2011, 03:46:35 AM
Interested to see your demo code

How about a for loop that uses a space as a delimmiter and then makes 1=a, 2=b and so on.
It can't be done without spaces as this would indeed cause confusion where 26= z and at the same time 26= bf
Title: Re: .bat that translates custom code to words
Post by: millergram on February 12, 2011, 04:01:28 AM
idk how to use delimiters  at all
Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 12, 2011, 04:17:24 AM
This sounds like one of the earliest "secret codes" ever used, the substitution code. The Roman emperor Julius Caesar who died in the year 44 BC used such a code, which is named after him. The problem you are going to have is that you seem to want to make letters of the alphabet into numbers, and there are 26 letters in the alphabet but only 10 digits (0 to 9), so you cannot have a simple one-to-one translation. You could encode each letter of the alphabet into a two digit number, but you are going to run into all kinds of problems if you have some one and some two-digit numbers, as some people have already pointed out. Also batch scripting is about the worst language I can think of for doing this. A "scrambled alphabet" type of code is quite simple to implement in batch, but the code is not beginner's level.

http://en.wikipedia.org/wiki/Substitution_cipher

Title: Re: .bat that translates custom code to words
Post by: mat123 on February 12, 2011, 04:30:54 AM
Code: [Select]
@echo off
setlocal ENABLEDELAYEDEXPANSION
set /p c=enter number sequence:
set c1=%c:~0,1%
if not %c1%==, set c=,%c%
set d=%c:,26=z%
set d=%d:,25=y%
set d=%d:,24=x%
set d=%d:,23=w%
set d=%d:,22=v%
set d=%d:,21=u%
set d=%d:,20=t%
set d=%d:,19=s%
set d=%d:,18=r%
set d=%d:,17=q%
set d=%d:,16=p%
set d=%d:,15=o%
set d=%d:,14=n%
set d=%d:,13=m%
set d=%d:,12=l%
set d=%d:,11=k%
set d=%d:,10=j%
set d=%d:,9=i%
set d=%d:,8=h%
set d=%d:,7=g%
set d=%d:,6=f%
set d=%d:,5=e%
set d=%d:,4=d%
set d=%d:,3=c%
set d=%d:,2=b%
set d=%d:,1=a%
echo %d%
pause
Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 12, 2011, 04:37:57 AM
Quote
setlocal ENABLEDELAYEDEXPANSION

What does this line do?

also...

Code: [Select]
C:\Batch>test1.bat
enter number sequence:12
'c' is not recognized as an internal or external command,
operable program or batch file.
12
Title: Re: .bat that translates custom code to words
Post by: mat123 on February 12, 2011, 04:53:27 AM
the set local was copied/pasted from my template forgot to remove it ;) anyways the fixed code is
Code: [Select]
@echo off
set /p c=enter number sequence:
set /a c1=%c:~0,1%
if not %c1%==- set c=-%c%
rem debug line echo %c% %c1%
set d=%c:-26=z%
set d=%d:-25=y%
set d=%d:-24=x%
set d=%d:-23=w%
set d=%d:-22=v%
set d=%d:-21=u%
set d=%d:-20=t%
set d=%d:-19=s%
set d=%d:-18=r%
set d=%d:-17=q%
set d=%d:-16=p%
set d=%d:-15=o%
set d=%d:-14=n%
set d=%d:-13=m%
set d=%d:-12=l%
set d=%d:-11=k%
set d=%d:-10=j%
set d=%d:-9=i%
set d=%d:-8=h%
set d=%d:-7=g%
set d=%d:-6=f%
set d=%d:-5=e%
set d=%d:-4=d%
set d=%d:-3=c%
set d=%d:-2=b%
set d=%d:-1=a%
echo %d%
pause
Title: Re: .bat that translates custom code to words
Post by: Salmon Trout on February 12, 2011, 05:39:50 AM
You could encode each letter of the alphabet into a two digit number

Code: [Select]
@echo off

set input=MARY HAD A LITTLE LAMB

REM Encode
set output=
rem loop through the string
set j=0
:Loop1
call set inchar=%%input:~%j%,1%%
if "%inchar%"=="" goto ExitLoop1
IF "%inchar%"=="A" set outchar=01
IF "%inchar%"=="B" set outchar=02
IF "%inchar%"=="C" set outchar=03
IF "%inchar%"=="D" set outchar=04
IF "%inchar%"=="E" set outchar=05
IF "%inchar%"=="F" set outchar=06
IF "%inchar%"=="G" set outchar=07
IF "%inchar%"=="H" set outchar=08
IF "%inchar%"=="I" set outchar=09
IF "%inchar%"=="J" set outchar=10
IF "%inchar%"=="K" set outchar=11
IF "%inchar%"=="L" set outchar=12
IF "%inchar%"=="M" set outchar=13
IF "%inchar%"=="N" set outchar=14
IF "%inchar%"=="O" set outchar=15
IF "%inchar%"=="P" set outchar=16
IF "%inchar%"=="Q" set outchar=17
IF "%inchar%"=="R" set outchar=18
IF "%inchar%"=="S" set outchar=19
IF "%inchar%"=="T" set outchar=20
IF "%inchar%"=="U" set outchar=21
IF "%inchar%"=="V" set outchar=22
IF "%inchar%"=="W" set outchar=23
IF "%inchar%"=="X" set outchar=24
IF "%inchar%"=="Y" set outchar=25
IF "%inchar%"=="Z" set outchar=26
IF "%inchar%"==" " set outchar=27
set output=%output%%outchar%
set /a j=%j%+1
goto Loop1
:ExitLoop1
echo (1) Encode a message
echo Plain text input  %input%
echo Encoded output    %output%

Rem decode
set input=%output%
set output=
rem loop through the string
set j=0
:Loop2
call set inchar=%%input:~%j%,2%%
if "%inchar%"=="" goto ExitLoop2
IF "%inchar%"=="01" set outchar=A
IF "%inchar%"=="02" set outchar=B
IF "%inchar%"=="03" set outchar=C
IF "%inchar%"=="04" set outchar=D
IF "%inchar%"=="05" set outchar=E
IF "%inchar%"=="06" set outchar=F
IF "%inchar%"=="07" set outchar=G
IF "%inchar%"=="08" set outchar=H
IF "%inchar%"=="09" set outchar=I
IF "%inchar%"=="10" set outchar=J
IF "%inchar%"=="11" set outchar=K
IF "%inchar%"=="12" set outchar=L
IF "%inchar%"=="13" set outchar=M
IF "%inchar%"=="14" set outchar=N
IF "%inchar%"=="15" set outchar=O
IF "%inchar%"=="16" set outchar=P
IF "%inchar%"=="17" set outchar=Q
IF "%inchar%"=="18" set outchar=R
IF "%inchar%"=="19" set outchar=S
IF "%inchar%"=="20" set outchar=T
IF "%inchar%"=="21" set outchar=U
IF "%inchar%"=="22" set outchar=V
IF "%inchar%"=="23" set outchar=W
IF "%inchar%"=="24" set outchar=X
IF "%inchar%"=="25" set outchar=Y
IF "%inchar%"=="26" set outchar=Z
IF "%inchar%"=="27" set "outchar= "
set output=%output%%outchar%
set /a j=%j%+2
goto Loop2
:ExitLoop2
echo.
echo (2) Decode a message
echo Encoded input     %input%
echo Plain text output %output% 


Code: [Select]
(1) Encode a message
Plain text input  MARY HAD A LITTLE LAMB
Encoded output    13011825270801042701271209202012052712011302

(2) Decode a message
Encoded input     13011825270801042701271209202012052712011302
Plain text output MARY HAD A LITTLE LAMB