Wednesday, September 12, 2007

Awake from the darkness..

Hi , It has been a long time haa? Since i wrote my last post to this blog, i lost my mind:) There are many things changed, i was graduated in July from both of my major.. Now, it is happening again, i decide to write something in order to be alive.. You can not live in fair my man :p So take a look at that sezar crypto algorithm: ( it is not just complete but very near :)


#include<stdio.h>


void encode( char* str ){
asm (
"movl %0,%%ebx\n\t" //store the string address in ebx register
"eback:\n\t" //loop scans the string character
"movb (%%ebx), %%al\n\t" //put next character to eax register
"cmp $0, %%al\n\t" //look at string termination, NULL character
"je efinish\n\t" //jump to finish point if null is found
"addb $3, %%al\n\t" //forward 3 characters front..
"movb %%al, (%%ebx)\n\t" //put encrypted character to its place
"addl $1, %%ebx\n\t" //go to next character
"jmp eback\n\t"
"efinish:\n\t"
:
:"g"(str)
:"%ebx" //ebx is marked as changed register
);
}




void decode( char* str ){
asm (
"movl %0,%%ebx\n\t" //store the string address in ebx register
"dback:\n\t" //loop scans the string character
"movb (%%ebx), %%al\n\t" //put next character to eax register
"cmp $0, %%al\n\t" //look at string termination, NULL character
"je dfinish\n\t" //jump to finish point if null is found
"subb $3, %%al\n\t" //forward 3 characters back..
"movb %%al, (%%ebx)\n\t" //put encrypted character to its place
"addl $1, %%ebx\n\t" //go to next character
"jmp dback\n\t"
"dfinish:\n\t"
:
:"g"(str)
:"%ebx" //ebx is marked as changed register
);
}

int main(){

char message[] = "Hi this is emreknlk";

/*original message*/
printf("original \tmessage: %s\n",message);

/* encode the message:*/
encode( message );

printf("encoded \tmessage: %s\n",message);

/*decode the message*/
decode( message );
printf("decoded \tmessage: %s\n",message);

return 0;
}

output:
D:\My Documents\itu\cc>sezar_asm.exe
original message: Hi this is emreknlk
encoded message: Kl#wklv#lv#hpuhnqon
decoded message: Hi this is emreknlk

yea, i want to begin with C, asm and pointers :) It is just a begining it is not the end.. C U Soon guys..