Sunday, September 29, 2013

C++ Tutorial #3: Getting Comfortable With Command Prompt

Note: Folders are going to become a frequent topic of conversation.  I highly recommend you create a special folder dedicated to your programming.  I have a one under "C:" entitled "ProgrammingProjects" (so it's C:\ProgrammingProjects).  It's just an easier way to keep things organized.

Okay, so you're feeling pretty accomplished right about now.  You have a basic understanding of how programming works, you've got Dev-C++ and a compiler, and at the end of the last post I said, "You're ready to learn how to program."

But I forgot one little thing.

I didn't think about it because it's included in computers already—no software to download.  But you do have to become familiar with a command line.

What the hell is a command line?  Here's a pretty drawn-out but necessary and non-skimmable explanation: an interface is a method by which a user (you) communicate with digital technology (your computer).  If you use Windows, OSX, or a similar operating system, you are using a graphical-user interface, or GUI.  This means that you and the computer communicate via graphics—you know, stuff you can see.  Menus, buttons, you use a mouse in addition to a keyboard, etc.  GUIs were developed because they're very intuitive and easy on the eyes, but computers haven't always used them.

Before the age of the GUI, there was something called a command line interface, or command line.  For example, if you remember Disk Operating System (DOS) (this goes way back to the late 80s/early 90s), that was a command line.  It's basically a black screen with white (or alien green if you were lucky) letters.  No mouse was used, everything was in plain text format, and you got the computer to do what you wanted it to do not by clicking buttons and scrolling through menus but typing out rather cryptic-looking commands.

Source: Wikipedia

This is what a command line looks like.  Yes, kind of creepy, but you'll need it to test-run your programs once they're written.  While DOS is no longer used, modern computers still have command line programs that will work the same way.

Unix-like operating systems (such as Linux and Mac OSX) have their own command lines that operate their own way with their own commands.  I have minimal experience programming with the Unix command line, and I actually have never owned any Unix-based OSes, so I won't be covering them.  If you ever take a programming class at a college or university, it's almost certain that you will use a Unix-based system.  However, the main point of this tutorial is to get you familiar with the C++ language, not any kind of OS, so I'm going to teach it based on the command line I'm most comfortable with.  If you use a different OS, then I'm sure you can find a guide to basic commands online that are equivalent to the ones I demonstrate here.  I don't want to try to explain them because, honestly, I don't understand Unix well enough and I don't want to give incorrect instructions.

Using the Windows Command Line

Modern versions of Windows (and by "modern" I mean in the last 10 years) use a program called Command Prompt.  It's a command line, just like DOS, but it exists as a smaller program within Windows (which is a GUI).  To get to Command Prompt, either search for it on your computer or (if you like using the "Run..." button), run cmd.exe.

A really scary-looking box like this one should open up.  (Note: I blotted out the name because I'm currently using someone else's computer and would like to respect their privacy.)

Every time you open up Command Prompt, you'll have that little copyright thing at the top.  For the sake of explaining this, we're going to pretend that the user on this computer (the name that I blotted out) is "LadyPakenham".  The weird C:\Users\LadyPakenham> thing is called a prompt.  You notice how it's got the little cursor thing after the "greater than" (>) sign?  That cursor is where you type the commands that tell the computer what to do.

Get it?  It's prompting you for commands.

Using Commands: cd.. and cd

Okay, simple enough.  But what are you supposed to type into this thing anyway?  What are you going to want your computer to do when you're programming?

Well, when you go to program, the first thing you're going to want to do is open Command Prompt and navigate to the folder where you're keeping your programming projects.  In this case, my special programming folder is C:\Programming_Projects.  When I open up Command Prompt, its default setting is to take me to C:\Users\LadyPakenham.  How do I navigate from one folder to another?

There are two commands you can use to do this: cd.. and cd.  In both cases, "cd" means "change directory" (remember, a directory is a folder).  The difference between the two of them?  cd.. (with the two periods) means to move out of a directory, where cd means to move into a directory.  Let me show you:

1) cd.. moves out of a directory

Let's say I want to get from C:\Users\LadyPakenham to just plain old C:.  I have to move out of the directories LadyPakenham and User, one at a time.  In this example, the prompt is going to be in bold, while the commands I type will not.  I'll type a command and then press Enter, producing another prompt on another line.


You see what I did there?  Every time I typed cd.. it removed one directory from the prompt.  It's equivalent to going through folders in Windows Explorer and hitting the "Back" button.

2) cd moves into a directory

Now, let's say I'm in C: and I want to get back to C:\Users\LadyPakenham.  To enter into a directory (which is the same as double-clicking a folder you want to get into), you type the command cd (without periods), hit the Spacebar, and then type the name of the directory you want to enter, like so:

C:\>cd Users
C:\Users>cd LadyPakenham

3) How to get to your programming folder

I personally recommend that when you make a folder for your programming projects, it be something simple, like C:\ProgrammingProjects.  You know, just so it's easy to get to when you use Command Prompt.  Let's say that I did that, and wanted to get from C:\Users\LadyPakenham to my programming folder.  This is how I would use both "change directory" commands to do so:

C:\>cd ProgrammingProjects

Ta-da!  I'm in a good place to test-run my programs.

4) What if I don't know where my desired directory is?

It's a truth of life: folders have subfolders, and sometimes you can't remember which folder has the subfolder you're looking for.  In this case, you can use a third command, called dir, to view the contents of a directory.  Look at the picture I got from Wikipedia again:

Look at the line directly under "FreeCom version blah blah blah".  You see the prompt C:\> with the command dir.  It displays a lot of stuff.  The first line that appears upon typing the command and pressing Enter tells you the name of the directory (in this case, C:).  The second line tells you the serial number (since this directory just happens to be the entire hard drive).  Finally, it tells you everything that's in the directory of C:.

In the list that follows, the leftmost column has the names of all files and sub-directories.  The second column has the name of file extensions.  Notice how FDOS is a sub-directory while AUTOEXEC.BAT is a file.  The file size of all files is given, then the date and time of modification.  If, in the file size column, <DIR> is listed, that means the given item is a sub-directory and not a file.

So, if the user wanted to get into the FDOS folder, he or she could just type cd FDOS and the prompt would change to C:\FDOS>.

Why am I telling you this?  If you can't remember where your programming folder is, you can always use dir to see what's in the directory you're currently in.  That way, you can keep searching directories until you find it.  (A lot of headache can be eliminated by just keeping the folder in an easy-to-remember place, like C:\ProgrammingProjects, but dir is still a helpful command to know.)

5) Finally, how to run a file

Running files is easy.  Just type the file name and extension.  Let's say you're in your designated programming folder in Command Prompt, and you wrote and compiled a program called Hello.exe.  Literally, all you have to do is type Hello.exe.

An important thing to note: make it a habit to type the file extension (the .exe part in this case) as well as the name.  Why?  Well, remember how I told you in Tutorial #1 that you have two files for every program you write (the source code version and the machine code version)?  Well, both of them are going to have the same name, but different extensions.  In this case, the source code file (written in C++) would be named Hello.cpp, and the executable file (translated into machine code) would be Hello.exe.  If you just type Hello, without any extension, you might not get the program you want.  Your computer may open one or the other, but not both, and closing out of the wrong program and opening the one you want is a time-waster.  Be specific when running files.

Okay, I think that really is all the preliminary work this time.  I know it's frustrating when you're first getting started—you just want to program already!  But getting your computer set up and becoming familiar with the tools you need will save you a lot of grief in the long run.  Trust me, it's tough to program when you know the environment you're in!  Don't make things more difficult for yourself than they need to be.

Wednesday, September 25, 2013

C++ Tutorial #2: Installing Dev-C++ and a Compiler

The program you're going to want to install is called Dev-C++, and you can download it here.  Download "Dev-C++ 5.0 beta 9.2 ( (9.0 MB) with Mingw/GCC 3.4.2" (it's the first option).

It includes two things.  The first is the actual Dev-C++ program.  It includes a color-coded editor (which is EXTREMELY helpful because different parts of the code have different colors) and a relatively simple interface (I actually don't use most of the buttons and options it comes with, so don't be intimidated by them).  The second part (the "Mingw/GCC") is the compiler. After you write your code with the Dev-C++ editor, you'll use the GCC to compile it into machine code.

Here are the installation/setup instructions:

1) Download the program from the link I provided.  (I've used SourceForge before; you're safe.)

2) There will be a file in your "Download" folder called "devcpp-".  Run it.

3) Follow the installation instructions.  Your installation folder should be: "C:\Dev-Cpp"

4) When you get that scary error message ("The following directories don't exist...") just click "Yes".  It will install the compiler for you.

5) Open Dev-C++ (search for it and it should pop up).

6) On the toolbar, go to Tools > Compiler Options > Directories.

There will be a little box you can use to browse for the compiler directory (the folder where your compiler is).  This is what it looks like:

Click on that and browse for the following folder (don't worry, I'll include a picture too): C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2.

I do hope these motivational smileys are helping.

Once you find it, click "OK" and then "Add".  You should see that horribly long directory appear in the box like so:

Motivation with a capital M.

7) Next, click the "Programs" tab.

In the first line (dubbed "gcc:"), leave the text in the box alone (it should say "gcc.exe") but type in some extra stuff before it: C:\Dev-Cpp\Bin\.  So the first text box should say C:\Dev-Cpp\Bin\gcc.exe.

8) Do this with all the other text boxes (tip: you can save time by copying "C:\Dev-Cpp\Bin\" and pasting them in the other boxes).  Make sure that your end result looks like this:

 Notice how you just added that one string to every line?
Don't DELETE anything from the text boxes, just add to them.

9) Click OK.  The installation process is over.

You now have two new programs: Dev-C++, which will help you write and edit programs, and the GCC compiler, which will help you translate them into machine code.

You're ready to learn programming.

C++ Tutorial #1: How Code Becomes a Program

Part 1 of the C++ tutorial, in which I try to explain (as efficiently as possible) how code works...

Modern-day programming, regardless of language, utilizes two basic types of code: machine code and source code.

Machine code is just another way of saying binary code—it's a bunch of 0s and 1s.  The reason it's called "machine" code is because a computer is indeed a machine that operates on electrical signals.  The 0s and 1s are comparable to switches being "off" and "on" respectively.  Think of machine code/binary as Morse code for computers.  It is the one and only language a computer understands.

However, it would be next-to-impossible to write modern programs in binary—just think of all those wacky combinations of 0s and 1s we'd have to understand.  Thus, people created more understandable languages, like C++, to make things easier.  C++ is what we call a high-level programming language, meaning it's very close to English (at least, compared to binary).  As a programmer, you'd be much happier working with C++ than machine code.

Still, one question remains: if you write a program in C++, but the computer only understands binary, how do you get a C++ program to run?

The answer is that you translate it.  After you write code, you have to compile it, or translate it into binary.  So you actually end up with two files for every program you write: the original file with the C++ code you wrote (this is called source code) and the new file, translated into binary, that the computer can understand (this is the executable file, which is what people who use your program would run).

How do you translate source code into machine code?  Well, you use a special type of program called a compiler, which will so kindly translate and create an executable file for you.  If you own a Mac computer with OSX, you already have a compiler.  However, if you use Windows on any type of computer, you'll need to install one yourself.  But fear not—just pay close attention and you'll get it.

I'll tackle actually installing the necessary programs in the next post, but for now, just review these terms:

Machine code: also, "binary".  A code of 0s and 1s that the computer understands as language.
Source code: the high-level code (such as C++) used in programming.
Compile: to translate high-level code into machine code.
Compiler: the program that does this for you.
Executable file: a file with source code translated into machine code.

As usual, if you have any questions, feel free to comment or email me.


Sunday, September 22, 2013

An External Resource: the MMPC

The Microsoft Malware Protection Center (MMPC) is a great place to learn more about threats and what you can do to protect yourself from them (it goes without saying that this site is most helpful to Windows users, but others can benefit from reading up on some of its articles as well).

The most helpful part of this site, for me, was the malware encyclopedia.  You can learn about common terminology (which will be of use when reading any security-related work) in the Glossary

You can learn about how malware is named (within the Microsoft Corporation, as well as many other security organizations) here.

Under the "Malware Encyclopedia" tab you can find more information on different types of malware (getting more specific than I did in my first three posts) and specific programs.  There's also a "help" section for those who are infected or worried about becoming infected.

Note: There are some parts of the site, particularly those under "Our Research", that are geared more towards advanced "power users".  Of course, anyone should feel free to check out those reports.  You never know—sometimes you think something is way over your head, but you still learn something valuable from it.

I have to say, they've really revamped their site since I was last there.  There's lots of new information, and it just looks nicer in general.  I hope it helps you as much as it helped (and still helps) me!

Friday, September 20, 2013

The 5 Most Important Things to Know When Surfing the Net

Just a short, general list of things that everyone—amateurs to tech junkies—should keep in mind when using the Internet.  Also, I want to make sure I don't go a whole month without posting again.

1) Don't believe everything you see—especially if it looks too good to be true.

This means something different for every Internet user.  If you're a student, it means don't use Wikipedia as a source.  If you're a consumer looking to buy something, it means don't trust the ads that pop up or assault you on every webpage you visit.  Really, you should follow the same general rules that you (should) use in real life: don't blindly take anyone's word for anything, and if something looks too good (or too convenient) to be true, then it probably is.

2) Be careful with online commerce.

I would caution against paying for something online if you have alternatives.  Increasingly, more and more companies are mandating that online purchases be paid for online (rather than by check).  However, even large companies like Amazon can be hacked, and you don't want anyone getting hold of your credit/debit card or bank account number.  If you're going to do online commerce, the safest option is to use a credit card.  An even better idea is to have a separate credit card designated only for online payments.  If someone makes a fraudulent charge and the credit card company catches them, you can be reimbursed.  However, if a hacker takes money directly from your bank account using a debit card or bank account number, you probably won't see that money again.  And they will drain your account.  Very quickly.

2.5) PayPal is a cool alternative to using credit/debit/bank account numbers online, but it can be hacked too.

Your PayPal account can be hacked, PayPal itself can be hacked, and companies using PayPal for transactions can be hacked so that transactions are rerouted to a different source.  You're never safe when engaging in E-commerce.

3) Don't give out personal information.  Just don't.

Okay, occasionally you have to give information to a trusted, verifiable source (ex. giving Amazon your home address so they can send you what you ordered).  However, your forum friends don't need to know what your full name is (hell, your Facebook friends don't need to know).  People often make the mistake of giving out info such as their name, age, address, phone number, personal things about their life and relationships, etc. in public places like forums and social media sites.

A lot of people can use this information against you.  First of all, hackers love a good case study.  Having all that information really helps when attempting to steal your identity.  And second, people can use that information in very negative ways.  There are a lot of cool, normal people on the Internet, but there are also a lot of psychopaths (yes, legitimate, clinical psychopaths).  As much as we don't want to believe it, people who have tendencies for violent, perverse, and/or predatory behavior exist in society, and they're all on the Internet.  And, as in real life, there are more of them than you think.  And it generally doesn't take much for them to choose a victim—more than anything, they like a good opportunity and an easy target.  You don't want them knowing too much about you, especially if you are of a vulnerable demographic (i.e. female or a young person/minor).

This is why I'm so hesitant to give out information as insignificant as my first name, or even friend people on Facebook.  It's not that I believe everyone is a violent criminal/sexual predator; it's that I know these people exist and a lot of times they look and behave like normal, kind people.  There's no clear way to tell the difference, so we all need to be cautious as well as courteous and respecting of others' privacy.

4) Don't let someone bully you.

Extending from my last point, if someone is pushing you to give them personal information or access, you'd be wise to have little to do with them.  Again, this doesn't automatically mean they're rapists or murderers, but they're bullies and you really don't know what they want, so you'd be best off staying away from them.

On forums or any other website where discussions can be had through comments or posts, if someone is pushing you or someone else around, be assertive, but still courteous.  It's okay to defend yourself or someone else.  But these online instigators (sometimes called "trolls") love a good fight, and so responding furiously, calling them names and making generalizations, etc. is exactly the kind of response they want from you.  That way, they can either make you look bad or they can enjoy the thrill of the argument (yes, some people get a thrill out of this).  Don't feed the trolls.  Stick up for yourself, and do the same for others, but be responsible and mature.  It's far easier said than done, but it's worth it.

Finally, if this person continues to bother you, you can always leave.  Unlike real-life situations, the anonymity and geographic differences allow you to simply "walk away" from an argument.  Again, sometimes easier said than done, but online fights ruin everyone's day (except for the trolls'; their days are usually pretty crappy anyway—that's why they do this).  Don't let them ruin yours.

5) You'll probably be infected by malware at some point.

It doesn't matter how careful you are, what antivirus you have, or whether or not you use a Mac.  If you use an Internet-connected computer long enough, you'll be infected by something.  Usually, it happens right under your nose.  You don't have to download anything, open any weird attachments or click "yes" on any suspicious dialog boxes.  If that was the only way malware could get onto your machine, it wouldn't be so rampant.  Hackers know how to download malware silently, so your best bet is to follow a few rules:

        1) Be vigilant.  Always.  Get to know how your computer runs normally so you can pick up suspicious activity.
        2) Download antivirus/antimalware.  In fact, download a couple of programs—it's always good to have a second pair of eyes watching.  (Just make sure the programs are compatible with each other.)
        3) If your computer begins behaving strangely and you think your programs may be missing something, it doesn't hurt to do a third-party scan.  I'd suggest HitmanPro (sorry Mac users; it's not available for OSX yet).
        4) Most importantly, don't assume you're safe.  A lot of people—amateurs and tech geeks alike—allow their egos get in the way of their safety.  You probably use your computer for very important things and send very important information through it.  Hackers like to be one step ahead of everyone else, and a lot of them play the game quite well.  Cybercrime is evolving as quickly as any other facet of technology.  It's up to you to make sure you don't fall behind.

Again, just a general list.  If you have any other important points you'd like to share, be my guest and post a comment below.  :-)

Monday, September 9, 2013

The Security of the iPhone 5s

Hi everyone,

Yes, this blog has been all but dead for a long time.  I just started senior year a few weeks ago and I've given myself a rather heavy workload for this year.  In addition, I'm looking to do something extra-curricular—either join a choir, volunteer, or both.  So blogging hasn't exactly been on my mind lately, but I'm back now.  ;-)

But anyway.  Whether you're an Apple fanatic, a techie in general, or just somebody who enjoys their iPhone, you probably know that some pretty cool Apple stuff is around the corner.  Among this "stuff" is the new iPhone, likely to be called the 5s, and a supposedly "low-budget" iPhone, the 5C.

As a techie teenager in a high-tech society, it is with much regret that I say I have never owned a smartphone (my parents aren't quite as technologically enthusiastic as I am).  However, seeing that I'll be moving away in less than a year, my parents have decided that it's finally time for the family to update its cellular communications.  Since I'm hoping to use my first phone for a good long while, I'm inclined to splurge for the iPhone 5s, despite the notorious prices of a brand new model.  However, regardless of which one you're interested in, you should know that rumor has it that both models will be announced TOMORROW, Sept. 10.  If so, they should become available later this month.  (The new Amnesia game comes out tomorrow as well, but I digress.)

The Security of the iPhone 5s

Of course, security was the first thing on my mind when I started browsing the smartphone market.  The iPhone initially popped into my head not because I believe Apple products are invincible (most security enthusiasts don't), but because of some of the security features you see with iPhones that you don't see with, for example, Mac computers.  However, things are changing for the iPhone as well, both for better and for worse, and it looks like I'm going to have to do some thinking before I finally make my purchase.  You should as well.

1) App Store Security—Does it Really Work?

This used to be a big thing for Apple in terms of mobile security.  Apple keeps a tight grip on what apps are allowed to be published in the App Store, which at first glance looks great.  And in most cases, its stringent rules prevent malicious apps from being published.  However, recently, a group of researchers from Georgia Tech managed to sneak a very malicious program into the App store, past all of Apple's security checkpoints, and get it published, where it can be downloaded onto any iPhone or iPad.  (Full details on the story here.)

So, in short, the concept of the App Store is very attractive.  However, as the Jekyll app showed us, nothing is fool-proof, and so your best bet is to have multiple levels of defense.  That means antimalware, which sadly does not yet exist for the iPhone.  (Maybe we'll start to see a change now...?)

2) Remote Locking

A lot of smartphones have this, but it's worth mentioning.  If your phone is ever stolen, you can log into a separate, online account and lock it down.  This prevents thieves from accessing your information, altering or damaging it, or selling your phone to someone else.  The iPhone 5s will have this, which is a plus, but doesn't really help it to stand out among the sea of mobile devices that are available nowadays.

3) The iPhone 5s Fingerprint Sensor

Here's something Apple can really brag about.  First of all, it's just cool.  To some, it may even seem like something out of a sci-fi movie.  Secondly, if they could figure out how to use a fingerprint sensor to authorize online transactions (such as PayPal), it would be a huge leap forward in the payment security sphere.  For now, it's only to authorize an iPhone user's ID, but that's still pretty cool.  I personally would feel comfortable with both a password and a fingerprint sensor, but not everyone is that paranoid concerned.

4) Definitely Needs Antimalware

As someone who will also be in the market for a new laptop in the next several months, I'm very happy to say that major AV companies (such as Avast and ESET) now have products for Mac computers.  They defend against both OSX and Windows malware, which is awesome.

Of course, the surge of Mac AV was undoubtedly brought forth by some of the malicious programs and outbreaks Apple has had to deal with in the last couple of years (i.e. Mac Defender, Flashback, and a hack attack on Apple itself from earlier this year).  So one could only hope that the latest Jekyll incident would trigger some new releases.  Let's keep our fingers crossed...

Bottom line: the new iPhones are probably going to be cool, fun toys to play with, and the 5s at least will be boasting some cool new security features.  However, it is of critical importance that some safety net be created, as nothing, not even a carefully-guarded App Store, is completely safe from hackers.  Still, in the coming months it will be important to keep up-to-date on your tech news and the latest iPhone reviews.  The up and coming releases are a big deal for Apple and the mobile world in general, and it'll be interesting to see how everything plays out.