ads

Python Basics - Kickstart with Python (Python for Hackers Part-3.2)


Lists

Python allows you to make use of a list data structure which is extremely useful when it comes to storing collections of objects. As a programmer, you can create lists that contain different types of data. At the same time, you can also make use of several built-in techniques in Python that will allow you to insert, index, count, sort, append, remove, pop, and even reverse items in a list. Take a look at this example:


Using the above code, you were able to create a list through the method append(), print all the specified items, and then manage to sort the items before you asked the program to print them again. You were also able to find an item’s index and also remove particular items.

Dictionaries

Python’s dictionary structure allows you to make use of a hash table that can be used to store virtually any amount of objects. The program’s dictionary contains a pair of items which consists of a key and its corresponding value.


Dictionaries are extremely helpful in creating hacking scripts. For example, you can create a scanner that is designed to exploit vulnerabilities of a particular system, such as open TCP ports. If you have a dictionary that will display service names for corresponding ports that you want to exploit. For example, you can create a dictionary that will allow you to look up the ftp key, and then provide you an output of 21, which corresponds to a port that you may want to test. You can also use dictionaries to perform brute force attacks to crack an encrypted password.What makes Python even better is that you can code your own dictionaries and use them in other scripts that you may want to develop in the future. 

When you create a dictionary, keys should be separated from their corresponding value with a colon, and the items should be separated using commas. In the following example, you will be able to use the .keys() method to give you a list of all the available keys in the dictionary, and the .items() method that will provide you all the items that the dictionary contains. Take a look at this example:


Now that you know the basic concepts that make Python scripts perform tasks, you are now ready to start using them in your own script. In the next chapter, you will learn how a readable Python script should look like.

Post a Comment

0 Comments