0% found this document useful (0 votes)
6 views5 pages

Simulation

The document contains a Python simulation for a satellite communication system using AES-GCM encryption. It includes functions for encrypting and decrypting messages, simulating telemetry data transmission, and plotting battery and temperature levels over time. The simulation involves a satellite server and a ground station client that communicate securely and visualize telemetry data.

Uploaded by

mensi5092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Simulation

The document contains a Python simulation for a satellite communication system using AES-GCM encryption. It includes functions for encrypting and decrypting messages, simulating telemetry data transmission, and plotting battery and temperature levels over time. The simulation involves a satellite server and a ground station client that communicate securely and visualize telemetry data.

Uploaded by

mensi5092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Simulation

import socket

import time

import matplotlib.pyplot as plt

import numpy as np

from Crypto.Cipher import AES

from Crypto.Random import get_random_bytes

# Generate AES Key

KEY_AES = get_random_bytes(32) # 256-bit key

def generate_iv():

return get_random_bytes(12) # 12-byte IV

# Encrypt telecommand using AES-GCM

def encrypt_message(message):

iv = generate_iv()

cipher = AES.new(KEY_AES, AES.MODE_GCM, nonce=iv)

ciphertext, tag = cipher.encrypt_and_digest(message.encode())

return iv + ciphertext + tag

# Decrypt message using AES-GCM

def decrypt_message(encrypted_message):

iv = encrypted_message[:12]

ciphertext = encrypted_message[12:-16]

tag = encrypted_message[-16:]

cipher = AES.new(KEY_AES, AES.MODE_GCM, nonce=iv)

try:

decrypted_data = cipher.decrypt_and_verify(ciphertext, tag)

return decrypted_data.decode()
except ValueError:

return "ERROR: Data integrity compromised!"

# Satellite (Server)

def satellite():

try:

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind(('127.0.0.1', 5555)) # Use 127.0.0.1 instead of 'localhost'

server.listen(1)

print("[SATELLITE] Ready to receive commands...")

except OSError as e:

print(f"[ERROR] Failed to start server: {e}")

return

conn, addr = server.accept()

print(f"[SATELLITE] Connected to ground station {addr}")

data = conn.recv(1024)

if data:

command = decrypt_message(data)

print(f"[SATELLITE] Received Command: {command}")

# Simulate telemetry response

battery_levels = np.linspace(100, 80, 10) # Simulated battery drain

temperature_levels = np.linspace(20, 25, 10) # Simulated


temperature rise

telemetry_data = []

for battery, temp in zip(battery_levels, temperature_levels):


telemetry = f"Telemetry: Battery {battery:.1f}%, Temp:
{temp:.1f}°C"

encrypted_telemetry = encrypt_message(telemetry)

conn.sendall(encrypted_telemetry)

telemetry_data.append((battery, temp))

time.sleep(0.5) # Simulate delay

print("[SATELLITE] Sent encrypted telemetry.")

conn.close()

server.close()

return telemetry_data

# Ground Station (Client)

def ground_station():

time.sleep(1) # Ensure server starts first

try:

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

client.connect(('127.0.0.1', 5555)) # Use 127.0.0.1 instead of


'localhost'

print("[GROUND STATION] Connected to satellite.")

except OSError as e:

print(f"[ERROR] Failed to connect to satellite: {e}")

return

# Send encrypted command

command = "Activate camera"

encrypted_command = encrypt_message(command)

client.sendall(encrypted_command)

print("[GROUND STATION] Sent encrypted command.")


battery_data = []

temp_data = []

# Receive encrypted telemetry

for _ in range(10):

data = client.recv(1024)

telemetry = decrypt_message(data)

print(f"[GROUND STATION] Received Telemetry: {telemetry}")

# Extract telemetry values for plotting

parts = telemetry.split(', ')

battery = float(parts[0].split(' ')[1].strip('%'))

temp = float(parts[1].split(' ')[1].strip('°C'))

battery_data.append(battery)

temp_data.append(temp)

client.close()

return battery_data, temp_data

# Plot telemetry data

def plot_telemetry(battery_data, temp_data):

time_points = np.arange(len(battery_data))

plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)

plt.plot(time_points, battery_data, marker='o', linestyle='-',


color='blue')
plt.xlabel('Time Step')

plt.ylabel('Battery Level (%)')

plt.title('Battery Drain Over Time')

plt.subplot(1, 2, 2)

plt.plot(time_points, temp_data, marker='o', linestyle='-', color='red')

plt.xlabel('Time Step')

plt.ylabel('Temperature (°C)')

plt.title('Temperature Rise Over Time')

plt.tight_layout()

plt.show()

# Run simulation sequentially

if __name__ == "__main__":

telemetry_data = satellite()

battery_data, temp_data = ground_station()

plot_telemetry(battery_data, temp_data)

You might also like