r/AskProgramming • • Oct 10 '26

Architecture Theoretically, could you make a virus that evolves under evolutionary principles?

The most basic part of evolution is, simplified:

- shit reproduces
- there is a random chance of mutation
- mutations more advantageous in the environment spread.

So in theory, could you create a computer virus that function under the same principles as an actual virus? Have it so that every time it reproduces, it makes a new copy of itself there’s a random chance to make random changes to its own code? Most of the time it would result in the virus breaking, but that’s also true for IRL.

7 Upvotes

29 comments sorted by

11

u/sock_dgram Oct 10 '26

It's called an "Evolutionary Algorithm."

-5

u/eeeeeeevar Oct 10 '26

Not like that. I mean every single time it reproduces the court code itself can be changed. On the level of changes that it could by chance turn off its ability to modify itself.

11

u/sock_dgram Oct 10 '26 edited Oct 10 '26

Still the same type of algorithm. Just let the program itself copy itself with randomly modified instructions.

You won't have much success though. It will fail almost always after the first modification. That's why real viruses don't mutate on every transmission, but only sometimes. And somewhat targeted, which brings us back to evolutionary algorithms.

Let's say you want to evolve to have a lot of neighbors in a network. You want to know that, so you can't evolve the reporting part of the code. And you want them to replicate, so you can't modify the replication code itself.

1

u/edgmnt_net Oct 10 '26

If the parameter space is raw instructions, yeah, although it might work better with a different parameter space. Could be something like tunables (e.g. how aggressively the virus looks for other executables) or perhaps (part of) a higher-level representation of its own code that gets translated back into machine code in a more rigorous way.

1

u/sock_dgram Oct 10 '26

If I'd be interesting in writing an experimental virus, I'd be interested in the routers Iran uses.

They can't sue.

-3

u/eeeeeeevar Oct 10 '26

Like real viruses 99% of the time mutation would just kill it one percent of the time we do nothing and 0.01% of the time it would be useful

2

u/sock_dgram Oct 10 '26

How would you modify a software virus?
You can't recompile it, or at least not on all machines, so let's ignore this.

So you'd have to set parameters to tune from the start. Which ones?

-1

u/eeeeeeevar Oct 10 '26

I don’t know I’m stupid and don’t really know how computers work. I’m just imagining something like.
- before you copy code check each character of the entire code base and for each one roll a one in 10,000 chance
- if it lands on one, change it to a random character, delete the character, add a character or copy the character

8

u/sock_dgram Oct 10 '26

Like I said. An evolutionary algorithm. Maybe not even that. Just random locally.

It's not a stupid idea at all, but it has existed since the first computer virus like 50 years ago.

4

u/KingofGamesYami Oct 10 '26

That's one of the major known strategies for producing machine learning algorithms, pioneered in theory around 1950, with the first practical implementation emerging in 1981. There was also a surge of interest in this field from 2012-2018.

3

u/Different_Pain5781 Oct 10 '26

Funny how evolution works outside biology too.

0

u/Human38562 Oct 10 '26 edited Oct 26 '26

The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.

Boat correct beneficial piquant school school

2

u/cipheron Oct 10 '26 edited Oct 10 '26

They were taling about Genetic algorithms.

In those, all changes to the potential solutions are in fact random, in a process analogous to mutation. The non-random part is the selection criteria, basically you need some function that can rank possible solutions, which is analogous to the selection step from evolution.

0

u/Human38562 Oct 10 '26 edited Oct 26 '26

The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.

Juggle sophisticated hydrogen society smart hurry quickest dolls liquid

1

u/wonkey_monkey Oct 12 '26

The author used Redact to remove it, exercising their right to control their data & privacy.

"Interesting. Yes that would already be closer to what OP is asking than general machine learning, although it still lacks reproduction and spreading mechanisms."

So much for that... https://ihsoyct.github.io/

1

u/Human38562 Oct 12 '26 edited Oct 26 '26

The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.

Offer cobalt pot ink capable cooing attempt pet employ

1

u/RealNamek Oct 10 '26

Yes, they have done this before. Not just as a virus, because that makes no money, content is made this way. You think every reddit article, comment section, youtube feed is exactly the same for everyone? What do you think FOR YOU means, it's literally an evolutionary alogirthm to feed you exactly what you want, at all times.

1

u/mochsner Oct 10 '26

Haha some more advanced phishing attempts may work this way too

1

u/drbomb Oct 10 '26

Evolution is not about randomness but selection of beneficial traits.

1

u/LokiAstaris Oct 12 '26

Yes, but one of the major theories of evolution is "Natural Selection", where the mechanism for change is random genetic mutations, which are then selected by environmental pressure.

1

u/SnugglyCoderGuy Oct 10 '26

Yes, but the chances of it not fizzling out almost immediately is next to zero.

Biological viruses have millions and trillions of chances of reproduction because the act on individual cells of any given organism, and there could be millions or billions of organisms it is acting upon.

There is also a humongous margin of error when it comes to DNA/RNA mutations versus mutations in code. One bit off and everything goes to shit. One different in nucleac pair could end up being completely benign. Most DNA is 'junk'.

1

u/owp4dd1w5a0a Oct 10 '26

Yes. And I think using genetic algorithms in a lisp language where the evolutionary algorithms involved (re)write and inject their own code would be incredibly interesting. In fact, this has been done and the most interesting form is called “autoconstructive evolution”.

https://dl.acm.org/doi/10.1023/A:1014538503543

1

u/Savings-Cry-3201 Oct 10 '26

The earliest one I’m thinking of was back in the 40hex days where one of the viruses highlighted would remix its code and add random bytes in while modifying its jump codes to dodge the random bits. That’s less of an evolution and more polymorphism. It was cool af though, an early method of trying to avoid antivirus heuristics.

The chance of adding random opcodes and generating something useful is incredibly small. Actual viruses replicate in the trillions and they simply have a bigger space to play in.

0

u/SgtSausage Oct 10 '26

LOL.

You've never written a line of code in your life. hava ya, Scooter. 

-1

u/Worth-Wonder-7386 Oct 10 '26

In theory yes. The problem is that evolution is very slow and you need a good basis. And it would be hard to link the performane to the spread. Remember that real life viruses are selected for their own survival, not to perform some other goal.

And for viruss they have way more cells to try on than there are computers you get access to. but there are evolution based programs that you can run to try to optimize how a virus would work.

-1

u/Temporary_Pie2733 Oct 10 '26

Not just in theory; it’s been done in practice.

https://kk.org/mt-files/outofcontrol/ch15-a.html

2

u/sock_dgram Oct 10 '26

But it doesn't scale if every instance is searching without knowledge of the other ones. Not anymore.

-1

u/BoBoBearDev Oct 10 '26 edited Oct 10 '26

Yeah, maybe, but such ingenious virus probably takes 8GB of RAM and I only have 8GB of RAM. The software has to be so smart to write code, like a mini ChatGPT. Otherwise your mutation is so limited, it is not mutating in any meaningful sense.