Is it possible to create a c# file in c#?

I want to make one c# script that creates multiple c# files in a designated directory and then writes code in the files it just created. I know it would be easier to just create and write the scripts myself, but I want to create this as some form of security. I want it to be able to encrypt and decrypt itself, scan it’s own code for inconsistencies and then create every file it needs from within that one script. So no “unwanted” files can be downloaded along side it or allow anyone to access or modify that script.

The main purpose of the code I’m trying to make is to show people how easy it is for ONE file to find and access private information on a device.
But I want to make sure that the code is as safe as possible so no “data parasites” can use my code to steal that same sensitive data.

That and I just think it would be cool to watch a script make more scripts :),

@Boredman46

This is very much possible and I decided to take the time and make you an example script that creates one single script. Hopefully you can build from here mate. Cheers!

    //This is the directory where the file will be put
    public string directoryLocation = "C://Users//YourUserNameGoesHere//Documents//";

    //The new scripts name
    public string scriptName = "result";
    void Start()
    {
        //File.WriteAllText(directoryLoc + "NewResult2.txt", string.Empty); ==> //This line I commented out can be used to clear the file

        //This writes the new file but it will be empty
        using (StreamWriter newWriter = new StreamWriter(directoryLocation + scriptName + ".cs", true))
        {
            //The rest of this writes what you want your file to contain
            newWriter.WriteLine("using UnityEngine;");

            //This is an empty line because I like having spaces :D
            newWriter.WriteLine();
            newWriter.WriteLine("public class " + scriptName + " : MonoBehavior {");
            newWriter.WriteLine("}");
        }
        Debug.Log("Writing Of Script Done!");
    }