Text to Binary Translator Problem

January 5, 2012 at 07:24:02
Specs: Windows 7 Home Premium, 3.192 GHz / 3959 MB
Hi all you smart folks out there....
I Have this problem with my Text to Binary translator.
SOURCE: @echo off
SetLocal EnableDelayedExpansion
title 8-bit Binary Encoder
set charamount=500
color 0b
SET no=0
:begin
echo.
echo ^|------------------------------------------^|
echo ^|Welcome to the Binary Encoder ^|
echo ^|What do you want to do. ^|
echo ^|------------------------------------------^|
echo ^| (1) Encode Text ^|
echo ^| (2) Decode Binary ^|
echo ^| (3) Exit ^|
echo ^|------------------------------------------^|
set /p "ans1=What do you want to do? >"
IF %ans1%==1 goto encode
IF %ans1%==2 goto decode
IF %ans1%==3 exit
cls
echo Your choice is invalid!
goto begin
:encode
cls
echo Please enter the Letters sepperatly, enter "done" when you are done.
echo Special characters not supported. Use "-" for space. %charamount% Characters Left.
echo So far you have: !char1!!char2!!char3!!char4!!char5!!char6!!char7!!char8!!char9!!char10!!char11!!char12!!char13!!char14!!char15!!char16!!char17!!char18!!char19!!char20!!char21!!char22!!char23!!char24!!char25!!char26!!char27!!char28!!char29!!char30!!char31!!char32!!char33!!char34!!char35!!char36!!char37!!char38!!char39!!char40!!char41!!char42!!char43!!char44!!char45!!char46!!char47!!char48!!char49!!char50!!char51!!char52!!char53!!char54!!char55!!char56!!char57!!char58!!char59!!char60!!char61!!char62!!char63!!char64!!char65!!char66!!char67!!char68!!char69!!char70!!char71!!char72!!char73!!char74!!char75!!char76!!char77!!char78!!char79!!char80!!char81!!char82!!char83!!char84!!char85!!char86!!char87!!char88!!char89!!char90!!char91!!char92!!char93!!char94!!char95!!char96!!char97!!char98!!char99!!char100!!char101!!char102!!char103!!char104!!char105!!char106!!char107!!char108!!char109!!char110!!char111!!char112!!char113!!char114!!char115!!char116!!char117!!char118!!char119!!char120!!char121!!char122!!char123!!char124!!char125!!char126!!char127!!char128!!char129!!char130!!char131!!char132!!char133!!char134!!char135!!char136!!char137!!char138!!char139!!char140!!char141!!char142!!char143!!char144!!char145!!char146!!char147!!char148!!char149!!char150!!char151!!char152!!char153!!char154!!char155!!char156!!char157!!char158!!char159!!char160!!char161!!char162!!char163!!char164!!char165!!char166!!char167!!char168!!char169!!char170!!char171!!char172!!char173!!char174!!char175!!char176!!char177!!char178!!char179!!char180!!char181!!char182!!char183!!char184!!char185!!char186!!char187!!char188!!char189!!char190!!char191!!char192!!char193!!char194!!char195!!char196!!char197!!char198!!char199!!char200!!char201!!char202!!char203!!char204!!char205!!char206!!char207!!char208!!char209!!char210!!char211!!char212!!char213!!char214!!char215!!char216!!char217!!char218!!char219!!char220!!char221!!char222!!char223!!char224!!char225!!char226!!char227!!char228!!char229!!char230!!char231!!char232!!char233!!char234!!char235!!char236!!char237!!char238!!char239!!char240!!char241!!char242!!char243!!char244!!char245!!char246!!char247!!char248!!char249!!char250!!char251!!char252!!char253!!char254!!char255!!char256!!char257!!char258!!char259!!char260!!char261!!char262!!char263!!char264!!char265!!char266!!char267!!char268!!char269!!char270!!char271!!char272!!char273!!char274!!char275!!char276!!char277!!char278!!char279!!char280!!char281!!char282!!char283!!char284!!char285!!char286!!char287!!char288!!char289!!char290!!char291!!char292!!char293!!char294!!char295!!char296!!char297!!char298!!char299!!char300!!char301!!char302!!char303!!char304!!char305!!char306!!char307!!char308!!char309!!char310!!char311!!char312!!char313!!char314!!char315!!char316!!char317!!char318!!char319!!char320!!char321!!char322!!char323!!char324!!char325!!char326!!char327!!char328!!char329!!char330!!char331!!char332!!char333!!char334!!char335!!char336!!char337!!char338!!char339!!char340!!char341!!char342!!char343!!char344!!char345!!char346!!char347!!char348!!char349!!char350!!char351!!char352!!char353!!char354!!char355!!char356!!char357!!char358!!char359!!char360!!char361!!char362!!char363!!char372!!char373!!char374!!char375!!char376!!char377!!char378!!char379!!char380!!char381!!char382!!char383!!char384!!char385!!char386!!char387!!char388!!char389!!char390!!char391!!char392!!char393!!char394!!char395!!char396!!char397!!char398!!char399!!char400!!char401!!char402!!char403!!char404!!char405!!char406!!char407!!char408!!char409!!char410!!char411!!char412!!char413!!char414!!char415!!char416!!char417!!char418!!char419!!char420!!char421!!char422!!char423!!char424!!char425!!char426!!char427!!char428!!char429!!char430!!char431!!char432!!char433!!char434!!char435!!char436!!char437!!char438!!char439!!char440!!char441!!char442!!char443!!char444!!char445!!char446!!char447!!char448!!char449!!char450!!char451!!char452!!char453!!char454!!char455!!char456!!char457!!char458!!char459!!char460!!char461!!char462!!char463!!char464!!char465!!char466!!char467!!char468!!char469!!char470!!char471!!char472!!char473!!char474!!char475!!char476!!char477!!char478!!char479!!char480!!char481!!char482!!char483!!char484!!char485!!char486!!char487!!char488!!char489!!char490!!char491!!char492!!char493!!char494!!char495!!char496!!char497!!char498!!char499!!char500!
set /p "let1=>"
Set /a no=%no%+1
set /a charamount=%charamount%-1
:: Alpha
IF %let1%==A set var%no%= 01000001 & set char%no%=A
IF %let1%==a set var%no%= 01100001 & set char%no%=a
IF %let1%==B set var%no%= 01000010 & set char%no%=B
IF %let1%==b set var%no%= 01100010 & set char%no%=b
IF %let1%==C set var%no%= 01000011 & set char%no%=C
IF %let1%==c set var%no%= 01100011 & set char%no%=c
IF %let1%==D set var%no%= 01000100 & set char%no%=D
IF %let1%==d set var%no%= 01100100 & set char%no%=d
IF %let1%==E set var%no%= 01000101 & set char%no%=E
IF %let1%==e set var%no%= 01100101 & set char%no%=e
IF %let1%==F set var%no%= 01000110 & set char%no%=F
IF %let1%==f set var%no%= 01100110 & set char%no%=f
IF %let1%==G set var%no%= 01000111 & set char%no%=G
IF %let1%==g set var%no%= 01100111 & set char%no%=g
IF %let1%==H set var%no%= 01001000 & set char%no%=H
IF %let1%==h set var%no%= 01101000 & set char%no%=h
IF %let1%==I set var%no%= 01001001 & set char%no%=I
IF %let1%==i set var%no%= 01101001 & set char%no%=i
IF %let1%==J set var%no%= 01001010 & set char%no%=J
IF %let1%==j set var%no%= 01101010 & set char%no%=j
IF %let1%==K set var%no%= 01001011 & set char%no%=K
IF %let1%==k set var%no%= 01101011 & set char%no%=k
IF %let1%==L set var%no%= 01001100 & set char%no%=L
IF %let1%==l set var%no%= 01101100 & set char%no%=l
IF %let1%==M set var%no%= 01001101 & set char%no%=M
IF %let1%==m set var%no%= 01101101 & set char%no%=m
IF %let1%==N set var%no%= 01001110 & set char%no%=N
IF %let1%==n set var%no%= 01101110 & set char%no%=n
IF %let1%==O set var%no%= 01001111 & set char%no%=O
IF %let1%==o set var%no%= 01101111 & set char%no%=o
IF %let1%==P set var%no%= 01010000 & set char%no%=P
IF %let1%==p set var%no%= 01110000 & set char%no%=p
IF %let1%==Q set var%no%= 01010001 & set char%no%=Q
IF %let1%==q set var%no%= 01110001 & set char%no%=q
IF %let1%==R set var%no%= 01010010 & set char%no%=R
IF %let1%==r set var%no%= 01110010 & set char%no%=r
IF %let1%==S set var%no%= 01010011 & set char%no%=S
IF %let1%==s set var%no%= 01110011 & set char%no%=s
IF %let1%==T set var%no%= 01010100 & set char%no%=T
IF %let1%==t set var%no%= 01110100 & set char%no%=t
IF %let1%==U set var%no%= 01010101 & set char%no%=U
IF %let1%==u set var%no%= 01110101 & set char%no%=u
IF %let1%==V set var%no%= 01010110 & set char%no%=V
IF %let1%==v set var%no%= 01110110 & set char%no%=v
IF %let1%==W set var%no%= 01010111 & set char%no%=W
IF %let1%==w set var%no%= 01110111 & set char%no%=w
IF %let1%==X set var%no%= 01011000 & set char%no%=X
IF %let1%==x set var%no%= 01111000 & set char%no%=x
IF %let1%==Y set var%no%= 01011001 & set char%no%=Y
IF %let1%==y set var%no%= 01111001 & set char%no%=y
IF %let1%==Z set var%no%= 01011010 & set char%no%=Z
IF %let1%==z set var%no%= 01111010 & set char%no%=z
:: Numeric
IF %let1%==1 set var%no%= 00110001 & set char%no%=1
IF %let1%==2 set var%no%= 00110010 & set char%no%=2
IF %let1%==3 set var%no%= 00110011 & set char%no%=3
IF %let1%==4 set var%no%= 00110100 & set char%no%=4
IF %let1%==5 set var%no%= 00110101 & set char%no%=5
IF %let1%==6 set var%no%= 00110110 & set char%no%=6
IF %let1%==7 set var%no%= 00110111 & set char%no%=7
IF %let1%==8 set var%no%= 00111000 & set char%no%=8
IF %let1%==9 set var%no%= 00111001 & set char%no%=9
IF %let1%==0 set var%no%= 00110000 & set char%no%=0
IF %let1%==- set var%no%= 00100000 & set char%no%=
:: Check if done
IF %let1%==done goto exit2
IF %charamount%==0 goto charactersfinished
goto encode
:exit2
Echo Enter your filename
set /p "filename=>"
echo !var1!!var2!!var3!!var4!!var5!!var6!!var7!!var8!!var9!!var10!!var11!!var12!!var13!!var14!!var15!!var16!!var17!!var18!!var19!!var20!!var21!!var22!!var23!!var24!!var25!!var26!!var27!!var28!!var29!!var30!!var31!!var32!!var33!!var34!!var35!!var36!!var37!!var38!!var39!!var40!!var41!!var42!!var43!!var44!!var45!!var46!!var47!!var48!!var49!!var50!!var51!!var52!!var53!!var54!!var55!!var56!!var57!!var58!!var59!!var60!!var61!!var62!!var63!!var64!!var65!!var66!!var67!!var68!!var69!!var70!!var71!!var72!!var73!!var74!!var75!!var76!!var77!!var78!!var79!!var80!!var81!!var82!!var83!!var84!!var85!!var86!!var87!!var88!!var89!!var90!!var91!!var92!!var93!!var94!!var95!!var96!!var97!!var98!!var99!!var100!!var101!!var102!!var103!!var104!!var105!!var106!!var107!!var108!!var109!!var110!!var111!!var112!!var113!!var114!!var115!!var116!!var117!!var118!!var119!!var120!!var121!!var122!!var123!!var124!!var125!!var126!!var127!!var128!!var129!!var130!!var131!!var132!!var133!!var134!!var135!!var136!!var137!!var138!!var139!!var140!!var141!!var142!!var143!!var144!!var145!!var146!!var147!!var148!!var149!!var150!!var151!!var152!!var153!!var154!!var155!!var156!!var157!!var158!!var159!!var160!!var161!!var162!!var163!!var164!!var165!!var166!!var167!!var168!!var169!!var170!!var171!!var172!!var173!!var174!!var175!!var176!!var177!!var178!!var179!!var180!!var181!!var182!!var183!!var184!!var185!!var186!!var187!!var188!!var189!!var190!!var191!!var192!!var193!!var194!!var195!!var196!!var197!!var198!!var199!!var200!!var201!!var202!!var203!!var204!!var205!!var206!!var207!!var208!!var209!!var210!!var211!!var212!!var213!!var214!!var215!!var216!!var217!!var218!!var219!!var220!!var221!!var222!!var223!!var224!!var225!!var226!!var227!!var228!!var229!!var230!!var231!!var232!!var233!!var234!!var235!!var236!!var237!!var238!!var239!!var240!!var241!!var242!!var243!!var244!!var245!!var246!!var247!!var248!!var249!!var250!!var251!!var252!!var253!!var254!!var255!!var256!!var257!!var258!!var259!!var260!!var261!!var262!!var263!!var264!!var265!!var266!!var267!!var268!!var269!!var270!!var271!!var272!!var273!!var274!!var275!!var276!!var277!!var278!!var279!!var280!!var281!!var282!!var283!!var284!!var285!!var286!!var287!!var288!!var289!!var290!!var291!!var292!!var293!!var294!!var295!!var296!!var297!!var298!!var299!!var300!!var301!!var302!!var303!!var304!!var305!!var306!!var307!!var308!!var309!!var310!!var311!!var312!!var313!!var314!!var315!!var316!!var317!!var318!!var319!!var320!!var321!!var322!!var323!!var324!!var325!!var326!!var327!!var328!!var329!!var330!!var331!!var332!!var333!!var334!!var335!!var336!!var337!!var338!!var339!!var340!!var341!!var342!!var343!!var344!!var345!!var346!!var347!!var348!!var349!!var350!!var351!!var352!!var353!!var354!!var355!!var356!!var357!!var358!!var359!!var360!!var361!!var362!!var363!!var372!!var373!!var374!!var375!!var376!!var377!!var378!!var379!!var380!!var381!!var382!!var383!!var384!!var385!!var386!!var387!!var388!!var389!!var390!!var391!!var392!!var393!!var394!!var395!!var396!!var397!!var398!!var399!!var400!!var401!!var402!!var403!!var404!!var405!!var406!!var407!!var408!!var409!!var410!!var411!!var412!!var413!!var414!!var415!!var416!!var417!!var418!!var419!!var420!!var421!!var422!!var423!!var424!!var425!!var426!!var427!!var428!!var429!!var430!!var431!!var432!!var433!!var434!!var435!!var436!!var437!!var438!!var439!!var440!!var441!!var442!!var443!!var444!!var445!!var446!!var447!!var448!!var449!!var450!!var451!!var452!!var453!!var454!!var455!!var456!!var457!!var458!!var459!!var460!!var461!!var462!!var463!!var464!!var465!!var466!!var467!!var468!!var469!!var470!!var471!!var472!!var473!!var474!!var475!!var476!!var477!!var478!!var479!!var480!!var481!!var482!!var483!!var484!!var485!!var486!!var487!!var488!!var489!!var490!!var491!!var492!!var493!!var494!!var495!!var496!!var497!!var498!!var499!!var500! >> %filename%.txt
Echo Completed...
pause
cls
goto begin
:decode
cls
echo.The code must be on one line of the .txt document
echo.
echo File name(No extension)
set /p FileName=">
if not exist "%FileName%.txt" (
echo.No such file exists, %Filename%.txt
pause
goto decode
)
Set /p binary=<%Filename%.txt
Set binary=%binary%xxxxxxxx
Set AODL=0
SET conversion=
:decodeloop
CLS
Echo Working...
Set /a AODL=%AODL%+1
Set binary=%binary:~1%
SET TD=%binary:~0,8%
IF "%TD%" == "xxxxxxxx" Goto :EXITDECODELOOP
if "%TD%" == "01011010" set DL%AODL%=Z
if "%TD%" == "01011001" set DL%AODL%=Y
if "%TD%" == "01011000" set DL%AODL%=X
if "%TD%" == "01010111" set DL%AODL%=W
if "%TD%" == "01010110" set DL%AODL%=V
if "%TD%" == "01010101" set DL%AODL%=U
if "%TD%" == "01010100" set DL%AODL%=T
if "%TD%" == "01010011" set DL%AODL%=S
if "%TD%" == "01010010" set DL%AODL%=R
if "%TD%" == "01010001" set DL%AODL%=Q
if "%TD%" == "01010000" set DL%AODL%=P
if "%TD%" == "01001111" set DL%AODL%=O
if "%TD%" == "01001110" set DL%AODL%=N
if "%TD%" == "01001101" set DL%AODL%=M
if "%TD%" == "01001100" set DL%AODL%=L
if "%TD%" == "01001011" set DL%AODL%=K
if "%TD%" == "01001010" set DL%AODL%=J
if "%TD%" == "01001001" set DL%AODL%=I
if "%TD%" == "01001000" set DL%AODL%=H
if "%TD%" == "01000111" set DL%AODL%=G
if "%TD%" == "01000110" set DL%AODL%=F
if "%TD%" == "01000101" set DL%AODL%=E
if "%TD%" == "01000100" set DL%AODL%=D
if "%TD%" == "01000011" set DL%AODL%=C
if "%TD%" == "01000010" set DL%AODL%=B
if "%TD%" == "01000001" set DL%AODL%=A
if "%TD%" == "01111010" set DL%AODL%=z
if "%TD%" == "01111001" set DL%AODL%=y
if "%TD%" == "01111000" set DL%AODL%=x
if "%TD%" == "01110111" set DL%AODL%=w
if "%TD%" == "01110110" set DL%AODL%=v
if "%TD%" == "01110101" set DL%AODL%=u
if "%TD%" == "01110100" set DL%AODL%=t
if "%TD%" == "01110011" set DL%AODL%=s
if "%TD%" == "01110010" set DL%AODL%=r
if "%TD%" == "01110001" set DL%AODL%=q
if "%TD%" == "01110000" set DL%AODL%=p
if "%TD%" == "01101111" set DL%AODL%=o
if "%TD%" == "01101110" set DL%AODL%=n
if "%TD%" == "01101101" set DL%AODL%=m
if "%TD%" == "01101100" set DL%AODL%=l
if "%TD%" == "01101011" set DL%AODL%=k
if "%TD%" == "01101010" set DL%AODL%=j
if "%TD%" == "01101001" set DL%AODL%=i
if "%TD%" == "01101000" set DL%AODL%=h
if "%TD%" == "01100111" set DL%AODL%=g
if "%TD%" == "01100110" set DL%AODL%=f
if "%TD%" == "01100101" set DL%AODL%=e
if "%TD%" == "01100100" set DL%AODL%=d
if "%TD%" == "01100011" set DL%AODL%=c
if "%TD%" == "01100010" set DL%AODL%=b
if "%TD%" == "01100001" set DL%AODL%=a
if "%TD%" == "00110001" set DL%AODL%=1
if "%TD%" == "00110010" set DL%AODL%=2
if "%TD%" == "00110011" set DL%AODL%=3
if "%TD%" == "00110100" set DL%AODL%=4
if "%TD%" == "00110101" set DL%AODL%=5
if "%TD%" == "00110110" set DL%AODL%=6
if "%TD%" == "00110111" set DL%AODL%=7
if "%TD%" == "00111000" set DL%AODL%=8
if "%TD%" == "00111001" set DL%AODL%=9
if "%TD%" == "00110000" set DL%AODL%=0
if "%TD%" == "00101101" set DL%AODL%=-
if "%TD%" == "00100000" set DL%AODL%=
Set binary=%binary:~9%
SET conversion=%conversion%!DL%AODL%!
Goto :decodeloop
:EXITDECODELOOP
CLS
if Exist %FileName%-Decoded.txt del %FileName%-Decoded.txt
echo.%conversion% >%FileName%-Decoded.txt
echo.Translated!
ping -n 2 antonie-pc>nul
start %FileName%-Decoded.txt
echo.
pause >nul
goto begin

:charactersfinished
ping -n 1 antonie -pc>nul
cls
echo You have reached your character limit of 500!
echo The characters you entered will now be translated to binary...
pause
goto exit2

I want to be able to enter the entire sentence without pressing enter after each letter. Is it possible please help!
Also i want to be able to use <space> as a space instead of -.
Please reply asap!


See More: Text to Binary Translator Problem

Report •

#1
February 3, 2012 at 02:01:07
TRANSLATE.BAT "This is my sentence."

Determine the length of %1

Then parse it and assign each character to a different variable.

Then do your conversion

OR

Do the conversion one character at a time as you parse the input string. Then you only need just a few variables!

NOTE: It wouldn't take much more to read your sentence from a file to overcome the 500 character restriction and also convert <CR> and <LF> characters.

Please post your completed BAT file. I would very much like to have a copy. You should use the < pre - /pre > for all your code. It is very difficult to follow the way you have it.


Report •
Related Solutions


Ask Question