Windows UsersInstalling PythonFollow these instructions to install Python 2.7:https://samsclass.info/124/proj14/python2.7-win.htm Creating a Python ProgramFrom your desktop, click Start and type CMD.Right-click "Command Prompt" and click "Run as Administrator". If a User Account Control box pops up, click Yes. In the Administrator Command Prompt window, execute these commands, as shown below.
A box pops up asking "Do you want to create
a new file?". Click Yes.
In Notepad, enter this code, as shown below.
In Notepad, click File, Save to save the file. Running the Python ProgramIn the Command Prompt, execute this command, as shown below.
The program runs, printing out
"Hello, World!",
as shown below.
|
Mac or Linux UsersCreating a Python FileOpen a Terminal window and execute this command, as shown below.
In nano, enter this code,
as shown below.
Press Ctrl+X, Y, Enter to save the file. Running the Python FileIn the Terminal window, execute this command, as shown below.
The program runs, printing out
"Hello, World!",
as shown below.
If this fails, because you are running Python 3, try this command line instead:
|
greet = "Hello, World!"
print greet
print "Start: ", greet[0:3]
print "Middle: ", greet[3:6]
print "End: ", greet[-3:]
a = greet.find(",")
print "Portion before comma", greet[:a]
Run the program, as shown below.
Examine the output to make sure you understand how to cut out portions of a string, and how to find substrings within a string,
import socket
s = socket.socket()
s.connect(("ad.samsclass.info", 10101))
print s.recv(1024)
s.send("Hello from Python!\n")
print s.recv(1024)
s.close()
Run the program, as shown below. It sends the string "Hello from Python!" to the server, which echoes it back.
Explanation
import socket import the "socket" library, which contains networking functions s = socket.socket() create a socket object named "s" s.connect(("ad.samsclass.info", 10101)) connect to the server "ad.samsclass.info" on port 10101 s.recv(1024) receive data from the server, up to a maximum of 1024 characters s.send("Hello from Python!\n") send data to the server s.close() close the connection and destroy the "s" object
Send it the string "Goodbye".
When you do, you will receive a flag, covered by a green box in the image below.
Enter the flag into the form below to put your name on the WINNERS PAGE!
Troubleshooting
If a service is unresponsive on my server, try adding 10 or 20 to the port number.There are three copies of each service running:
- Task 3: Echo -- ports 10101, 10111, 10121
- Challenge 1: Goodbye -- ports 10102, 10112, 10122
- Challenge 2: Increment -- ports 10103, 10113, 10123
- Challenge 4: Add and Subtract -- ports 10104, 10114, 10124
It sends you a number. Add one to that number and send it to the server.
When you do, you will receive a flag, covered by a green box in the image below.
Enter the flag into the form below to put your name on the WINNERS PAGE!
Hint
Integers and strings are different data types in Python.You can convert items back and forth with the int() and str() functions, as shown below.
Combine two numbers as required and send the result. You have to get all five answers correct within five seconds to get the flag, covered by a green box in the image below.
Enter the flag into the form below to put your name on the WINNERS PAGE!
Leetspeak typo fixed, additional ports added 10-18-18
/usr/bin/python Mac tip added, thanks to a @hackvalley27 participant 10-21-18