Wednesday, 5 April 2017

Quick Sort

WRITE A PROGRAM ON QUICK -SORT:-
#include <stdio.h>
#include <stdbool.h>
#define MAX 7

int intArray[MAX] = {4,6,3,2,1,9,7};

void printline(int count) {
   int i;

   for(i = 0;i <count-1;i++) {
      printf("=");
   }

   printf("=\n");
}

void display() {
   int i;
   printf("[");

   // navigate through all items
   for(i = 0;i<MAX;i++) {
      printf("%d ",intArray[i]);
   }

   printf("]\n");
}

void swap(int num1, int num2) {
   int temp = intArray[num1];
   intArray[num1] = intArray[num2];
   intArray[num2] = temp;
}

int partition(int left, int right, int pivot) {
   int leftPointer = left -1;
   int rightPointer = right;

   while(true) {
      while(intArray[++leftPointer] < pivot) {
         //do nothing
      }

      while(rightPointer > 0 && intArray[--rightPointer] > pivot) {
         //do nothing
      }

      if(leftPointer >= rightPointer) {
         break;
      } else {
         printf(" item swapped :%d,%d\n", intArray[leftPointer],intArray[rightPointer]);
         swap(leftPointer,rightPointer);
      }
   }

   printf(" pivot swapped :%d,%d\n", intArray[leftPointer],intArray[right]);
   swap(leftPointer,right);
   printf("Updated Array: ");
   display();
   return leftPointer;
}

void quickSort(int left, int right) {
   if(right-left <= 0) {
      return;
   } else {
      int pivot = intArray[right];
      int partitionPoint = partition(left, right, pivot);
      quickSort(left,partitionPoint-1);
      quickSort(partitionPoint+1,right);
   }      
}

main() {
   printf("Input Array: ");
   display();
   printline(50);
   quickSort(0,MAX-1);
   printf("Output Array: ");
   display();
   printline(50);
}


OUTPUT:-

Monday, 3 April 2017

VoCore: A Cheap And Coin-sized Linux Computer With Wi-Fi


Short Bytes: VoCore is an open hardware that runs OpenWRT Linux. This tiny computer comes with Wi-Fi, USB, 20+ GPIOs that will help you to make a smart home automation system or use it in other embedded projects. Read more to know about this device and grab one for yourself.
With each passing day, mini computer boards are getting more and more popular. Single board computers like Raspberry Pi, CHIP, OrangePi etc. are being endorsed by makers and DIY enthusiasts to create new innovations. However, if you are looking for an even smaller Linux computer, VoCore is the perfect device for you.
At fossBytes, we love open source technologies and so do the makers of VoCore. It’s an open source hardware that runs OpenWrt on top of Linux. With this mini Linux machine, you can fork your own Wi-Fi router, make smart home automation systems, invent a new device, build a motherboard and whatnot.

In simpler words, you can use it as a standalone device or use it as an embedded component of a larger system. It comes with included Dock that extends the USB and Ethernet ports to enhance its functionality.

Specifications of VoCore Linux computer:

This coin-sized computer is powered by 32MB SDRAM, and 8MB SPI Flash. It provides many interfaces like 10/100M Ethernet, USB, UART, I2C, I2S, PCM, JTAG and over 20 GPIOs.
  • OpenWRT Linux
  • Onboard Wi-Fi adapter
  • Integrates a 802.11n MAC, baseband, radio, FEM & 5-port 10/100Mbps Ethernet switch
  • Processor: Ralink/Mediatek 360 MHz RT5350 MIPS
Here’s the pin map of VoCore:
An open source software and hardware of VoCore means that you will also get its full hardware design and source code. This will allow you to control every part of this tiny Linux computer.



Did we miss something? Let us know in comments below.

what’s an error?

what’s an error?
An error is a type of mistake. We can say an error is a condition of having incorrect or false knowledge or an error is defined as an unexpected, invalid program state from which it is impossible to recover.
Error can also be defined as "a deviation from accuracy or correctness".
A "mistake" is an error caused by a fault: the fault being misjudgment, carelessness, or forgetfulness. An error message with filename, line number and a message describing the error is sent to the browser.
What are the different kinds of errors in PHP?
Basically there are four kinds of errors in PHP, which are as follows:
·         Parse Error (Syntax Error): The parse error occurs if there is a syntax mistake in the script; the output is Parse error. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:
1.       Unclosed quotes
2.      Missing or Extra parentheses
3.      Unclosed braces
4.      Missing semicolon
Example:
<?php
echo
 "Cat";
echo
 "Dog"
echo
 "Lion";
?>
Output:
In the above code we missed the semicolon in the second line. When that happens there will be a parse or syntax error which stops execution of the script.
·         Fatal Error: Fatal errors are caused when PHP understands what you've written, however what you're asking it to do can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.
Example:
<?php
function fun1()
{
echo "Vineet Saini";
}
fun2();
echo "Fatal Error !!";
?>
Output:
In the above code we defined a function fun1 but we call another function fun2 i.e. func2 is not defined. So a fatal error will be produced that stops the execution of the script.
·         Warning Error: Warning errors will not stop execution of the script. The main reason for warning error is to include a missing file or using the incorrect number of parameters in a function.
Example:
<?php 
echo "Warning Error!!";
include ("Welcome.php");
?>
Output:


In the above code we include a welcome.php file, however the welcome.php file does not exist in the directory. So there will be a warning error produced but that does not stop the execution of the script i.e. you will see a message Warning Error!!
·         Notice Error: Notice error is the same as a warning error i.e. in the notice error, execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

Example:
<?php
$a="Vineet kumar saini";
echo "Notice Error !!";
echo $b;
?>
Output:
In the above code we defined a variable which named $a. But we call another variable i.e. $b, which is not defined. So there will be a notice error produced but execution of the script does not stop, you will see a message Notice Error!! 

What are the different types of errors in PHP?
Basically there are 13 types of errors in PHP, which are as follows:
1.       E_ERROR: A fatal error that causes script termination
2.      E_WARNING: Run-time warning that does not cause script termination
3.      E_PARSE: Compile time parse error
4.      E_NOTICE: Run time notice caused due to error in code
5.       E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
6.      E_CORE_WARNING: Warnings that occur during PHP’s initial startup
7.       E_COMPILE_ERROR: Fatal compile-time errors indication problem with script
8.      E_USER_ERROR: User-generated error message
9.      E_USER_WARNING: User-generated warning message
10.   E_USER_NOTICE: User-generated notice message
11.    E_STRICT: Run-time notices
12.   E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
13.   E_ALL: Catches all errors and warnings



Send Email From Server Side

//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {
 
  //Email information
  $admin_email = "someone@example.com";
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
  $comment = $_REQUEST['comment'];
 
  //send email
  mail($admin_email, "$subject", $comment, "From:" . $email);
 
  //Email response
  echo "Thank you for contacting us!";
  }
 
  //if "email" variable is not filled out, display the form
  else  {
?>

 <form method="post">
  Email: <input name="email" type="text" /><br />
  Subject: <input name="subject" type="text" /><br />
  Message:<br />
  <textarea name="comment" rows="15" cols="40"></textarea><br />
  <input type="submit" value="Submit" />
  </form>
 
<?php
  }
?>


Inheritance

Inheritance is a mechanism of extending an existing class by inheriting a class we create a new class with all functionality of that existing class, and we can add new members to the new class.
When we inherit one class from another we say that inherited class is a subclass and the class who has inherit is called parent class.
-We declare a new class with additional keyword extends.
- PHP only supports multilevel inheritance.
Best example of multilevel inheritance in PHP

1.       class grandParent
2.       {
3.       //Body of grand parent class
4.       }
5.       class parent extends grandParent
6.       {
7.       //Body Of parent class
8.       }
9.       class child extends parent
10.    {
11.    //Body of child class
12.    }

Above example is so clear to understand, child class is extending parent class and parent class is extending grand parent.This was a very basic example to understand the concept of multilevel inheritance in php oops.

Constructor

Constructor
void __construct ([ mixed $args = "" [, $... ]] )
The constructor is the most useful of the two, especially because it allows you to send parameters along when creating a new object, which can then be used to initialize variables on the object
PHP  allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. If the child does not define a constructor then it may be inherited from the parent class just like a normal class method (if it was not declared as private).

class Animal
{
    public $name = "No-name animal";
   
    public function __construct()
    {
        echo "I'm alive!";       
    }
}

Output


$animal = new Animal(); 

Monday, 27 March 2017

Best CMD commands used in hacking

Top CMD or MS-DOS prompt commands which every hacker should know

If you have been following Techworm regularly, chances are you are a very versatile hacker in your own right and don’t need to know these commands. But many of our readers who are beginners and want to learn hacking always ask us for the top Dos Prompt (C:/ or CMD commands in Windows 10/7/8.1) they should know. So here goes.
CMD is a power tool which lets you do almost anything with your PC/laptop. There are common commands like CD.. and MD etc which you probably know so we wont get into that. Here are some really useful things a hacker can do with CMD commands.
First, open your Network Connection and right click and select Properties. Then Select TCP/IP and click Properties again. Now Click on Advanced and WINS tab. Select Default for NeBIOS.
This is just to make sure you have NetBIOS enabled. We will have some fun with NetBIOS on CMD. In case you don’t know how to get CMD by clicking the Windows icon at the left-hand bottom of your screen in all Windows versions and click on Start. Press run from the start, then type “cmd” without quotes.
Now here are the important commands which every wannabe hacker should know :

nslookup
net view
net use
net user
ping
tracert
arp
route
nbtstat
netstat
ipconfig

In case you don’t know some of them, then just type the command on CMD and hit enter. A little help will show up on your screen. Read it to understand what that particular command does.
Let’s start easy…
1) ping : This command will allow you to know if the host you pinging is alive, which means if it is up at the time of executing the “ping” command.
ping x.x.x.x (x is the IP address). You can try pinging 8.8.8.8 which belongs to Google
or
ping www.google.com (www.google.com is the website you want to ping, but you don’t know the IP)
2) nslookup : This command has many functionalities. One is for resolving DNS into IP. Lets say you know the website URL but you don’t know its IP but you want to find it out.
Eg. nslookup www.google.com (www.google.com is the website for which you want to find out the IP)
Now, another really nice function of nslookup is to find out IP of specific Mail Severs
nslookup (enter)
set type=mx (enter)
yahoo.com
This command will give you the mail server IP of yahoo.com. You can use whatever server you want and if it is listed on DNS, then you get the IP. Simple, isn’t it? You can send a spoofed email to your friends using the IP address of the mail server. You can check the tutorial here for sending spoofed email.
3) tracert : This command will give you the hops that a packet will travel to reach its final destination. This command is really helpful if you know the route a packet takes before it goes to the target box.
tracert x.x.x.x (x is the IP address)
or
tracert www.google.com (www.google.com is the website you don’t know the IP)
4) arp : This command will show you the arp table. You can find out if anyone has done arp poisoning in your LAN using this command.
arp -a
5) route : This command will show you the routing table, gateway, interface and metric.
Code:
route print
6) ipconfig : This command will show you a lot of useful things like your IP, Gateway, DNS in use, etc. This command will give all that info but for all networks you might have it.
Code:
ipconfig
or
Code:
ipconfig /all
Also, in case you have a dynamic IP and want to change it, then type…
Code:
ipconfig /release (this will release your IP)
ipconfig /renew (this will renew your iP)
7) netstat : This command will show you connection stats
Code:
netstat
or
Code:
netstat -a (this will show you all the listening ports and connection with DNS names)
netstat -n (this will show you all the open connection with IP addresses)
netstat -an (this will combined both of the above)
net view x.x.x.x or computername (will list the available sharing folders on the target box)
Here are some additional CMD commands which will help you.
Code:
net use \ipaddressipc$ “” /user:administrator
(this command will allow you to connect to the target as administrator)
Now if you want to connect to the target and browse the entire C drive, then use this command:
Code:
net use K: \computernameC$
(this will create a virtual drive on your “my computer” folder)
Please not that this command will only work if the target PC/laptop has not set a Adminastrator Password.
And least but not last, the “help” command.
Quote:
whatevercommand /help
or
Quote:
whatevercommand /?
This command is very useful in finding what a particular command does, especially if you are a newby.
Hope you liked the CMD commands listed above. If you have found any command other than those listed above, kindly note them in the comments for our other readers.