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
kinman@yoga-linux:~$ 
2) To edit the code you will want to use an Integrated Development Environment (IDE). Two popular ones for Python are:

VSCode by Microsoft: https://code.visualstudio.com/
PyCharm by JetBrain: https://www.jetbrains.com/pycharm/

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: https://marketplace.visualstudio.com/items?itemName=ms-python.python 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

print(var) 
# 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 ;-)
print("var:\n{}".format(var))
print("var2:\n{}".format(var2))
# Will print out:
var:
123
var2:
321
4) The range() function is very useful. See: https://docs.python.org/3/library/functions.html#func-range
for i in range(1, 5):
    print(i)

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

# This will print out:
1
3
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 test_crypto_proj_1.py TestCryptoProject.test_task_3

Comments

Popular posts from this blog

Apple Pay, Android Pay, contactless credit cards, is it safe?

How Salesforce uses AWS to Improve The Support Call Experience

Failed CUDA Toolkit Install? Ubuntu 18.04 stuck on boot of Gnome Display Manager?