Computer Hope
Microsoft => Microsoft DOS => Topic started 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?
-
yes it can be done, please explain presisly what you want. You want 1=A, 2=B, or something like that?
-
Yes exctaly
-
Yep
yes it can be done, please explain presisly what you want. You want 1=A, 2=B, or something like that?
-
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.
-
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
-
exctaly
Is that code too?
-
"486739" into letters like "Hello"
Why has 486739 got 6 figures and hello only 5 letters?
-
yes it can be done
Interested to see your demo code
-
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
-
Im a noob at this but heres what i got
@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
@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
-
are you turning letters into numbers or vica-verca
-
vice versa
-
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
-
idk how to use delimiters at all
-
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
-
@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
-
setlocal ENABLEDELAYEDEXPANSION
What does this line do?
also...
C:\Batch>test1.bat
enter number sequence:12
'c' is not recognized as an internal or external command,
operable program or batch file.
12
-
the set local was copied/pasted from my template forgot to remove it ;) anyways the fixed code is
@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
-
You could encode each letter of the alphabet into a two digit number
@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%
(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