Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: .bat that translates custom code to words  (Read 7649 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: .bat that translates custom code to words
« Reply #15 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


mat123



    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: .bat that translates custom code to words
« Reply #16 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



Salmon Trout

  • Guest
Re: .bat that translates custom code to words
« Reply #17 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

mat123



    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: .bat that translates custom code to words
« Reply #18 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



Salmon Trout

  • Guest
Re: .bat that translates custom code to words
« Reply #19 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