Tutorials for Code Obfuscation in C [closed] - c

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am fascinated by the way people obfuscate their code (mostly, C) (examples here : http://ioccc.org/) and would like to learn the various techniques for the same. I have been told of a book, "Obfuscated C and other Mysteries", but I am not able to get that book.
Are there any tutorials or books that give hints on this topic?
Thank you.

The best you can do is read the comments of the author of the programs on IOCCC. They describe how they manage to obfuscate their code. Here are a few pointers:
Short and meaningless identifiers
Because a=aaa*aa; will always be more obfuscated than result = value * factor;
In order to have short identifiers, obfuscators tend to even #define many things.
Reversed array indexing
You just have to remember that var[3] and 3[var] are equivalent.
Digraphs and trigraphs
if(a< <:b+aa??))??<f();%>
should be less readable than:
if (a < (b+aa)) { f(); }
Look-alike characters
Sometimes, it's hard to tell appart l, 1 and I or o, 0 and O. For example, if you write 10l, I bet everyone will read 101 instead.
Coding style guidelines
Generally speaking, just try to find good coding guidelines and to try to violate them all. Those documents that you could find anywhere on the web could help you more than most things and would allow you not to buy anything.
Here are some links:
How to write unmaintainable code.

Morwenn's answer nicely covers obfuscation of syntax. But there is another level, and that is semantic obfuscation. Consider that the oft-mentioned Turing Machine has the same computational power as any other programming language (ignoring considerations of input and output). In fact all of the various models of computation have sibling models with equivalent power.
For example, a string char s[N] can be considered a mapping from indices to characters, so any string can be represented instead by a function which always delivers the appropriate character when called with a specified index char f(int i). Now read this. Crazy, right?

Related

Is "K&R C" still applicable [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I relearning C; it's been years and whilst familiar the nuances are lost in time.
I originally learned C from K&R. However, I now see many people levelling criticism at K&R.
A chief example is http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html#x61-27200055
Top reasons seem to be that it's code style is overly terse, practises aren't applicable in larger programs and lead to memory leaks or are subject to attack in shared network accessible systems.
Do people feel these criticisms are fair? Do they matter to somebody learning C? If so, could people recommend a "modern" C book, preferably available for Kindle?
As long as you're talking about the 2nd Edition, K&R is still very relevant.
In fact, I would say it's still the very best single book on C, both for learning, and for reference.
That said, you should also get a copy of Harbison & Steele's "C: A Reference Manual". It's the best current reference on C, and the Fifth Edition covers C99, which you should use if you can.
Also, once you've got a bit of C behind you, I'd strongly recommend reading "Expert C Programming", by Peter van der Linden.
It is still relevant and still very useful with regards to learning the language. Learning the language doesn't require you to implement new practices or styles that assist in code readability, etc.
For example, the idea of self documenting code is that you use verbose variable and function names to help explain the purpose of a function or a variable. K&R is clearly opposed to this. That doesn't mean you can't learn the C language from K&R, it just means that your style will need to be adjusted/updated based on whatever naming convention you decide upon in the future.
I cannot recommend "Expert C Programming" enough (as stated by gregj).

Why are C names shortened? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Why there is a function called strcat and not a function called stringConcatenation, or stringConcat or string_concat or something like that? Why there is a clrscr function and not clearScreen or clear_screen?
Does it have something to do with source code size in past days, where every byte was worth gold on overly-sized floppy disks? Or is this fueled by programmers' inherent laziness? Is it a convention?
This is partly historical.
In very old C compilers, there was no guarantee that more than the first 8 characters of an identifier name would be used to determine uniqueness. This meant that, originally, all identifiers had to be eight or fewer characters, so method names were all made short.
For details, see Identifiers in the C Book.
When C and its associated tools were first being developed, input devices were not nearly as easy to use as modern keyboards. I've never actually used an ASR-33 Teletype, but as I understand it typing stringConcatenation on such a beast was significantly more difficult than typing strcat (and without autocompletion, you would have had to type the entire name with no typos). It took a substantial amount of pressure to activate each key. Output was also painfully slow by modern standards.
This also explains why common Unix command names are so terse (mv and cp rather than move or rename and copy).
And it's probably also why old linkers only supported such short names. Programmers would generally create short names in the first place, so there was little point in using scarce memory to allow for longer ones.
In addition to all this, there's a case to be made that shorter names are just as good as longer ones. Names of library functions, whether strcat or stringConcatenation (or is it stringConcatenate? String_Concatenate? stringCatenation?) are essentially arbitrary. Ease of typing isn't as important as it once was, but it's still a consideration.

Compiler C to Brainfuck (for harassing a professor)? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
A professor of mine has said he'll accept homework assignments in any language we'd care to use. I'm on good enough terms that I'd like to mess with him a bit and submit a valid homework assignment using brainfuck, whitespace, or some equally "useful" language.
I have the C-sources for a few simple numerical analysis routines as well as the compiled output and the assembly files they generate.
Does anyone know of a decompiler (or a C->brainfuck translator) that could give me something akin to the "brainfuck source code"?
Just use APL or J.
Unlike BF, they were actually designed to serve a "useful" (and not a "useful as in BF" sense) purpose - and yet can easily make Perl code-golf entries look like novels. (The dedication and mental training to enjoy these languages is currently more than my skill/effort levels.)
If the goal is using a purely esoteric language, I have always enjoyed the look of Piet programs. It looks prettier and is actually able to solve common CS homework problems. Following the links will reveal "Piet assemblers" and other tools. Win.
Happy coding.
For what it's worth, I just wrote a very simple Brainfuck Assembler (inspired by this SO post actually), which assembles readable source code (not C, just something simple and nameless) to BrainFuck. The source-code and compilation/usage instructions can be found here: BrainFuck Assembler.
Edit: The project has recently been updated under a new name: BrainFix.
Edit 2: I redid the entire project. The new and improved version has quite a lot of features and is available on Github.
A quick Google search brings up the (a?) Brainfuck site, which links to an archive with "all things Brainfuck". I doubt there's a C->brainfuck translator anywhere, I wouldn't think anyone would invest that much time.

Programming challenges related to chemistry [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm looking for interesting programming puzzles, problems or challenges suitable for a class of chemistry majors learning C as their first programming language. Do you have any recommendations?
Project Euler is pretty good. They have some simple challenges that may be suitable.
These won't really do much to teach them C, though. Text books are much better for that.
Additionally, you could have them write a program to balance chemical reaction equations. That would be good for I/O and simple math.
Given a text file with a whole bunch of pressure/temperature/mole count as input, and using the ideal gas law equation, output the values of the volume for the gases and output the entire set of data (P,V,T and n) into a nicely formatted output file.
Should cover file i/o, basic function usage, and string formatting. Has the potential to cover arrays and stucts as well.
David, tasks that come to my mind would be:
calculation of the number/topology of isomers of hydrocarbons (cyclic and acyclic, saturated and unsturated)
numerical integration of optical spectra (absorption and fluorescence)
kinetical models
deconvolution of experimental data
modelling of thermodynamical cycles and their efficiencies
This seems a really vague question but assuming I'm a chemistry student that is learning C I would like to write programs that allows me to define molecules and compounds starting from simple elements.
I really don't know how to explain it, but maybe define your struct for a nitrogen atom, one for oxigen atom and have a way to bind it to produce water.. or maybe mixing to different substances too see what will come out programmatically..
You can try pex4fun. It allows you to learn algorithms in C# (which is close enough to C). pex4fun provides read-to-use classes and also engaging coding duels that turn learning into a game.

Is starting a one-word function with a capital letter a good practise? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
I have read in K&R that functions containing more than one word should be capitalized.Should one-word functions like prime(),be written as Prime()?Is this a good practise?
I have never seen this in K&R, are you sure it's not another book?
K&R always use lowercase, abbreviated function names without underscores for their function name throughout their book.
The only identifier-related advice I can find in their book is: Don't start with an underscore, variables are lowercase, symbolic constants all uppercase.
As others have said, the important part is consistency. The three common styles are:
lowercasetogether
CamelCase
lcase_underscore_sep
It's more important to be consistent.
Edit: What looks weird to you might look normal to someone else. Consistency is what's important; as long as all one-word functions are lower-case and all multiple-word functions are initially upper-cased, I think you're good to go. If you get to choose, choose what makes the most sense to you; if you're working with existing code, comply with what's already been done. If the existing code is inconsistent, fix it.
I believe consistency with your code base and with the libraries you are using is important as well as language custom is important when considering capitalization and camelCase vs under_score. I may be wrong but I haven't seen many c single word uppercase functions.
It's completely up to you. What matters is that you should be persistent.

Resources