Slove a malware challenge | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

Slove a malware challenge

Write s python program to do this task: Your company is analyzing malware which targets numerical record files. The malware uses a sliding window over the array of numbers in a file, and tries to match the following | T1, -, -, X, -, -, Tr The entire window is moved so that 'X' passes through all the values and is compared to the numbers at and 'Tr' locations, which are positioned at a constant offset to 'X'. The malware has the following rules: • If the value at the 'TI' or 'Tr' position of the pattern is bigger or equal to the value at the 'X' position, th malware replaces the value at 'X' with 0. • If the value at the 'TI' or 'Tr' offset is out of bounds, then the value at 'X' is only compared to the other existing value. • The record is processed in two stages: first, all the positions that should be set to 0 are located, usin original values for comparison. Only after all positions have been identified do they get set to 0. For example, if the values in a record file are the following: [1, 2, 0, 5, 0, 2,

30th Mar 2024, 11:50 AM
Mohammed Hassan
Mohammed Hassan - avatar
54 Antworten
+ 2
Mohammed Hassan , By the way, the algorithm in that puzzle is similar to the filters used in graphics, such as a smoothing algorithm, where you use the values of surrounding pixels to set the value of the center pixel.
31st Mar 2024, 3:15 PM
Rain
Rain - avatar
+ 4
Per Bratthammar Keith Rain How can we solve this challenge because i really don't get the full meaning?
30th Mar 2024, 11:51 AM
Mohammed Hassan
Mohammed Hassan - avatar
+ 3
Do you have full description as well as input outpt examples?
30th Mar 2024, 3:13 PM
JaScript
JaScript - avatar
+ 3
Per Bratthammar the i dea is simple just to compare the value of position x to T1,Tr if T,Tr >=X should X=0,else make compare for other positions with X position value. But the point which i not get it is in this Example : [1, 2, 0, 5, 0, 2, 4, 3, 3, 3] The expected values after the malware runs are: [1, 0, 0, 5, 0, 0, 0, 3, 3, 0] Why the last 3 in the list became 0 only . While other 3 not compare to value of position x
30th Mar 2024, 3:52 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
Per Bratthammar this task looks like esay but needs more explanation ,i search on YouTube but idont find any thing usfull
30th Mar 2024, 12:45 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
@ T1,Tr Refer as locations in list U must compare the the value of x position to T1,Tr
30th Mar 2024, 12:48 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
Rain i already past the whole information for task no missing point
30th Mar 2024, 3:45 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
Mohammed Hassan , At the bottom, it says, "For example," and starts to give a list. The list is cut off in the middle, and the rest of the directions are missing.
30th Mar 2024, 3:50 PM
Rain
Rain - avatar
+ 2
Mohammed Hassan , OK. I solved it by adding 10 lines to the starting code supplied by the test site, so I can now help you. What have you tried so far?
30th Mar 2024, 9:21 PM
Rain
Rain - avatar
+ 2
Mohammed Hassan , I already explained why the last 3 changed to 0 yesterday: "The last 3 is set to 0 because, when X is on the 3, T1 is on a 4, and 4 is greater than or equal to 3." Tr represents 4 steps right of X. X represents every index in the list one by one. The other two are always relative to X. If either of the other two is outside the list, it is ignored. CheatGPT doesn't think, and it has no concept of what a fact is. It's just an algorithm to generate imitation human text. People shouldn't expect so much from it.
31st Mar 2024, 2:57 PM
Rain
Rain - avatar
+ 2
The malware analysis can be got for example in this way: https://sololearn.com/compiler-playground/cs829PDqAbrK/?ref=app
1st Apr 2024, 8:44 AM
JaScript
JaScript - avatar
+ 2
Mohammed Hassan , Be sure to save and share a link to your final code when you pass the test.
3rd Apr 2024, 3:22 AM
Rain
Rain - avatar
+ 2
Rain JaScript I finally seccssfully done the code here my Method. To be honest this challenge require more aware about different python functions like to be esay to you https://sololearn.com/compiler-playground/cJZoFYaYJ3Pj/?ref=app
3rd Apr 2024, 7:27 AM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
Mohammed Hassan Congratulations.
3rd Apr 2024, 10:42 AM
JaScript
JaScript - avatar
+ 2
Mohammed Hassan , Ah, you used enumerate(). 👍 I will give a speed-optimization suggestion in a comment attached to your code.
3rd Apr 2024, 2:59 PM
Rain
Rain - avatar
+ 2
Rain JaScript The secret key to win a code challenge is Great knowledge about useful python libraries & funcation which we can get it from References
3rd Apr 2024, 3:17 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 2
Rain 😂😂😂 Not fully 3 days but we are busy with another activities (iam study for data analyst with python)
3rd Apr 2024, 3:20 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 1
Rain For example: [1, 2, 0, 5, 0, 2, 4, 3, 3, 3 ] The expected values after the malware runs are: [1, 0, 0, 5, 0, 0, 0, 3, 3, 0]
30th Mar 2024, 3:53 PM
Mohammed Hassan
Mohammed Hassan - avatar
+ 1
Mohammed Hassan , The last 3 is set to 0 because, when X is on the 3, T1 is on a 4, and 4 is greater than or equal to 3. But I don't know why the first 1 in the list is not set to 0, because when X is on the 1, Tr is on a 5, and 5 is greater than or equal to 1, so 1 should have been set to 0. I don't know why the first 2 in the list is set to 0, because when the X is on that 2, Tr is on a 0, and 0 is not greater than or equal to 2, so 2 should not have been set to 0. Maybe the spacing should be T1, _, _, X, _, _, _, Tr not symmetrical. I need to see the original site. Maybe it's a typo. No link? Was this translated by optical character recognition (OCR) at some pont? I suspect that T1 was actually Tl, with a lowercase L for left, to match the lowercase r for right in Tr. Also, many sentences are missing text, as if the OCR missed the edges of the page. The directions are basically wrecked, which makes it hard to help with.
30th Mar 2024, 4:45 PM
Rain
Rain - avatar
+ 1
def find_matching_indices(arr, T1, Tr, window_size): # Initialize an empty list to store the indices that match the pattern matching_indices = [] # Iterate through the array with a sliding window of the given size for i in range(len(arr) - window_size + 1): window = arr[i : i + window_size] X = window[1] T1_val = window[T1] Tr_val = window[Tr] # Check if the value at T1 or Tr is bigger than or equal to the value at X if T1_val >= X or Tr_val >= X: # If either T1 or Tr is out of bounds, check if the value at X is 0 if T1 >= window_size or Tr >= window_size: if X == 0: matching_indices.append(i) else: # If T1 and Tr are in bounds, check if they are both bigger than or equal to X if T1_val >= X and Tr_val >= X: matching_indices.append(i) return matching_indices def set_values_to_zero(arr, indices): # Iterate through the array and set the values at the given indices to 0 for i in indices: arr[i] = 0 def process_record_file(arr, T1, Tr, window_size): # Find the indices that match the pattern indices = find_matching_indices(arr, T1, Tr, window_size) # Set the values at the matching indices to 0 set_values_to_zero(arr, indices) # Example usage: arr = [1, 2, 0, 5, 0, 2] T1 = 0 Tr = 4 window_size = 7 process_record_file(arr, T1, Tr, window_size) print(arr) # Output: [0, 2, 0, 0, 0, 0] This could possibly answer that
30th Mar 2024, 6:38 PM
Alexa Perez
Alexa Perez - avatar