Welcome to Chapter 02 of my learning journey through scripting and offensive security.
Iโm not just learning to code โ Iโm learning to build, document, and explain.
This series is based on Hacking with Go, but reimagined in Ruby and Swift, with step-by-step examples and real-world analogies to help anyone understand โ even if youโve never written a single line of code.
๐งฑ What weโll cover in this chapter:
- ๐ฆ Variables (how to store information)
- ๐ Loops (how to repeat actions)
- ๐ Conditionals (how to make decisions)
- ๐ง Functions (how to reuse logic)
- ๐ฌ Input/Output (how to talk to the user)
๐ก Variables โ Giving names to values
name = "Alice"age = 30
๐ง Explanation
Weโre storing data in memory using variables.
-
nameholds the string"Alice" -
ageholds the number30
Think of variables like stickers you put on boxes โ the name tells you whatโs inside.
๐ Loops โ Repeating things automatically
3.times do puts "Knock knock!"end
๐ง Explanation
-
3.timesruns the block three times -
putsprints the message
This is like telling a kid: โSay โknock knock!โ three timesโ โ and theyโll do it without question.
๐ Conditionals โ Making decisions
password = "swordfish"if password == "swordfish" puts "Access granted!"else puts "Access denied!"end
๐ง Explanation
We check a condition:
If the password matches, we let the person in. Otherwise, we block them.
Itโs like checking someoneโs ID before opening the door.
๐ง Methods โ Reusable blocks of logic
def greet(name)
"Hello, #{name}!"endputs greet("Alice")
๐ง Explanation
Weโre defining a method (like a mini-program) that:
- Takes one input:
name - Returns a message using string interpolation
Calling greet("Alice") is like pushing a button labeled โSay hello to Alice.โ
๐ฌ User Input โ Interacting with people
print "What's your name? "name = gets.chompputs "Welcome, #{name}!"
๐ง Explanation
-
printshows a prompt without a newline -
getswaits for input from the user -
chompremoves the trailing newline
This is how Ruby talks to the user โ and listens back.
๐ง Final Recap
๐ฆ Variables โ Store information with names
๐ Loops โ Repeat things automatically
๐ Conditionals โ Make decisions
๐ง Methods โ Reuse blocks of logic
๐ฌ Input/Output โ Talk to the user
โ Youโve learned the building blocks
This chapter gave you everything you need to start writing real scripts.
Next up: weโll dive into useful packages and Ruby gems to do powerful things like parsing files, automating tasks, and working with the web.
๐ซ About the Author
[Jรบnior Carreiro]
๐ Mobile AppSec | iOS Security | Reverse Engineering
๐ Let's connect: [GitHub] ยท [Linkedin]
Top comments (0)