How to make a virus with Python

RickA
4 min readDec 2, 2022

--

A virus which constantly makes your screen rotate, sounds difficult but it is surprisingly easy to do!

Disclaimer: this article has only educational purpose, never harm or hurt anyone! It is only to learn the components of computer science.

If you know a little bit about programming, you can explain the definition of a virus. For the ones who can’t, a short explanation: a virus is a form of software. It is a program which can in to your files and they can harm your computer, not something you want. But it is cool to make one yourself. You can annoy your friends and it can help with understanding how some parts of computer science works. Pretty interesting! So, in this article I am going to show you how to make some kind of virus.

Before we start, I already explained the meaning of a virus, but to improve your knowledge, I will inform you a little bit better about a virus and what is does and how it works. If you aren’t interested, don’t worry, just skip this part for now and maybe read it later. But anyway, let’s start with how a virus works: first, you need to get a virus to a device and there are three ways to do so. It can happen via Bluetooth, mms and the internet. The last one is logical, you download something you shouldn’t download, but you do it either way and tadaa, you device is infected with a virus. Next, Bluetooth is an option, but because it is really slow and easy to see, it is easy detectable. But if it works, the virus copies itself to the selected device. The last option is mms, which means “Multimedia Messaging Service”. If you get a video and accept it to watch the video and the file contains a virus, the virus is going to spread itself into the device. This method is the most efficient one. The last important thing to know: sharing a virus with other devices and so infecting them is a criminal offence. So, only make them to understand and learn the mechanics of viruses, this way you can protect yourself from them and you have a proper knowledge about them. Now let’s move on to the more enjoyable part, coding!

In this tutorial I will guide you through 2 steps:

  1. Installing requirement
  2. Making the code

Firstly, you need some apps and other things, but these are not so hard to get. You will need the Python app from the Microsoft Store, download it and the first step is done. Next, you need a program where you can write some code. I suggest Visual Studio Code.

Download Python via the Microsoft Store
The home screen of Visual Studio Code

One last step before you can start with coding. This virus requires some libraries and because now you have Python, it is pretty easy to download these libraries. Go to command prompt (Windows) or Terminal (Mac), there you will install 2 libraries, first typ “pip install rotate-screen”. After a small amount of time, you will get the message the library was installed succesfully. You can download the other library typing “pip install pywin32”.

How to install library rotate-screen
how to install library pywin32

Now you can finally start with coding:
First, we are going to import the libraries:

import time, rotatescreen as rs

Next:

display = rs.get_primary_display()

Then, we are making an array for the angles the screen must turn to:

listOfAngels = [90,180,270,0]

To make the screen rotate, we will need 2 for loops:

for i in range(3):

Then, go to the next line and place a tab

  for x in listOfAngels:

In the second for loop, make the following code:

    pd.rotate_to(x)
time.sleep(0.5
The code of the rotation virus

You make your own virus! There are some things can you change to what you like, the names of the variables are changable. The number of how many times the first for loop must run is also a thing you can change. Keep in mind, the number you put their, multiplied by 4 is the number of how many times your screen is going to rotated by 90 degrees. So, if you want that the screen is going to rotate almost the entire day, pick a really high number and you won’t be able to use that computer for the rest of the day. The time between the rotation is adjustable too, to make the screen rotate really slow, put a high number. To make it quicker, put a lower number. The time it takes to make a rotation is in seconds. The last one option is the most tricky one, if you turn the first for loop into a while true loop, it will never end. Keep that in mind!

In this article you learned how to make a virus and hopefully it was interesting and you understand a small part of computer science a little bit better. Share this with your friends, family and other people who are interested in computer science or other technical subjects!

--

--

RickA

Computer Science: Python - Unity - Coding & Programming - Student - Follow me please :)