No, not because it is a new year.
A single chat changes your mood totally. Can’t tell anything more. And yeah…
CONGRATS. :) :) :)
I’m so so so so glad now. :-)
Posted by sp2hari
No, not because it is a new year.
A single chat changes your mood totally. Can’t tell anything more. And yeah…
CONGRATS. :) :) :)
I’m so so so so glad now. :-)
Posted by sp2hari
Been a long time since I posted any photolog in my blog. So here comes one. ;)
Click on the picture to view the picture in original size. :-)
Posted by sp2hari
Hi all,
This is my third post on the series of articles I’m writing on C code obfuscation. You can check all the posts I’ve written about obfuscation here.
The task for this post is quite simple. Given two numbers a and b (b>a>3) as input, print all prime numbers in between a and b (including a and b).
Let me first paste final code here. I’ll be happy if you feel that you can’t make head or tail of it. ;-)
#define _$_ "%d",&I);I;})
Y,A,Z,H,I;main() {
#define __$__ ({ int I; scanf(_$_
#define FOR(_,__,___)for(_=__;_<___;+_++)
Y=__$__,A=__$__;FOR(Z,
#define T ({sscanf("2 is the only even prime number. Do you know that?", _$_
Y,A+T/2)FOR(H,T,Z)if(!(Z%H)||(H==Z-1&&printf("%d\n",Z)))break;}
Like the last post, we will start with a simple, clean code. The following code solves the given task.
#include <stdio.h>
int main() {
int a, b, i, j;
scanf("%d", &a);
scanf("%d", &b);
for (i=a ; i<=b; i++) {
for (j=2; j<i; j++) {
if (i%j == 0) {
break;
}
else if (j==i-1) {
printf("%d\n", j+1);
}
}
}
return 0;
}
First thing we see here is that we have two for loops. We can replace the for loops using preprocessor statement. This is a common time saving technique if you participate in online programming contests like Topcoder or SPOJ. Also let us remove {} for single line statements.
#define FOR(i,a,b) for(i=a;i<b;+i++)
int main() {
int a, b, i, j;
scanf("%d", &a);
scanf("%d", &b);
FOR(i, a, b+1)
FOR(j, 2, i) {
if (i%j == 0) break;
else if (j==i-1 && printf("%d\n", i));
}
return 0;
}
Next step, we remove the return 0 statement and modify int main as simply main. Also we change all the integer variables we use in our code as global variables so that we need not defing their data type. Another modification that can be done here is to replace 2 by TWO and have a preprocessor statement to define TWO. This preprocessor statement is placed in between the for statement, just before we need the value 2.
Next modification is to is to remove the if else and have it in a single if statement. The idea used here is short-circuiting, so that there is no need for the else statement.
a,b,i,j,t;main(){
scanf("%d",&a);
scanf("%d",&b);
#define FOR(i,a,b) for(i=a;i<b;+i++)
FOR(i,a,b+1) FOR(j,
#define TWO 2
TWO,i)
if (i%j==0||(j==i-1&&printf("%d\n",i)))break;}
Next we see that #define TWO 2 is straight forward. So modify that as shown below. The catch here is that you can have any statement which starts with 2 and has any non digit character following the 2. That way sscanf will just store the value of 2 to TWO.
a,b,i,j,t; main(){
scanf("%d",&a);
scanf("%d",&b);
#define FOR(i,a,b) for(i=a;i<b;+i++)
FOR(i,
#define TWO ({sscanf("2 is the only even prime number. Do you know that?", "%d",&t);t;})
a,b+1) FOR(j,TWO,i) if(!(i%j)||(j==i-1&&printf("%d\n",i)))break;}
Finally, we see that we have 2 scanfs and 1 sscanf. The tail part of these functions are similar. Like
scanf(”%d”,&a);
scanf(”%d”,&b);
sscanf(”2 is the only even prime number. Do you know that?”, “%d”,&t);
In the above three statements, we see that “%d”, &variable); is common. So add one preprocessor statement to replace that as shown below. Rename the variables to single characters. I have used upper case here. ;-).
#define _$_ "%d",&I);I;})
Y,A,Z,H,I;main() {
#define __$__ ({ int I; scanf(_$_
#define FOR(_,__,___)for(_=__;_<___;+_++)
Y=__$__,A=__$__;FOR(Z,
#define T ({sscanf("2 is the only even prime number. Do you know that?", _$_
Y,A+T/2)FOR(H,T,Z)if(!(Z%H)||(H==Z-1&&printf("%d\n",Z)))break;}
You can download all the C files as a single zip file here.
Posted by sp2hari
Writing this post just to remember this night. Obviously a personal post, so no one will understand anything. Please stop reading after this. :)
For the first time in my life, I want to remember this night forever. I think I’ll do. I feel like I can sleep after this. It is 4AM. And I have that smile in my face, which I lost long long back.
Working for Interviewstreet now. Whenever I think of doing something, some coding work which really means to me, only Interviewstreet comes to my mind. Not even topcoder. Guess this is something I want to do. And I will do it. :-)
And I know why. Not because I want to finish it for viv and taggy and walrus. Just that I like coding in php and I get some satisfaction out of it. Yes, now I understand. It can be called selfish :-)
Here I come IS :-) …
Posted by sp2hari
Top ten things that pops out of my mind when I think about Friends.
1. duck and the chick
2. ugly naked guy
3. double pizza
4. paleontologist
5. foozball
6. Days of our Lives
7. Mac and C.H.E.E.S.E
8. How you doin.
9. Turkey in thanksgiving dinner
10. ‘Shall we go get some coffee?’ ‘Sure. Where?’