obfuscated hello world won't print hello world

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
NunoLava1998
Posts: 10
Joined: 01 Mar 2015 10:06

obfuscated hello world won't print hello world

#1 Post by NunoLava1998 » 27 Jan 2017 14:51

I'm trying to create a (very) obfuscated "Hello World!" in batch. However, this gives an error or displays nothing rather than displaying "Hello WorlD!"

Code: Select all

set/a_=5-4>nul&&set/a.=5-5>nul&&set "m=^%^t^m^p^:^~^5^,%_%%"&&set "q=%^t^m^p^:^~%.%,%_%%&&set "z=%^t^m^p^:^~6,%_%%&&set "v=%^c^o^m^s^p^e^c^:^~6,%_%%
%m%%q%Ho H%m%%z%%z%o Wor%z%%v%!

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: obfuscated hello world won't print hello world

#2 Post by ShadowThief » 27 Jan 2017 17:13

What's it supposed to look like un-obfuscated?

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: obfuscated hello world won't print hello world

#3 Post by thefeduke » 28 Jan 2017 00:48

NunoLava1998 wrote:this gives an error or displays nothing
Remarkable code. So which is it? An undisclosed error or no display? Or does it act differently based on some external influences?
Oh, where is my tongue-in-cheek icon?
John A.

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: obfuscated hello world won't print hello world

#4 Post by penpen » 28 Jan 2017 04:33

I guess "%m%%q%Ho H%m%%z%%z%o Wor%z%%v%!" should be "echo Hello World!", and
the first line then has to set up the used environment variables.

I see two issues here:
1. Perctentage expansion is only appended once before a line of batch code is interpreted see:
http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/4095133#4095133
You may use "call" to realize a second percentage expansion, but this has also other side effects (for example on the circumflex accent character):

Code: Select all

set "AB=de" && set "C=f" && set "ABF=xyz" && call set "D=%%AB%C%%%^"
echo D=%D%


2. Percentage expansion doesn't work the way you (NunoLava1998) assumes (like parentheses):
So "%AB%C%%" would not first expand %C% and then (assumed "%C%"== "f") %ABf%.

Instead percentage expansion first expands "%AB%" (to its value) and then "%%" (to "%").
For more information on percentage expansion see:
http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/7970912#7970912.
(Same linked page as above, but different post.)


penpen

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: obfuscated hello world won't print hello world

#5 Post by misol101 » 28 Jan 2017 10:54

I'm having trouble with mine as well. How do I write a blank space instead of an underscore?

Code: Select all

@setlocal enabledelayedexpansion&@for /f "delims=" %%H in (%~n0.bat) do @for %%W in (53,2,4,8,5,124,79,30,36,14,16) do @set _=%%H&set /p ="!_:~%%W,1!"<nul


Edit: Ahh, here is a better version:

Code: Select all

@setlocal enabledelayedexpansion&@(for /f "delims=" %%H in (%~n0.bat) do @for %%W in (54,2,4,8,5,9,80,30,37,14,16) do @set _=%%H&set O_=!O_!!_:~%%W,1!)&set /p="!O_!^!"<nul

Post Reply