1987 International C Language Chaos Code competition winning line of code

Source: Internet
Author: User


MACB ()? Lpcbyu (&gbcq/_\021%ocq\012\0_=w (GBCQ)/_dak._=}_ugb_[0q60) s+


This is Coolshell Bo master before doing a very interesting online puzzle, imitate some front-end clearance of the game, do a few and programmer-related puzzles, a clearance game, this thing test the second question. And for the top 10 customs clearance of the advanced programming of the UNIX Environment (third edition)(thanks to the @ Publishing Circle Guo Zhimin sponsorship) or a mug (thanks to the @linux command line Select Network Sponsorship)) These puzzles are interesting and have some difficulty. Because of the limited level, I did not customs clearance, but I feel that these things are really interesting is worth doing, or can learn a lot of things.

This is the original game Test link http://fun.coolshell.cn/. This test I think it is quite interesting, just a go in to see the page will be ignorant of the beginning AH. Limited to personal ability and narrow knowledge, at the author's prompt to understand that this is a Brainfuck programming language related fields. After searching the web for information, the answer is "welcome.html". Concrete solution to the implementation of the process see brainfuck--make your mind messy programming language




When I see this keyboard, I find it is not the same as our usual keyboard layout. So I thought, the problem is to replace the characters of the keyboard with the characters in the corresponding position on our computer keyboard. So I did it quickly and the result is as follows

Main () {printf (&unix["\021%six\012\0"], (Unix) ["has"]+ "fun" -0x60);}
see here a little dumbfounded, this is the legendary C language confusion code. This is the 4th International obfuscated C Code Contest (1987), by the T-Bell Labswritten by David Korn. Previous International C Language Chaos Code Competition works Appreciation . Paste the code into the IDE and compile the hint "Unix was is notdeclared in this scope ". Well, there is no statement, that decisively define a value with a # define macro
#define UNIX 1
the very fact that the results of Unix run out. The result is really not the intention, Chaos code is a word "chaos" of the have.

By looking at the relevant information, I finally figured out what it really was.


First review a little knowledge:

Character-type constants and ASCII character sets. Each character occupies a byte in memory and is used to store its ASCII value. Therefore, C-language characters have numeric characteristics that can participate in operations like integers.

Escape characters: Some characters, such as carriage return (' \ R '), control symbols such as line breaks (' \ n '), they cannot be displayed on the screen, cannot be entered from the keyboard, and can only be represented by escape characters. The escape character consists of a backslash plus a character or number, which converts the character or number after the backslash to something else.

\DDD the        characters represented by the 1-3-bit octal character, such as \102= ' B '    \xhh        1-2-bit hexadecimal characters, such as \x41= ' A '
printf ("%x", ' \ n ');p rintf ("%x", ' \ R ');//newline character, the ASCII value of the carriage return is a,d, which is the decimal 10,13
Finally, it's important.
int a[3]={1,2,3};p rintf ("%d%d\n", a[2], 2[a]);//Yes, your eyes are not mistaken. He's actually outputting the 3</span>.
The above read from the "C and the pointer",arry[2] and 2[arry] is equivalent, this strange technique is feasible, originates from the C language implementation of the following table method. Although there is no difference between the two, there is no doubt that this affects the readability of the program. Do not recommend large-scale promotion caused unnecessary kill!

See here, we can convert the above translation of the code once again, as follows:

Main () {printf (&unix["\021%six\n"], (Unix) ["has"]+ "fun" -0x60);} The \021=17,ascii character is DC1. It is a character; \012=10=0xa= ' \ n ', \0= ' 0 ', then main () {printf (& "Dc1%six\n\0" [Unix], "has" [unix]+ "Fun" -0x60);} Make Unix=1, then main () {printf (& "dc1%six\n" [1], "has" [1]+ "Fun" -0x60);} & "dc1%six\n", go to the address at subscript 1 in the string, then main () {printf ("%six\n", ' A ' -0x60+ "fun");} The ASCII of a is only 97=0x61, then main () {printf ("%six\n", "fun" + 1);} The above equals main () {printf ("%six\n", "un");}
writing here, the whole process should be clearly understood. OK, then look at the next question.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.