-
-
Save gnyman/233af222cb20f34770305aebb73ce786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# Get the filename from the command line argument | |
filename = sys.argv[1] | |
# Open the file and read its contents | |
with open(filename) as f: | |
data = f.read() | |
# Define a function to find the packet start | |
def find_packet_start(data): | |
# Initialize the window of four characters | |
window = ["", "", "", ""] | |
# Process each character in the data | |
for i, c in enumerate(data): | |
# Shift the window to the left and add the new character to the right | |
window = [window[1], window[2], window[3], c] | |
# Check if the four characters in the window are all different | |
if len(set(window)) == 4: | |
# Return the number of characters processed so far | |
return i + 1 | |
# Find the packet start and print the result | |
result = find_packet_start(data) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment