Sunday, October 13, 2019

Tips for Cybersecurity Students using Python for the First Time

I'm currently doing a Master's in Cybersecurity and one of the class projects use Python to learn more about Cryptography focused around simple implementations of RSA. So for my fellow peers who have never worked with Python before here are my pointers. 

This is most relevant for people enrolled in Georgia Tech's CSC 6035 course and working on the Cryptography project.

1) Depending on your OS you may already have a version of Python installed. This can be dangerous as some Python 2 syntax is not compatible with Python 3. To avoid needless headache type into the command line:
python --version
If it does not report Python 3.x.x. Go and install it. I can't speak for other OSes but for Linux Python 2 & Python 3 can be installed side-by-side with the caveat being I have to explicitly use python3 to run my code.

See the output of my system:
kinman@yoga-linux:~$ python --version
Python 2.7.15+
kinman@yoga-linux:~$ python3 --version
Python 3.6.8
2) To edit the code you will want to use an Integrated Development Environment (IDE). Two popular ones for Python are:

VSCode by Microsoft:
PyCharm by JetBrain:

Both run on all the popular OS platforms and have great online support. I personally use VSCode. VSCode is designed for many different programming languages and you will need to install the Python Extension: to enable great features like syntax highlighting and autocomplete. PyCharm is specifically for Python and is ready to use out of the box.

3) Print statements are your friend, especially for this project. Here are some common uses, lets us use var and var 2 as the variable we want to print out:

var = 123
var2 = 321

# Will print out: 123

print("The value of var: ", var) 
# Will print out: The value of var: 123
If you want to get fancy, use {} as a placeholder in your string
print("The value of var is {}. Isn't this awesome".format(var)) 
# Will print out: The value of var is 123. Isn't this awesome

print("The value of var is {} and var2 is {}".format(var, var2))
# Will print out: The value of var is 123 and var2 is 321

# For Python 3.6 and newer you can use this syntax. Note the addition of the f before the quotes
print(f"The value of var is {var} and var2 is {var2}")

To add a new line within your print statement use, which could be helpful when you want to compare your variable lengths ;-)
# Will print out:
4) The range() function is very useful. See:
for i in range(1, 5):

# Will print out:
To print out odd numbers:
for i in range(1, 5, 2):

# This will print out:
5) Last tip to run a specific function of the unit test, instead of every test use this command
python3 <unit test file> <class of function>.<function name>
python3 TestCryptoProject.test_task_3

1 comment:

  1. It allows you to monitor all of the major social media platforms. The good thing is that you can check call logs, location of the phone and the web search history. how to spy on iphone without access to phone