Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Foundations [Lect 1b: Competitive Cybers...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Python Foundations [Lect 1b: Competitive Cybersecurity 101]

Python is the undisputed industry standard for cybersecurity professionals, offering rapid prototyping, rich library support, and readable syntax essential for automating security tasks. This presentation constitutes Session 1 of the "Competitive Cybersecurity 101" series, bridging the gap between fundamental programming concepts and their direct application in Capture The Flag (CTF) competitions.

Moving beyond generic programming tutorials, this deck focuses exclusively on the data structures and operations most frequently encountered in cybersecurity challenges. Participants are guided through string manipulation, ASCII/Unicode translation, and the critical distinction between encoding (Hex, Base64) and encryption. The session culminates in a practical mini-challenge, requiring students to apply control flow and file I/O operations to programmatically extract and decode hidden flags, establishing the automation mindset required for advanced competitive informatics.

Avatar for Kannan Murugapandian

Kannan Murugapandian

July 24, 2026

More Decks by Kannan Murugapandian

Other Decks in Education

Transcript

  1. Competitive Cybersecurity 101 Session 1: Python Foundations for CTF Kannan

    Murugapandian July 10, 2026 Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 1 / 15
  2. Disclaimer & Ethical Rules Strictly for Educational Purposes All knowledge

    and tools must only be applied in environments where you have explicit permission. Do not test on systems you do not personally own or lack authorization to assess. Unauthorized access constitutes a criminal offense under the Computer Misuse Act. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 2 / 15
  3. Why Python for CTF? Industry Standard: Most widely used language

    in cybersecurity. Rapid Prototyping: Write and test exploits quickly. Rich Libraries: Built-in support for networking, cryptography, and data manipulation. Readable Syntax: Focus on logic, not complex syntax. CTF Essential: Required for scripting challenges and automation. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 3 / 15
  4. Python Data Types & Variables Primitive Types: int: Whole numbers

    (e.g., 42, -7) float: Decimal numbers (e.g., 3.14) bool: Logical values (True, False) str: Text (e.g., “flag”) Variables & Naming: Store data in memory using lowercase words separated by underscores. flag = " CTF { example } " port_number = 80 is_admin = True Note: In Python, = means assignment, not mathematical equivalence! Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 4 / 15
  5. Operators Arithmetic: + - * / (Standard math) // (Floor

    division: rounds down) % (Modulo: remainder) ** (Power) Examples: print (11 // 3) print (11 % 3) print (2 ** 3) Kannan Murugapandian # Floor division -> 3 # Modulo ( remainder ) -> 2 # Power (2^3) -> 8 Competitive Cybersecurity 101 July 10, 2026 5 / 15
  6. Strings: The CTF Workhorse Strings are sequences of characters. We

    can access them using indexing. s = " CTF " print ( s [0]) # Output : ’C ’ ( First character ) print ( s [ -1]) # Output : ’F ’ ( Last character ) Unicode/ASCII Values: Crucial for cryptography and shifting characters! print ( ord ( ’A ’) ) # Get ASCII number -> 65 print ( chr (65) ) # Get character from number -> ’A ’ Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 6 / 15
  7. What is Encoding? (Hex & Base64) Not Encryption! Encoding just

    changes the format of data so it can be easily read by systems. Anyone can decode it. Hexadecimal (Hex): Base-16 number system (0-9, A-F). CTF Relevance: Raw memory, network packets, or hidden files often dump data in Hex. Base64: Converts binary data into standard text characters (A-Z, a-z, 0-9, +, /). CTF Relevance: The most common way to “hide” a flag in plain sight on a webpage or in a text file. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 7 / 15
  8. Working with Hex in Python String to Hex: text =

    " flag " hex_data = text . encode () . hex () print ( hex_data ) # Output : 666 c6167 Hex to String: hex_data = " 666 c6167 " text = bytes . fromhex ( hex_data ) . decode () print ( text ) # Output : flag Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 8 / 15
  9. Working with Base64 in Python Encoding (Text to Base64): import

    base64 text = " flag " # Base64 requires bytes , so we encode first b64_data = base64 . b64encode ( text . encode () ) print ( b64_data ) # Output : b ’ ZmxhZw == ’ Decoding (Base64 to Text): b64_data = b ’ ZmxhZw == ’ text = base64 . b64decode ( b64_data ) . decode () print ( text ) # Output : flag Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 9 / 15
  10. Lists & Tuples Lists (Mutable): Ordered collections that can be

    changed. ports = [22 , 80 , 443] print ( ports [0]) # Output : 22 ports . append (8443) Tuples (Immutable): Like lists, but cannot be changed. coords = (10 , 20) # coords [0] = 5 <-- This causes a TypeError ! Slicing: Extracting parts of a sequence. data = [0 , 1 , 2 , 3 , 4 , 5] print ( data [1:4]) # Output : [1 , 2 , 3] print ( data [:: -1]) # Output : [5 , 4 , 3 , 2 , 1 , 0] Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 10 / 15
  11. Control Flow: Conditionals Make decisions in your scripts using if,

    elif, else. status = 404 if status == 200: result = " OK " elif status == 404: result = " Not Found " else : result = " Error " Truthy/Falsy: 0, "", None are False. Everything else is True. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 11 / 15
  12. Control Flow: Loops For Loop: Iterate over a sequence. for

    port in [22 , 80 , 443]: print ( f " Scanning port { port } " ) While Loop & Break: count = 0 while count < 5: if count == 3: break # Exit loop early print ( count ) count += 1 Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 12 / 15
  13. Mini Challenge: Find the Hidden Pattern Task: Write a Python

    script to find and decode a hidden flag in a file. Scenario You have a file mystery.txt containing mixed data. Hidden within is a Base64-encoded string that contains the flag. Hints: 1 Read the file line by line. 2 Look for strings that might be Base64 (often end with = or ==). 3 Try decoding candidates with base64.b64decode(). 4 Check if the decoded result contains CTF{ or flag{. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 13 / 15
  14. Key Takeaways Python is essential for CTF automation and scripting.

    Encoding vs Encryption: Hex and Base64 are just formats, not secrets! String manipulation is fundamental for decoding flags. Control flow (loops/conditionals) allows you to process data automatically. Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 14 / 15
  15. Thank You! Questions? Email: [email protected] Course Hub: kannan.bearblog.dev/ctf-dps/ Next Session:

    Python for CTF Scripting July 17, 2026 Kannan Murugapandian Competitive Cybersecurity 101 July 10, 2026 15 / 15