Showing posts with label Apress. Show all posts

Computational Techniques for Resolving Security Issues

Sanjib Sinha


e-books shop

Purchase Now !
Just with Paypal



Book Details
 Price
 4.00 USD
 Pages
 426 p
 File Size
 8,196 KB
 File Type
 PDF format
 ISBN-13 (electronic) 
 ISBN-13 (pbk)
 978-1-4842-3891-2
 978-1-4842-3890-5
 Copyright   
 2018 by Sanjib Sinha  

About the Author
Sanjib Sinha is a certified .NET Windows and
web developer, specializing in Python, security
programming, and PHP; he won Microsoft’s
Community Contributor Award in 2011.
Sanjib Sinha has also written Beginning Ethical
Hacking with Python and Beginning Laravel for Apress.

About the Technical Reviewer
Vaibhav Chavan holds a certification in ethical hacking and has worked
as a security analyst in the IT world as well as in the banking, insurance,
and e-commerce industries. He now works as a security analyst in Mumbai
and has more than five years of experience in the IT industry. He has
hands-on experience in Kali Linux and other tools such as the Metasploit
Framework, Burp Suite, Nessus, and more.

Introduction
You can get started in white-hat ethical hacking using Kali Linux, and this
book starts you on that road by giving you an overview of security trends,
where you will learn about the OSI security architecture. This will form the
foundation for the rest of Beginning Ethical Hacking with Kali Linux.
With the theory out of the way, you’ll move on to an introduction to
VirtualBox, networking terminologies, and common Linux commands,
followed by the step-by-step procedures to build your own web server and
acquire the skill to be anonymous. When you have finished the examples
in the first part of your book, you will have all you need to carry out safe
and ethical hacking experiments.

After an introduction to Kali Linux, you will carry out your first
penetration tests with Python and code raw binary packets for use in those
tests. You will learn how to find secret directories of a target system, how to
use a TCP client in Python and services, and how to do port scanning using
Nmap. Along the way, you will learn how to collect important information;
how to track e-mail; and how to use important tools such as DMitry,
Maltego, and others. You’ll also take a look at the five phases of penetration testing.

After that, this book will cover SQL mapping and vulnerability analysis
where you will learn about sniffing and spoofing, why ARP poisoning is a
threat, how SniffJoke prevents poisoning, how to analyze protocols with
Wireshark, and how to use sniffing packets with Scapy. Then, you will learn
how to detect SQL injection vulnerabilities, how to use Sqlmap, and how to
do brute-force or password attacks. In addition, you will learn how to use
important hacking tools such as OpenVas, Nikto, Vega, and Burp Suite.
The book will also explain the information assurance model and
the hacking framework Metasploit, taking you through important
commands, exploits, and payload basics. Moving on to hashes and
passwords, you will learn password testing and hacking techniques with
John the Ripper and Rainbow. You will then dive into classic and modern
encryption techniques where you will learn to work with the conventional
cryptosystem.

In the final chapter, you will use all the skills of hacking to exploit a
remote Windows and Linux system, and you will learn how to “own” a
remote target entirely.

Table of Contents
About the Author ...............................................................................xiii
About the Technical Reviewer ............................................................xv
Acknowledgments ............................................................................xvii
Introduction .......................................................................................xix
Chapter 1: Security Trends
Nature and Perspective .........................................................................................3
Before and After the Digital Transformation ..........................................................6
The OSI Security Architecture ...............................................................................6
Security Attacks, Services, and Mechanisms .....................................................10
Timeline of Hacking .......................................................................................14
How to Use Google Hacking Techniques .............................................................15
Further Reading ..................................................................................................17
Chapter 2: Setting Up a Penetration Testing and Network
Security Lab
Why Virtualization? .............................................................................................20
Installing VirtualBox ............................................................................................21
Installing Appliances on VirtualBox ...............................................................23
Installing VirtualBox Guest Addition ...............................................................29
Installing Metasploitable ...............................................................................31
Installing Windows ........................................................................................33
Installing Kali in VMware .....................................................................................36
Chapter 3: Elementary Linux Commands
Finding the Kali Terminal ....................................................................................42
Navigating the File System .................................................................................44
Working with Text Files .......................................................................................48
Searching Files ...................................................................................................49
Writing to the Terminal ........................................................................................51
Working with Directories .....................................................................................52
Setting File Permissions .....................................................................................53
Chapter 4: Know Your Network
Networking Layers ..............................................................................................61
Internetworking Models ......................................................................................65
OSI .................................................................................................................65
TCP/IP ............................................................................................................68
Further Reading ..................................................................................................69
Chapter 5: How to Build a Kali Web Server
Why Do You Need a Web Server? ........................................................................72
Introducing Sockets ............................................................................................73
Beginning the Web Server ..................................................................................73
Diving into Sockets .............................................................................................76
Installing PyCharm and the Wing IDE Editor .......................................................84
How to Stay Anonymous .....................................................................................86
Changing Your Proxy Chain ............................................................................88
Working with DNS Settings ...........................................................................92
Using a VPN ...................................................................................................94
Changing Your MAC Address .......................................................................100
Chapter 6: Kali Linux from the Inside Out 
More About Kali Linux Tools ..............................................................................106
Information Gathering ..................................................................................107
Vulnerability Analysis ...................................................................................108
Wireless Attacks ..........................................................................................109
Web Applications .........................................................................................109
WPS Tools ....................................................................................................110
Exploitation Tools .........................................................................................111
Forensic Tools ..............................................................................................111
Sniffing and Spoofing ..................................................................................112
Password Attacks ........................................................................................112
Maintaining Access .....................................................................................113
Reverse Engineering ...................................................................................113
Hardware Hacking .......................................................................................114
Exploring Kali Linux from the Inside .................................................................114
Machine Language ......................................................................................114
Registers .....................................................................................................115
Why Is Understanding Memory So Important? ............................................116
Editors .........................................................................................................117
Hacking Tools ..............................................................................................121
Staying Updated with SSH ................................................................................124
Getting Started ............................................................................................125
Working with Blacklists and Whitelists .......................................................128
Securing SSH ...............................................................................................130
Connecting to Kali Linux Over SSH ..............................................................134
Chapter 7: Kali Linux and Python
What Is Penetration Testing? ...........................................................................137
First Penetration Using Python ..........................................................................139
Whois Searches for More Information .........................................................142
Finding Secret Directories ...........................................................................152
Top-Level Domain Scanning ........................................................................158
Obtaining a Web Site’s IP Address ...............................................................161
TCP Client in Python and Services ....................................................................164
Capturing Raw Binary Packets ..........................................................................170
Port Scanning Using Nmap ...............................................................................174
Importing the Nmap Module ........................................................................175
What Does Nmap Do? ..................................................................................180
Nmap Network Scanner ..............................................................................183
Chapter 8: Information Gathering 
Python Virtual Environment ...............................................................................190
Reconnaissance Tools .......................................................................................197
Know the Domain and Hostname ................................................................198
E-mail Tracking Made Easy .........................................................................200
Searching the Internet Archive ....................................................................202
Passive Information .....................................................................................204
Web Spiders Are Crawling ...........................................................................205
More About Scanning ..................................................................................206
You Can Find Location Too! ..........................................................................213
DMitry, Maltego, and Other Tools .......................................................................214
Summarizing the Five Phases of Penetration ...................................................220
Chapter 9: SQL Mapping
Sniffing and Spoofing ........................................................................................221
Packing and Unpacking with Python ...........................................................223
Why Wireless Media Is Vulnerable ...............................................................227
ARP Poisoning Is a Threat ............................................................................228
SQL Injection .....................................................................................................241
Detecting SQL Injection Vulnerabilities ........................................................242
How to Use sqlmap ......................................................................................243
Brute-Force or Password Attacks .....................................................................253
Chapter 10: Vulnerability Analysis
Overview of Vulnerability Analysis Tools ...........................................................259
How to Use OpenVas .........................................................................................260
How to Use Nikto ..............................................................................................268
How to Use Vega ...............................................................................................270
How to Use Burp Suite ......................................................................................276
Chapter 11: Information Assurance Model 
What the AI Model Is All About ..........................................................................284
How to Tie the Elements Together? ...................................................................285
How the AI Model Works ...................................................................................287
Why Is the AI Model Important? ........................................................................289
Further Reading ................................................................................................290
Chapter 12: Introducing Metasploit in Kali Linux
Understanding the Metasploit Architecture ......................................................292
Summarizing Modules ......................................................................................295
Mixins and Plugins in Ruby ...............................................................................302
Metasploit Console or Interface ........................................................................304
Exploits and Payloads in Metasploit .................................................................308
How to Use Exploit and Payloads ................................................................309
How to Start Exploits ...................................................................................315
Chapter 13: Hashes and Passwords 
Hashes and Encryption .....................................................................................324
Password Testing Tools .....................................................................................327
John the Ripper and Johnny .............................................................................338
How to Use RainbowCrack ................................................................................342
Chapter 14: Classic and Modern Encryption
Nature and Perspective .....................................................................................348
Models of the Cryptography System .................................................................352
Types of Attacks on Encrypted Messages .........................................................354
Chapter 15: Exploiting Targets
Exploiting Linux with Metasploit .......................................................................358
Exploiting Samba .........................................................................................359
Exploiting IRC ..............................................................................................371
Exploiting Windows with Armitage ....................................................................380
Index .................................................................................................405

Bookscreen
e-books shop

Who This Book Is For
This book is primarily for information security professionals. However,
security enthusiasts and absolute beginners will also find this book
helpful. For absolute beginners, knowledge of high school algebra,
the number system, and the Python programming language is a plus.
However, this book provides an explanation of the foundational rules so
you can understand the relationship between them and ethical hacking,
information security, and the hacking-related tools of Kali Linux.
For more advanced professionals, the book also includes in-depth analysis.

Whether you are new to ethical hacking or a seasoned veteran, this
book will help you understand and master many of the powerful and
useful hacking-related tools of Kali Linux and the techniques that are
widely used in the industry today.
To start with, you need a virtual box or virtual machine, so proceed to Chapter 1.

Sanjib Sinha

Howrah, West Bengal, India


Begin Ethical Hacking with Python

Purchase Now !
Just with Paypal



Book Details
 Price
 2.00 USD
 Pages
 255 p
 File Size
 2,714 KB
 File Type
 PDF format
 ISBN
 eISBN
 978-1-4842-2540-0
 978-1-4842-2541-7
 Copyright   
 Sanjib Sinha 2017  

Prologue – Hacker’s Goal
This book is intended for complete programming beginners or general people
who know nothing about any programming language but want to learn ethical hacking.
Let us clear it first: Ethical Hacking is not associated with any kind of
illegal electronic activities. They always stay within laws. This book is
intended for those people – young and old – who are creative and curious and
who want to develop a creative hobby or take up internet security profession
acting as ethical hacker. Keeping that in mind we’ll also learn Python 3
programming language to enhance our skill as ethical hackers.
This book is not intended for any kind of malicious user. If anyone tries to
use this book or any type of code examples from this book for illegal purpose
this book will take no moral responsibility for that malicious behaviours.
If you think that you can use this book for any malicious purpose then you
are advised to read the first chapter “Legal Side of Ethical Hacking”. I hope
you won’t like the idea of ending up in jail by harming some other systems.
I would like to start this brief introduction with an image. This image
depicts many things that I will later discuss in detail. It says, “The author is
using “Ubuntu” Linux distribution as his default operating system. He has
installed Virtual Box – a kind of virtual machine – that runs in Windows also.
And in that Virtual Box he has installed three more operating systems. One is
“Windows XP” and the other two are “Kali Linux” and “Windows 7 Ultimate”.
The image also says, and that is very important, “Currently three operating
systems are virtually running on the desktop”.

( The virtual Box is running three operating systems. You can try any
kind of experiment on this Virtual OS. That will not damage your main
system. )
   As an ethical hacker you will learn how to defend yourself. To defend
yourself sometime you need to attack your enemy. But it is a part of your
defense system. It is a part of your defense strategy. More you know about your
enemy’s strategy, more you can defend yourself. You need to learn those tools
are frequently used by the malicious hackers or crackers. They use the same
tool that you use to defend yourself.
Whether you are an ethical hacker or a malicious cracker, you do the same
thing. You use the identical software tools to attack the security system. Only
your purpose or intention differs.
Probably you know that a big car company before launching a new model
of car generally tests the locking system. They have their own security
engineers and besides they call for the locking experts to test the vulnerability.
They pay a good amount of money if you can break the locking system of the
car. Basically it is a work of “PENTESTING”. The locking experts PENTESTS
the system and see if there is any weakness in the system.
It is good example of ethical hacking. The locking experts are invited to do
the job and they are paid well. On the contrary car thieves do the same job
without any invitation. They simply break the locking system of an unattended
car parked on the road side and take it away. I hope by now you have
understood the difference between ethical hacking and cracking.
Your main intention centers on the security of the system. Security consists
of four key components. As the book progresses you will increasingly be
finding words like “PENTESTING”, “EXPLOIT”, “PENETRATION”,
“BREAK IN THE SYSTEM”, “COMPROMISE THE ROUTER” etcetera. The
four key components mentioned below mainly deal with these terms.

Table of Contents
Part I
Chapter 1: Legal Side of Hacking
Chapter 2: Hacking Environment
Ethical Hacking and Networking
What Does Network Mean?
Summary
Chapter 3: Installing Virtual Box
Chapter 4: Installing Kali Linux and Other Operating Systems on VB
Chapter 5: Linux Terminal, Basic Commands
Summary
Part II
Chapter 6: Python 3 and Ethical Hacking
Chapter 7: Python Environment
Chapter 8: General Syntaxes
Create the main() function
Indentation and White Space
Commenting
Assigning Values
Chapter 9: Variables, Objects and Values
Using Numbers
String
What is Type and ID
Logical Values
Tuples And Lists
Dictionary
Object
Chapter 10: Conditionals
Chapter 11: Loops
While Loops
For Loops
Chapter 12: Regular Expressions
Using “re” Module
Reusing With Regular Expressions
Searching with Regular Expressions
Chapter 13: Exceptions, Catching Errors
Chapter 14: Functions
Return Values
Generate Functions
Lists of Arguments
Named Arguments
Chapter 15: Classes
Object-Oriented Methodology
The Foundation of Object Orientation
Understanding Classes and Objects
Write Your Own Game, “Good Vs Bad”
Primary Class and Object
Accessing Object Data
Polymorphism
Using Generators
Inheritance
Decorator
Chapter 16: String Methods
Chapter 17: File Input And Output
Chapter 18: Containers
Operating on Tuple and List Object
Operating on Dictionary Object
Chapter 19: Database
Let us start with SQLite3
MySQL for Big Project
Chapter 20: Module
Chapter 21: Debugging, Unittest Module
Chapter 22: Socket and Networking
Chapter 23: Importing Nmap Module
Chapter 24: Building an Nmap Network Scanner
Part III
Chapter 25: Protect Anonymity on the Internet
Chapter 26: Dark Web and Tor
Hidden Wikipedia
Chapter 27: Proxy Chains
Chapter 28: Virtual Private Network or VPN
Chapter 29: MAC Address
Epilogue—What Next
Index


Bookscreen
Begin Ethical Hacking with Python

The key components are: 
1. Availability
2. Integrity
3. Authenticity
4. Confidentiality
We will see how crackers want to attack these components to gain access to
the system. Since a hacker ’s main goal is to exploit the vulnerabilities of the
system so he wants to see if there is any weakness in these core components.
Let us assume the hacker wants to block the availability of the data. In that
case he will use the “Denial of Attack” or ‘DoS’ method. To do this attack
usually hackers use system’s resource or bandwidth. But DoS has many other
forms. When the resource or bandwidth of your system is eaten up completely,
the server usually crashes. The final target is one system but the number of
victims is plenty. It is something like millions of people gather in front your
house main door and jam it with a kind of human chain so that you and your
family members can not enter into it.
The second key component Integrity should not be compromised at any
cost. What does this term “integrity” mean? It’s basically centered on the nature
of data. When this nature of data is tampered with some kind of ‘BITFLIPPING’
attacks, the integrity of the system is also compromised. It can be
done just by changing the message itself. The data may either be in the move or
at rest, but it can be changed. Imagine what happens when a transaction of
money is tampered with the addition of few more zeroes at the end! Let us
assume a bank is transferring money. In its instruction it is written: “transfer
$10, 000”. Now the attacker changes the cryptic text in such a manner so that
the amount changes to $10, 000000. So the attack is intended for the message
itself or a series of messages.
The issue of authentication is normally handled by the Media Access
Control (MAC) filtering. If it is properly placed the network does not allow
unauthorized device. What happens if someone spoofs the MAC Address of a
legitimate network station and takes it off? He can take on the station’s identity
and control it. This is called authentication attack or MAC Address spoofing.
Finally the issue of confidentiality rises above all. Data travel in clear text
across the trusted network. Here data mean information. The information theft
like cracking someone’s password is confidentiality attack. The data or
information is intended for someone but instead of the recipient the hacker
gains the access. Actually the cracker steals it when the data is moving across
the trusted network as clear text.

- A Reference for Creating 2D and 3D Images -

B.J. Korites


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 4.00
 Pages
 365 p
 File Size 
 10,569 KB
 File Type
 PDF format
 ISBN-13
 978-1-4842-3377-1 (pbk)
 978-1-4842-3378-8  (electronic) 
 Copyright©   
 2018 by B.J. Korites

About the Author
B.J. Korites has been involved in engineering and scientific
applications of computers for his entire career. He has
been an educator, consultant, and author of more than
ten books on geometric modelling, computer graphics,
artificial intelligence, simulation of physical processes,
structural analysis, and the application of computers
in science and engineering. He has been employed by
Northrop Corporation, the Woods Hole Oceanographic
Institute, Arthur D. Little, Itek, and Worcester Polytech.
He has consulted for Stone and Webster Engineering, Gould Inc, Wyman Gordon, CTI
Cryogenics, the US Navy, Aberdeen Proving Grounds, and others. Early in his career he
developed mathematics and software that would find physical interferences between
three-dimensional solid objects. This found wide application in the design of nuclear
power plants, submarines, and other systems with densely packed spaces. He enjoys
sailing and painting maritime landscapes in oils. He holds degrees from Tufts and Yale.

About the Technical Reviewer
Andrea Gavana has been programming in Python for
almost 15 years and dabbling with other languages since the
late nineties. He graduated from university with a Master’s
degree in Chemical Engineering, and he is now a Senior
Reservoir Engineer working for Maersk Oil in Copenhagen, Denmark.
Andrea enjoys programming at work and for fun, and
he has been involved in multiple open source projects, all
Python-based. One of his favorite hobbies is Python coding,
but he is also fond of cycling, swimming, and cozy dinners
with family and friends.

Table of Contents
About the Author .............
About the Technical Reviewer ..............
Acknowledgments ....
Chapter 1: Essential Python Commands and Functions
1.1 Programming Style   2
1.2 The Plotting Area   3
1.3 Establishing the Size of the Plotting Area   4
1.4 Importing Plotting Commands   6
1.5 Displaying the Plotting Area  8
1.6 T he Plotting Grid  8
1.7 Saving a Plot  8
1.8 G rid Color   9
1.9 T ick Marks  9
1.10 Custom Grid Lines   11
1.11 L abelling the Axes  13
1.12 T he Plot Title  14
1.13 C olors  15
1.13.1 C olor Mixing  16
1.13.2 C olor Intensity  19
1.14 O verplotting  20
1.15 B ackground Color  23
1.16 T he Plotting Area Shape  23
1.17 How to Correct Shape Distortions  26
1.17.1 Applying a Scale Factor When Plotting   27
1.17.2 The Best Way: Scaling the Axes in plt.axis( )  27
1.18 Coordinate Axes   29
1.19 Commonly Used Plotting Commands and Functions   30
1.19.1 Points and Dots Using scatter( )  31
1.19.2 Lines Using plot( )  32
1.19.3 Arrows   33
1.19.4 Text   34
1.19.5 Lists, Tuples, and Arrays   36
1.19.6 Arrays   41
1.19.7 arange( )  42
1.19.8 range( )   43
1.20 S ummary   43
Chapter 2: Graphics in Two Dimensions   
2.1 Lines from Dots  45
2.2 Dot Art  50
2.3 Circular Arcs from Dots  52
2.4 Circular Arcs from Line Segments  59
2.5 C ircles   60
2.6 D ot Discs   64
2.7 E llipses  68
2.8 2D Translation   75
2.9 2 D Rotation  78
2.10 Summary  100
Chapter 3: Graphics in Three Dimensions
3.1 The Three-Dimensional Coordinate System  101
3.2 Projections onto the Coordinate Planes   104
3.3 Rotation Around the y Direction   106
3.4 Rotation Around the x Direction   109
3.5 Rotation Around the z Direction  111
3.6 Separate Rotations Around the Coordinate Directions  113
3.7 Sequential Rotations Around the Coordinate Directions   121
3.8 Matrix Concatenation   129
3.9 Keyboard Data Entry with Functional Program Structure   133
3.10 Summary  141
Chapter 4: Perspective
4.1 Summary  152
Chapter 5: Intersections
5.1 Line Intersecting a Rectangular Plane  153
5.2 Line Intersecting a Triangular Plane  166
5.3 Line Intersecting a Circle   181
5.4 Line Intersecting a Circular Sector   181
5.5 Line Intersecting a Sphere   187
5.6 Plane Intersecting a Sphere   196
5.7 S ummary  201
Chapter 6: Hidden Line Removal
6.1 Box   203
6.2 Pyramid  212
6.3 Planes   218
6.4 Sphere   225
6.5 S ummary  233
Chapter 7: Shading
7.1 Shading a Box  236
7.2 Shading a Sphere  246
7.3 Summary   253
Chapter 8: 2D Data Plotting
8.1 Linear Regression   265
8.2 Function Fitting   269
8.3 Splines   275
8.4 Summary   283
Chapter 9: 3D Data Plotting
9.1 3D Surfaces   297
9.2 3D Surface Shading   305
9.3 Summary   319
Chapter 10: Demonstrations
10.1 Saturn  321
10.2 Solar Radiation  331
10.2.1 Photons and the Sun   331
10.2.2 Max Planck’s Black Body Radiation   333
10.2.3 The Sun’s Total Power Output  334
10.3 Earth’s Irradiance  344
10.3.1 The Earth Sun Model  346
10.4 Summary  351
Appendix A: Where to Get Python ....... .......... 353
Appendix B: Planck’s Radiation Law and the Stefan-Boltzmann Equation ........... 355
Index . ........................ 359


Bookscreen
e-books shop

Acknowledgments
I would like to thank my wife, Pam, for her patience during the many long days and
nights that I spent writing this book and for her understanding of the distant stare I
sometimes had while off in another world thinking of math and Python, two of life’s great
joys. I would also like to thank everyone at Apress, especially editors Todd Green and Jill
Balzano, who made the production of this book a fast and seamless process.

Sloan Kelly


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 4.00
 Pages
 395 p
 File Size 
 5,991 KB
 File Type
 PDF format
 ISBN-13
 978-1-4842-4532-3 (pbk)
 978-1-4842-4533-0(electronic) 
 Copyright©   
 2019 by Sloan Kelly

About the Author
Sloan Kelly has worked in the games industry
for nearly 12 years. He has worked on a
number of AAA and indie titles and currently
works for an educational game company. He
lives in Ontario, Canada, with his wife and
children. Sloan is on Twitter @codehoose and
makes YouTube videos in his spare time.

About the Technical Reviewer
John Watson is a game developer, artist, guitar
player, husband, and father. Among John’s
many software-powered side projects, he’s
building a Raspberry Pi–powered device that
generates interactive music in live modern
dance performances. He’s also developing a
retro-inspired 2D twin-stick arcade shooter
called Gravity Ace. You can follow his progress
on Twitter @yafd or at gravityace.com. Stop by
and say hi!

Introduction
This book is intended for anyone who wants to learn how to program
games. It is ideally suited to students who want to learn Python and
PyGame on their Raspberry Pi. While not necessary, this book has been
oriented toward the Raspberry Pi computer.
The Python programming language is ideally suited to beginners and
experts alike. The skills you will learn in this book are easily transferable to
other computer languages too.
If you are unfamiliar with the Raspberry Pi, there are several good
eBook guides on getting started including mine called A Slice of Raspberry
Pi, available from all good eBook retailers.
This book assumes that you are familiar with the Raspberry Pi
computer and that you have the Raspberry Pi Foundation’s recommended
Raspbian operating system installed. Raspbian is a distribution of the
Debian Linux operating system built specifically for the Raspberry Pi. This
distribution contains all the Software Development Kits (SDKs) including
one for Python that includes PyGame. If you don’t have Raspbian installed,
you will have to ensure that you have Python and PyGame installed on
your system.
Don’t have a Raspberry Pi? Not to worry, you can still learn Python and
PyGame. The code in this book will work on other OSs with Python and
PyGame installed; Python is a platform-independent language.
You can obtain more information and download versions of Python from
www.python.org. PyGame can be obtained from www.pygame.org/.
Sprites from Ari Feldman’s SpriteLib have been used for the projects
contained in this book.


Table of Contents
About the Author ..............................................................................xvii
About the Technical Reviewer ...........................................................xix
Acknowledgments .............................................................................xxi
Introduction .....................................................................................xxiii
Chapter 1: What Is a Programming Language? ....................................1
What Does a Computer Program Do? ...................................................................2
Conclusion ............................................................................................................3
Chapter 2: What Is Python? ..................................................................5
Programming Styles ..............................................................................................5
Object-Oriented .....................................................................................................7
Functional .............................................................................................................8
What Is Pygame? ..................................................................................................8
Conclusion ............................................................................................................9
Chapter 3: Introducing Python ............................................................11
The Terminal Window ..........................................................................................11
Running the Python Interpreter ...........................................................................12
Python Is Interpreted ...........................................................................................13
Python As a Calculator ........................................................................................13
Keywords ............................................................................................................16
Printing ...............................................................................................................17
String Formatting ..........................................................................................19
Variables .............................................................................................................22
Naming Variables ...........................................................................................22
Python As a Calculator, Part II .............................................................................23
Arithmetic Operators .....................................................................................26
Data Types .....................................................................................................27
Numeric Types ...............................................................................................27
String Formatting Again ................................................................................29
Conclusion ..........................................................................................................31
Chapter 4: Breaking Free from the Interpreter ...................................33
What Is IDLE? ......................................................................................................33
Starting IDLE .......................................................................................................33
Starting a New File .............................................................................................34
Hello, World! ........................................................................................................36
Running from the Command Line ..................................................................36
Running from Inside IDLE ..............................................................................38
Conclusion ..........................................................................................................39
Chapter 5: Making Decisions ..............................................................41
A Note About Blocks ............................................................................................44
Testing for Equality .............................................................................................45
Using Boolean Logic ............................................................................................50
And ................................................................................................................50
Or ...................................................................................................................51
Not .................................................................................................................52
Nesting Ifs ...........................................................................................................52
A Note on Switch ................................................................................................54
Conclusion ..........................................................................................................54
Chapter 6: Making the Raspberry Pi Repeat Itself .............................55
The for Loop ........................................................................................................55
The range() Function .....................................................................................57
While Loops .........................................................................................................58
Counting ........................................................................................................58
Sentinel .........................................................................................................60
Conditional .....................................................................................................62
Conclusion ..........................................................................................................62
Chapter 7: Containers .........................................................................63
Container Nomenclature .....................................................................................63
Tuples ..................................................................................................................64
Removing Elements from a Tuple ..................................................................64
Changing Element Values ..............................................................................65
Tuples in Printing ...........................................................................................66
Deconstructing Tuples ...................................................................................67
Lists ....................................................................................................................67
List Creation ..................................................................................................68
Adding Values to the List ...............................................................................68
Removing Values from a List .........................................................................69
Doctor’s Waiting Room Program ....................................................................70
Dictionaries .........................................................................................................73
Iterating Through Dictionaries .......................................................................74
Adding New Items to Dictionaries .................................................................74
Removing Entries from a Dictionary ..............................................................74
Conclusion ..........................................................................................................75
Chapter 8: Putting It Together: Tic-Tac-Toe ........................................77
The Rules ............................................................................................................77
Program Layout ...................................................................................................79
Variables .............................................................................................................79
The Game ............................................................................................................80
Save and Run ......................................................................................................85
Conclusion ..........................................................................................................85
Chapter 9: Basic Introduction to PyGame ...........................................87
Importing the PyGame Framework .....................................................................87
Initializing PyGame ..............................................................................................88
The Main Loop ....................................................................................................89
Images and Surfaces ..........................................................................................92
Creating Images ..................................................................................................93
Loading Images ...................................................................................................93
Drawing Images ..................................................................................................94
Screen Coordinates and Resolution ....................................................................94
Sprite Sheets ......................................................................................................95
Full Listing ..........................................................................................................97
Conclusion ..........................................................................................................97
Chapter 10: Designing Your Game ......................................................99
Initial Concept .....................................................................................................99
Prototyping ..................................................................................................100
Functional Specification ...................................................................................101
Weapon Firing .............................................................................................101
Program Design ................................................................................................101
Coding ...............................................................................................................102
Testing ..............................................................................................................104
Iteration .............................................................................................................105
Conclusion ........................................................................................................105
Chapter 11: Game Project: Bricks ....................................................107
The Main Framework ........................................................................................108
Images ..............................................................................................................109
Moving the Bat ..................................................................................................110
Bat Initialization ...........................................................................................111
Drawing the Bat ...........................................................................................112
Moving the Bat ............................................................................................112
Moving the Ball .................................................................................................114
Ball Initialization ..........................................................................................114
Ball Movement .............................................................................................115
Bat and Ball Collision ...................................................................................118
Serving the Ball ...........................................................................................120
Brick Wall ..........................................................................................................121
Brick and Ball Collision ................................................................................122
Out of Bounds ..............................................................................................124
Conclusion ........................................................................................................125
Chapter 12: User-Defined Functions .................................................127
What Is a Function? ..........................................................................................127
Format of a Function .........................................................................................127
Functions as a Menial Task/Mnemonic Device .................................................128
Sending Parameters .........................................................................................129
Default Argument Values ...................................................................................131
Named Parameters ......................................................................................132
Returning Values ...............................................................................................133
Returning Tuples ..........................................................................................134
Accessing Global Variables ...............................................................................135
Real-World Example of a Function ....................................................................136
Conclusion ........................................................................................................139
Chapter 13: File Input and Output .....................................................141
Reading a File from Disk ...................................................................................141
Writing Data to a File ........................................................................................143
Reading and Writing Containers to a File ..........................................................144
Writing Your Own Serializer .........................................................................145
Writing Your Own Deserializer .....................................................................147
JSON .................................................................................................................148
JSON Serialization .......................................................................................148
JSON Deserializer ........................................................................................149
Handling Errors .................................................................................................150
Conclusion ........................................................................................................151
Chapter 14: Introducing Object-Oriented Programming ...................153
Classes and Objects ..........................................................................................154
Encapsulation ...................................................................................................154
Abstraction ........................................................................................................155
Inheritance ........................................................................................................155
Polymorphism ...................................................................................................155
Why Should You Use OOP? ................................................................................156
Data Hiding ..................................................................................................156
Reusable ......................................................................................................156
Easier to Code and Test Separately .............................................................156
The Ball Class ...................................................................................................157
Creating an Instance of the Class .....................................................................160
The Ball update( ) Method ............................................................................161
Constructors ................................................................................................162
SOLID ................................................................................................................164
Single Responsibility ...................................................................................165
Open-Closed Principle .................................................................................165
Liskov Substitution ......................................................................................166
Interface Segregation ..................................................................................166
Dependency Inversion .................................................................................167
Conclusion ........................................................................................................170
Chapter 15: Inheritance, Composition, and Aggregation ..................171
Inheritance ........................................................................................................172
Base and Child Classes .....................................................................................173
Programming to the Interface .....................................................................175
A Note About Constructors and Base Classes .............................................175
Composition ......................................................................................................177
Aggregation .......................................................................................................179
Conclusion ........................................................................................................180
Chapter 16: Game Project: Snake .....................................................181
Functions ..........................................................................................................182
Snake Framework .............................................................................................183
Images ..............................................................................................................190
Loading the Images .....................................................................................191
The Game Map ..................................................................................................192
Drawing the ‘Game Over’ Screen ......................................................................193
Drawing the Game ............................................................................................195
Drawing the Walls .............................................................................................196
Drawing the Player Data ...................................................................................198
Drawing the Snake ............................................................................................199
Updating the Game ...........................................................................................202
The updateGame( ) Method ..........................................................................203
Snake Movement .........................................................................................205
Touching a Berry ..........................................................................................206
Collision Detection ............................................................................................208
Helper Functions .........................................................................................208
Conclusion ........................................................................................................212
Chapter 17: Model View Controller ...................................................213
Model ................................................................................................................214
View ..................................................................................................................214
Controller ..........................................................................................................214
Why Use MVC? ..................................................................................................215
The Classes .................................................................................................216
Folder ..........................................................................................................217
The Robot Model .........................................................................................217
The Robot View ............................................................................................219
The Radar View ............................................................................................221
The Robot Controller ....................................................................................222
The Robot Generator ....................................................................................225
Ensuring Constant Speed ..................................................................................227
The Main Robot Program ..................................................................................228
Conclusion ........................................................................................................230
Chapter 18: Audio .............................................................................233
Playing a Sound ................................................................................................234
Playing, Pausing, and Changing Volume ...........................................................235
Conclusion ........................................................................................................240
Chapter 19: Finite State Machines ...................................................241
Game State .......................................................................................................241
Menu System ....................................................................................................241
Non-player Artificial Intelligence .......................................................................242
A Finite State Machine Example .......................................................................243
Finite State Machine Manager ....................................................................244
Conclusion ........................................................................................................249
Chapter 20: Game Project: Invaders .................................................251
The Classes .......................................................................................................253
The Finite State Machine ..................................................................................254
MVC and ‘Invaders’ ...........................................................................................255
The Framework .................................................................................................255
Bitmap Font .................................................................................................259
Interstitial Screens ......................................................................................263
The Main Menu ............................................................................................264
Player and Bullets .............................................................................................267
The Bullet Classes .......................................................................................267
The Player Classes ......................................................................................270
Testing Player ..............................................................................................273
The Alien Swarm Classes ..................................................................................275
Collision Detection ............................................................................................282
Explosions ...................................................................................................282
Collision Controller ......................................................................................285
The Main Program .............................................................................................288
The Main Game State ........................................................................................289
Running the Game ............................................................................................292
Conclusion ........................................................................................................293
Chapter 21: Simple Electronics with the GPIO Pins ..........................295
Voltage, Current, and Resistance ......................................................................296
What You Will Need ...........................................................................................298
Breadboard ..................................................................................................298
Breakout Board ............................................................................................299
Jumper Wires ..............................................................................................300
LEDs ............................................................................................................302
Resistors ......................................................................................................304
Switches ......................................................................................................307
Building a Circuit ...............................................................................................308
Connecting the Breakout Board to the Raspberry Pi ...................................308
Providing Power and Ground .......................................................................311
Adding the LED ............................................................................................312
Completing the Circuit .................................................................................313
Testing the Circuit ........................................................................................315
Pin Meanings ....................................................................................................316
The gpiozero Library .........................................................................................317
The Circuit ...................................................................................................318
The Python Program ....................................................................................319
Getting Button Input ....................................................................................320
Reading Button Input in Python ...................................................................321
Conclusion ........................................................................................................322
Chapter 22: Game Project: Memory ..................................................323
Arranging the Breadboard .................................................................................324
Placing the LEDs ..........................................................................................324
Testing the Circuit .............................................................................................326
Placing the Tact Switches ............................................................................327
Testing the Button Circuit ............................................................................328
The Memory Game ............................................................................................330
The ButtonLED and ButtonLEDCollection Classes .......................................331
The Main Program .......................................................................................334
Full Listing buttonled.py ....................................................................................336
Full Listing memorygame.py .............................................................................338
Conclusion ........................................................................................................339
Chapter 23: Game Project: Quiz ........................................................341
The Electronics .................................................................................................341
Testing the Buttons ......................................................................................342
The Finite State Machine ..................................................................................345
Making the Game ..............................................................................................347
The Questions ..............................................................................................348
UI Helper Classes .........................................................................................354
The Game Runner and Base State Class .....................................................359
Player Input .................................................................................................361
The State Classes ........................................................................................362
Playing the Game ..............................................................................................376
Conclusion ........................................................................................................377
Chapter 24: Conclusion .....................................................................379
Index .................................................................................................381


Bookscreen
e-books shop

Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Spandana Chatterjee
Development Editor: James Markham
Coordinating Editor: Divya Modi
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Loading...
DMCA.com Protection Status