...

wea.my - page 5/29

numeric diamonds

14 January 2010programmingalgorithmfun stuff

today i've encountered a simple yet tricky programming problem which is print a numeric diamond like this.

                  1
               7    2
            13    8    3
         19    14    9    4
      25    20    15    10    5
   31    26    21    16    11    6
      32    27    22    17    12
         33    28    23    18
            34    29    24
               35    30
                  36

at first glance it's look easy but it's a little bit tricky since the number order is from up to bottom and right to left. it's very different with this kind of numeric diamond

                  1
               2    3
             4    5    6
          7    8    9     10
      11   12    13    14    15
   16    17    18    19    20   21
      22    23    24    25    26
         27    28    29    30
            31    32    33
               34    35
                  36

so, after analyzing the number sequence i notice that the number order actually work like this diagram

numerical diamon diagram

after knowing how the number being ordered, now we can write our program. here's my solution. normally we use 2 times of loop when generating pyramid/diamond which is top and bottom triangle, but in this case we don't need to do that. see how easy to program something when you understand the algorithm.

#include <stdio.h>
#include <math.h>
void diamond(int size) {
 int i,j,k,x;
 x = sqrt(size);
 int left,right=-1*x+1;
 for (i = 1; i < x*2 ;i++)
  {
   left = (i>x)?x*2-i:i;
   for (k=0;k<=x-left;k++) printf("   ");
   right = (i>x)?right+1:right+x;
   printf("%d",right);
   for (j = 1;j < left;j++) {
   printf("    %d",right-(x-1)*j);
   }
   printf("\n");
  }
}
int main() {
//input must be n^2
diamond(9);
diamond(36);
diamond(100);
diamond(121);
return 0;
}

preview numeric diamonds output

if you have any other suggestion in term of better algorithm to solve this, feel free to drop your comment

dahulu

29 November 2009writingsjangan samakan

dulu, nasi lemak 30sen je

dulu, air sirap 20sen beb

dulu, gua dapat 50sen rasa macam dapat rm 2

dulu, tambang bas kok lanas ke kota bharu baru 70sen

dulu, tak sampai rm 5 pun takat nak kasi minyak full tank

tapi.. itu dahulu punya cerita la kan??

PacketiX.NET vpn client installation on linux

8 August 2009tips & trickssimple packetix free vpn guide

recently i've been using packetix.net vpn and the speed is quite good, unfortunately there's not many guide on how to use the client on linux, so i'm writing one. this gonna be very long..so bear with me till the end ..huhu

to make things easier, lets transform into root :D

sudo su && cd ~

now, make a folder name vpn and download the vpnclient file from their web http://packetix.net/en/secure/install/

mkdir vpn && cd vpn
wget -c http://packetix.net/en/special/files/vpn2\_5350\_en/vpnclient-5350a-rtm-en-linux-x86.tar.gz

now to compile this files, you need zlib, openssl, readline and ncurses.

apt-get install zlib1g-dev libreadline5-dev

once finish,extract the file and continue with compile

tar -zxvf vpnclient-5350a-rtm-en-linux-x86.tar.gz && cd vpnclient* && make

connecting/tunneling to packettix.net

./vpnclient start
./vpncmd

inside vpncmd, choose number 2

[2] Management of VPN Clinet and input localhost as the destination host

u will see something like this,

Input destination: localhost

Connected to VPN Client "localhost".

VPN Client>

now configuring your connection.

root@bur8:~/vpnclient> ./vpncmd

vpncmd command -- PacketiX VPN Command Line Management Utility

PacketiX VPN Command Line Management Utility (vpncmd command)

Version 2.20 Build 5350   (English)

Compiled Oct  9 2007 01:27:58 by yagi at ILC308

Copyright (C) 2004-2007 SoftEther Corporation. All Rights Reserved.

By using vpncmd program, the following can be achieved.

1.  Management of VPN Server or VPN Bridge

2.  Management of VPN Clinet

3.  Use of VPN Tools (certificate creation and communication speed measurement)

Select 1, 2 or 3: 2

Specify the host name or IP address of the computer that the destination VPN Client is operating on.

If nothing is input and Enter is pressed, connection will be made to localhost (this computer).

Input destination: localhost

Connected to VPN Client "localhost".

VPN Client>niccreate

NicCreate command -- Create New Virtual Network Adapter

Virtual Network Adapter Name: ****

The command terminated normally.

now lets configure our account and connection

VPN Client>niclist

NicList command -- Get List of Virtual Network Adapters

Item                        |Value

----------------------------+----------------------------;

Virtual Network Adapter Name|****

Status                      |Enabled

MAC Address                 |00AC9D035CF6

Version                     |Version 2.20 Build 5350   (English)

The command terminated normally.

VPN Client>accountcreate

AccountCreate command -- Create New VPN Connection Setting

Name of VPN Connection Setting: VPN

Destination VPN Server Host Name and Port Number: public.softether.com:443

Destination Virtual HUB Name: PUBLIC

Connecting User Name: PUBLIC

Used Virtual Network Adapter Name: ****

The command terminated normally.

VPN Client>accountlist

AccountList command -- Get List of VPN Connection Settings

Item                        |Value

----------------------------+----------------------------;

VPN Connection Setting Name |VPN

Status                      |Offline

VPN Server Address          |public.softether.com (Direct TCP/IP Connection)

Virtual Network Adapter Name|****

The command terminated normally.

VPN Client>accountconnect

AccountConnect command -- Start Connection to VPN Server using VPN Connection Setting

Name of VPN Connection Setting: VPN

The command terminated normally.

wait for awhile and list the account again

VPN Client>accountlist

AccountList command -- Get List of VPN Connection Settings

Item                        |Value

----------------------------+----------------------------;

VPN Connection Setting Name |VPN

Status                      |Connected

VPN Server Address          |public.softether.com (Direct TCP/IP Connection)

Virtual Network Adapter Name|****

The command terminated normally.

set this as default connection everytime vpnclient started

VPN Client>AccountStartupSet

AccountStartupSet command -- Set VPN Connection Setting as Startup Connection

Name of VPN Connection Setting: VPN

VPN Client>quit

now check for connection, note the interface postfix _0 at the end of vpn

root@bur8:~/vpnclient> ifconfig vpn_0

vpn_0 Link encap:Ethernet  HWaddr 00:ac:9d:03:5c:f6

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:1603 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:500

RX bytes:463867 (463.8 KB)  TX bytes:0 (0.0 B)

get dhcp from vpn

root@bur8:~/vpnclient> dhclient vpn_0

Listening on LPF/vpn_0/00:ac:9d:03:5c:f6

Sending on   LPF/vpn_0/00:ac:9d:03:5c:f6

Sending on   Socket/fallback

DHCPREQUEST of 10.3.83.250 on vpn_0 to 255.255.255.255 port 67

DHCPACK of 10.3.83.250 from 10.0.0.1

bound to 10.3.83.250 -- renewal in 437751335 seconds.

root@bur8:~/vpnclient> ifconfig vpn_0

vpn_0     Link encap:Ethernet  HWaddr 00:ac:9d:03:5c:f6

inet addr:10.3.83.250 Bcast:10.255.255.255 Mask:255.0.0.0

now you can start routing you connection to vpn...
beware noob routing technique ahead, but it should get the job done and should redirect all your traffic to vpn

route connection to packet vpn thru main gw

route add -net 130.158.6.0/24 gw 192.168.182.1

dhclient vpn_0

to route all connection to vpn gw

ip route del default via 192.168.182.1

ip route add default via 10.0.0.1 dev vpn_0

route only specific destion thru vpn gw

ip route del default via 10.0.0.1 dev vpn_0

route add -net 216.152.78.0/24 gw 10.0.0.1

this will route all connection to 216.152.78.0/24 to vpn_0 gw where  192.168.182.1 is your main gateway

for more about how to do advance routing in linux please refer to http://lartc.org/howto/index.html p/s: to back to your current connection.. stop the service and reroute back to your original gateway.

./vpnclient stop
route del default
route add default dev ppp0

where ppp0 is my celcom 3g modem interface

for those who didn't know what the hell packetix.net is,

PacketiX.NET is an academic, non-profit online environment for PacketiX VPN, the VPN technology developed by SoftEther Corporation.

more info please visit their website at http://packetix.net/en/

update: you need to enable ipforwarding or else you won't be able to connect to internet.

$ echo 1 > /proc/sys/net/ipv4/ip_forward

or simply edit your /etc/sysctl.conf file

hope it this guide will give benefit to everyone.. thank you ;)

trust no one

18 July 2009writingsanti security

Blend in.

Get trusted.

Trust no one.

Own everyone.

Disclose nothing.

Destroy everything.

Take back the scene.

Never sell out, never surrender.

Get in as anonymous, Leave with no trace.

~anti-sec

obfuscated malaysia map in c

13 July 2009programmingobfuscated programmingreverse engineering

gua ada satu benda menarik yang gua saja nak show off kat korang ekeke... nah, cuba la compile!!

#include <stdio.h>
int x,b=10;p(_){return(_>=34&&printf("%c"\
,++b==0x5A?b=b>>4<<1:041U^x&1)&&p(_-1));}
main(){int s="/*, n@vat3ch.^_^v *'b \
*'B#? *+>#? *,;%? *-:%? *-:$@ *-:$@ \
+-9$@ ,14&> -03)< -03*; ,12,: ,0(#(/\
9 --"/* handcoded by */"(''/8 ,/$+$1\
8 ,"/*azwan ali 2009*/"0#>CNDS?QAS@T\
>U=V<W=V<W<V;X:X9Y8Z9X;W<W;X9X;V=U=T\
AQBODMFLFLGKFMFLFJGJIKIGLHLHNENENEOC\
PDPCQ@U<X<X:Y8]5_2a1e+i),"[x+++18];s\
>32?p(s):x+1;return s>0?main():0;}

kalau korang masih ingat entry gua tentang seni pengeliruan atucara, hah ni dia versi yang lebih sempurna. apa kebaikan untuk korang?? takde.. seperti gua kata..saje nak menunjuk nunjuk hahaha!! ni versi lebih mampat dan padat tapi sebenarnya gunakan helper function

ciao!~