Cybersecurity Basics & Python
Page 1: Security mindset
Cybersecurity protects devices, accounts, applications, and information. Practice only in
systems you own or are authorized to test.
Code example
import hashlib
print(hashlib.sha256(b'example').hexdigest())
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 2: Passwords and MFA
Use unique passwords and multi-factor authentication. A password manager helps avoid reuse.
Code example
import secrets
print(secrets.token_hex(16))
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 3: Hashing and integrity
Cryptographic hashes can help verify whether data changed.
Code example
import hashlib
print(hashlib.sha256(b'data').hexdigest())
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 4: Input validation
Applications should validate type, length, format, and allowed values.
Code example
x=input('Value: ').strip()
if not x: raise ValueError('Empty input')
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 5: Safe logging
Logs should help diagnosis without exposing passwords, tokens, or unnecessary private
information.
Code example
import logging
[Link](level=[Link])
[Link]('Started')
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 6: Network concepts
Learn DNS, IP addresses, ports, HTTPS, and certificates in safe laboratories.
Code example
import socket
print([Link]())
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 7: File permissions
Restrict sensitive files to users and applications that actually need access.
Code example
from pathlib import Path
print(Path('[Link]').exists())
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 8: Backups
Regular protected backups reduce the impact of accidental deletion and ransomware.
Code example
from pathlib import Path
Path('[Link]').write_text('backup copy')
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 9: Incident response
When compromise is suspected, secure accounts from a trusted device and preserve useful
evidence.
Code example
event={'type':'login','status':'review'}
print(event)
Practice note: use these examples for learning in environments you own or are authorized to
manage.
Cybersecurity Basics & Python
Page 10: Defensive project
Build a local file-integrity checker that calculates hashes for files you own.
Code example
from pathlib import Path
import hashlib
print(hashlib.sha256(Path('[Link]').read_bytes()).hexdigest())
Practice note: use these examples for learning in environments you own or are authorized to
manage.