![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-12 05:18 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Can a batch file do Morse code conversion? |
| Printable Version 1,309 / 9 |
| Floor1 DOS2BAT | Posted 2010-08-22 21:27 |
| 新手上路 Posts 10 Credits 11 | |
|
Can a batch file do Morse code conversion? The user enters English letters, then they are converted into Morse code and saved into a text file. I thought of using set, but I don't know if that will work. Right now I still have no idea at all, so I'm asking everyone for help!
Conversion format: For example: I LOVE YOU Convert to: .. .-.. --- ...- . -.-- --- ..- Also attaching the conversion codes for Morse code and English: A .- I .. Q --.- Y -.-- 7 --… B -… J .--- R .-. Z --.. 8 ---.. C -.-. K -.- S … 1 .---- 9 ----. D -.. L .-.. T - 2 ..--- 0 ----- E . M -- U ..- 3 …-- . .-.-.- F ..-. N -. V …- 4 ….- ? ..--.. G --. O --- W .-- 5 ….. , --..-- H …. P .--. X -..- 6 -…. |
|
| Floor2 freeants001 | Posted 2010-08-22 23:39 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
|
for + set can easily do the encoding, I just don't know how to decode it. I can't see any pattern in it.
|
|
| Floor3 freeants001 | Posted 2010-08-22 23:52 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
|
I got dizzy, but I see it now. So it turns out to be a one-to-one correspondence.
Encoding: fix: After encoding, separate each word with spaces. [ Last edited by freeants001 on 2010-8-23 at 00:00 ] |
|
| Floor4 DOS2BAT | Posted 2010-08-23 12:26 |
| 新手上路 Posts 10 Credits 11 | |
|
What you posted won't work... What I want is conversion after user input, and your code also seems to have some problems, the window flashes and disappears. No way to make it work!
|
|
| Floor5 DOS2BAT | Posted 2010-08-23 12:27 |
| 新手上路 Posts 10 Credits 11 | |
|
It really is a correspondence relationship, one letter corresponds to one character.
|
|
| Floor6 freeants001 | Posted 2010-08-23 14:09 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
Originally posted by DOS2BAT at 2010-8-23 12:26: There is no problem with the code in post #3. If you want conversion after user input, you can try the following: [ Last edited by freeants001 on 2010-8-23 at 14:27 ] |
|
| Floor7 DOS2BAT | Posted 2010-08-23 20:31 |
| 新手上路 Posts 10 Credits 11 | |
|
Your conversion isn't standardized~ after conversion, the ciphertext can't be turned back into the original text! Maybe it's the spaces or some other nonstandard part, hope it can be fixed.
This is an online conversion website. If its conversion can be used, that would also work, but then people would need internet access to use it. Still don't want that. http://blog.gxceo.com/gj/morse.html |
|
| Floor8 WANKOILZ | Posted 2010-08-23 20:46 |
| 初级用户 Posts 89 Credits 198 From 重庆 | |
|
Batch Home already had it long ago: http://bbs.bathome.net/thread-6467-1-2.html
|
|
| Floor9 doshsyy | Posted 2010-08-24 09:48 |
| 新手上路 Posts 15 Credits 19 | |
|
The code in post #6 is completely correct, it's the replacement table you gave that's wrong! You wrote "-" as "—", and "..." as "…", those are not the same! So I changed it a bit:
@echo off&setlocal enabledelayedexpansion for /f "tokens=1,2" %%I in ('more +12 "%~f0"') do set #%%I=%%J :begin set newline= set/p line=Please input a string: for /l %%x in (0,1,1000) do if "!line:~%%x,1!" neq "" call:sub !line:~%%x,1! echo.string: !line!&echo.enCode: !newline!&echo.!newline!>>encode$$$.txt goto:begin :sub if "%1" equ "" (set "newline=%newline% "&goto:eof) set "newline=%newline%!#%1! " goto:eof A .- I .. Q --.- Y -.-- 7 --... B -... J .--- R .-. Z --.. 8 ---.. C -.-. K -.- S ... 1 .---- 9 ----. D -.. L .-.. T - 2 ..--- 0 ---- E . M -- U ..- 3 ...-- . .-.-.- F ..-. N -. V ...- 4 ....- ? ..--.. G --. O --- W .-- 5 ..... , --..-- H .... P .--. X -..- 6 -.... |
|
| Floor10 DOS2BAT | Posted 2010-08-27 21:35 |
| 新手上路 Posts 10 Credits 11 | |
|
OK, thanks everyone, the code is so complicated~ I can't understand it, I'm a newbie, thanks for taking care of me!
Right now I'm studying how to translate the ciphertext, hehe. That way conversion can be done without going online too. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |