How to encrypt a file using C #?

1

I need to create a function to encrypt files using the Caeser method without using the functions already done in the C # library. My code does not work for large files the computer crashes:

public static void cesar(string origem, string destino, int chave)
    {
        int cifra;
        byte[] textopuroEmBinario = File.ReadAllBytes(origem);
        byte[] textocriptografadoEmBinario = new byte[textopuroEmBinario.Length];
        BinaryWriter bw = new BinaryWriter(File.OpenWrite(destino));
        int i = 0;

            foreach (byte b in textopuroEmBinario)
            {
                    if (b >= 97 && b <= 122){
                    cifra = b + chave; 
                    if (cifra > 122)
                    {
                        cifra = cifra - 26;
                    }
                    textocriptografadoEmBinario[i++] = (byte)cifra;

                }
                else
                {
                    textocriptografadoEmBinario[i++] = b;
                }

            }

            bw.Write(textocriptografadoEmBinario);
            bw.Dispose();
        }
    
asked by anonymous 06.09.2017 / 20:31

0 answers