Skip to content

Instantly share code, notes, and snippets.

@clayball
Created September 14, 2017 15:15
Show Gist options
  • Select an option

  • Save clayball/6c92e84118636617105f21a96f4f2ecf to your computer and use it in GitHub Desktop.

Select an option

Save clayball/6c92e84118636617105f21a96f4f2ecf to your computer and use it in GitHub Desktop.
FirpBurp with Caesar
import socket
def read_caesar(r):
key = 'abcdefghijklmnopqrstuvwxyz'
result = ''
for l in r:
try:
i = (key.index(l) - 3) % 26
result += key[i]
except ValueError:
result += l
return result
HOST, PORT = "localhost", 1337
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
for i in range(1, 101):
sock.sendto(str(i) + "\n", (HOST, PORT))
response = sock.recv(1024)
print '[*] Got ' + response
if len(response) > 2:
response = read_caesar(response)
print '[*] Sent: ' + str(i) + ', Result: ' + str(response) + '\n'
import SocketServer
class FirpBurpUDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
socket = self.request[1]
do_cipher = int(0)
print "{} wrote:".format(self.client_address[0])
if int(data) % 15 == 0:
r = "FirpBurp"
do_cipher = int(1)
elif int(data) % 3 == 0:
r = "Firp"
do_cipher = int(1)
elif int(data) % 5 == 0:
r = "Burp"
do_cipher = int(1)
else: # leave room for refactoring
r = str(data)
cipher = r
print str(r)
if do_cipher == 1:
cipher = self.hail_caesar(r)
socket.sendto(str(cipher), self.client_address)
def hail_caesar(self, r):
key = 'abcdefghijklmnopqrstuvwxyz'
result = ''
for l in r.lower():
try:
j = (key.index(l) + 3) % 26
result += key[j]
except ValueError:
result += l
return result.lower()
if __name__ == "__main__":
HOST, PORT = "localhost", 1337
server = SocketServer.UDPServer((HOST, PORT), FirpBurpUDPHandler)
# Ctrl-C to stop
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment